Hi,
I working with Game States and all un-buffered methods works fine, including joysticks, but when I try to move my mouse, nothing happens.
GameManager.h
#ifndef GameManager_H
#define GameManager_H
#include "Ogre.h"
//////////////////////////////// OS Nuetral Headers ////////////////
#include "OISInputManager.h"
#include "OISException.h"
#include "OISKeyboard.h"
#include "OISMouse.h"
#include "OISJoyStick.h"
#include "OISEvents.h"
#include "USC_defs.h"
class GameState;
class GameManager : public Ogre::FrameListener, OIS::KeyListener, OIS::MouseListener
{
public:
GameManager();
~GameManager();
void start(void);
void changeState(GameState* state);
void pushState(GameState* state);
void popState();
// input manager
OIS::Keyboard *g_kb; //Keyboard Device
OIS::Mouse *g_m; //Mouse Device
OIS::JoyStick* g_joys[NUM_OF_JOYSTICK]; //This demo supports up to 4 controllers
OIS::ForceFeedback* g_ff[NUM_OF_JOYSTICK];//Array to hold ff interface for each joy
Ogre::Real mTimeUntilNextToggle;
int getNumJoySticks() { return numSticks; }
protected:
Ogre::Root* mRoot;
Ogre::RenderWindow* mWindow;
void doStartupControls();
void setupResources(void);
bool configure(void);
bool frameStarted(const Ogre::FrameEvent& evt);
bool frameEnded(const Ogre::FrameEvent& evt);
bool keyPressed(const OIS::KeyEvent &e);
bool keyReleased(const OIS::KeyEvent &e);
bool mouseMoved(const OIS::MouseEvent &e);
bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
private:
std::vector<GameState*> states;
int numSticks;
};
#endif
GameManager.cpp
#include "Ogre.h"
#include "GameManager.h"
#include "GameState.h"
using namespace Ogre;
GameManager::GameManager()
{
mRoot = 0;
mTimeUntilNextToggle = 0;
}
GameManager::~GameManager()
{
// clean up all the states
while (!states.empty()) {
states.back()->exit();
states.pop_back();
}
if (mRoot)
delete mRoot;
}
void GameManager::start(void)
{
mRoot = new Root();
setupResources();
if (!configure()) return;
mRoot->addFrameListener(this);
doStartupControls();
}
void GameManager::changeState(GameState* state)
{
// cleanup the current state
if ( !states.empty() ) {
states.back()->exit();
states.pop_back();
}
// store and init the new state
states.push_back(state);
states.back()->enter();
}
void GameManager::pushState(GameState* state)
{
// pause current state
if ( !states.empty() ) {
states.back()->pause();
}
// store and init the new state
states.push_back(state);
states.back()->enter();
}
void GameManager::popState()
{
// cleanup the current state
if ( !states.empty() ) {
states.back()->exit();
states.pop_back();
}
// resume previous state
if ( !states.empty() ) {
states.back()->resume();
}
}
void GameManager::setupResources(void)
{
// Load resource paths from config file
ConfigFile cf;
cf.load("resources.cfg");
// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();
String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
}
bool GameManager::configure(void)
{
// load config settings from ogre.cfg
if (!mRoot->restoreConfig())
{
// if there is no config file, show the configuration dialog
if (mRoot->showConfigDialog())
{
// if returned true, user clicked OK so initialise
// and create a default rendering window
mWindow = mRoot->initialise(true);
return true;
}
else
{
return false;
}
}
// initialise and create a default rendering window
mWindow = mRoot->initialise(true);
return true;
}
bool GameManager::frameStarted(const FrameEvent& evt)
{
if(mWindow->isClosed())
return false;
// call frameStarted of current state
return states.back()->frameStarted(this, evt);
}
bool GameManager::frameEnded(const FrameEvent& evt)
{
// call frameEnded of current state
return states.back()->frameEnded(this, evt);
}
void GameManager::doStartupControls()
{
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
mWindow->getCustomAttribute("HWND", &windowHnd);
//Both x11 and Win32 use handle of some sort..
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
OIS::InputManager &im = *OIS::InputManager::createInputSystem( pl );
// init variables
g_kb = 0;
g_m = 0;
for (int i = 0; i < NUM_OF_JOYSTICK; i++)
{
g_joys[i] = 0;
g_ff[i] = 0;
}
if( im.numKeyBoards() > 0 )
{
g_kb = (OIS::Keyboard*)im.createInputObject( OIS::OISKeyboard, true );
g_kb->setEventCallback( this );
}
if( im.numMice() > 0 )
{
g_m = (OIS::Mouse*)im.createInputObject( OIS::OISMouse, true );
g_m->setEventCallback( this );
}
//This demo only uses at max 4 joys
numSticks = im.numJoysticks();
if( numSticks > NUM_OF_JOYSTICK )
{
numSticks = NUM_OF_JOYSTICK;
}
for( int i = 0; i < numSticks; ++i )
{
g_joys[i] = (OIS::JoyStick*)im.createInputObject( OIS::OISJoyStick, true );
g_ff[i] = (OIS::ForceFeedback*)g_joys[i]->queryInterface( OIS::Interface::ForceFeedback );
}
}
bool GameManager::keyPressed(const OIS::KeyEvent &e) { return true; }
bool GameManager::keyReleased(const OIS::KeyEvent &e) { return true; }
bool GameManager::mouseMoved(const OIS::MouseEvent &e)
{
return states.back()->mouseMoved(e);
}
bool GameManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
return true;
};
bool GameManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }
_main.cpp
#include "GameManager.h"
#include "IntroState.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
// Create GameManager object
GameManager game;
try
{
// initialize the game and switch to the first state
game.start();
game.changeState(IntroState::getInstance());
} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( 0, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " << e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif
Please, any help would be really appreciated.
Thanks a lot!
Dirso