Acid_Gambit
08-05-2007 09:41:38
I am working on a simple game with Game States. There are two main states: Play State and Pause State. The OgreNewt World is constructed in Play State but I want to be able to access it in Pause State as well. I tried to pass World as user data but it crashes my game. The method getWorld() isn't helping me either because it keeps complaining about conversion problems (const World * to World *). Passing an OgreNewt::Body as user data works fine though. But I need the OgreNewt::World in my Pause State to create a new OgreNewt::Body.
Acid_Gambit
08-05-2007 16:06:13
Ok, I've managed to create OgreNewt bodies using mBody->getWorld() (mBody is passed to the new Game State as user data). This leaves one crucial question. How do I update the OgreNewt world? I can't use mBody->getWorld()->update().
Acid_Gambit
08-05-2007 16:51:10
I think I've managed to solve it by myself. It is not a "clean" solution but I couldn't figure out something different.
What I did is add a void myUpdate( Ogre::Real t_step ) const; to OgreNewt_World. Now I can call mBody->getWorld()->myUpdate();. It solved my problem but I am sure there is a better way to do it. I am open for suggestions.
walaber
08-05-2007 18:20:45
any particular reason you can't pass a pointer to the World from the gamestate to the pause state?
it looks like the real problem is that I have marked update() as a non-const function, but getWorld() returns a const pointer. I suppose there's no real reason that I couldn't add const to the update() function... it's an issue of design idealogy I suppose...
my solution would be to pass a pointer for the World to the pause state class from the game state class...
// inside gamestate class here
PauseState::getInstance()->setWorld( mWorld );
GameStateManager::getSingletonPtr()->pushState( PauseState::getInstance() );