[Det] World::Advance

TechnoBulldog

03-11-2010 23:19:19

Normally, I'm used to running everything from an Ogre FrameListener, but I recently decided instead to use a main loop. In a frame listener, to advance the world, I would simple call:
mWorld->advance(evt.timeSinceLastFrame);

However, now, using a loop instead of a frame listener, my code looks something like this:

// mMillisSinceLastFrame and mMicrosSinceLastFrame are both unsigned longs, and mFrameTimer is and Ogre::Timer.
while(mContinue)
{
mMouse->capture();
mKeyboard->capture();
if(mKeyboard->isKeyDown(OIS::KC_ESCAPE)) mContinue = false;

if(mContinue)
{
mWorld->advance(mMillisSinceLastFrame);
mContinue = mRoot->renderOneFrame();
}

mMillisSinceLastFrame = mFrameTimer->getMilliseconds();
mMicrosSinceLastFrame = mFrameTimer->getMicroseconds();
mFrameTimer->reset();
}

Are there any problems with doing this, will this mess up the physics in any way? Will this even work? If there are any problems, can anyone give me some advice? I would prefer to not use a frame listener anymore, but I really want to avoid any problems.

I doubt it matters in this scenario, but I'm using Detritus from Git. Probably not the latest commit though.

betajaen

04-11-2010 08:41:17

It should be okay.

But you need to turn your milliseconds into seconds (turn into a float divide by a 1000), otherwise your advancing NxOgre in neat 16 minutes, at a time. ;)