OgreNewt step size.

saladin

03-12-2007 12:24:09

Hi,

I found this piece of code in the OgreNewt demo's BasicFrameListen class.
def frameStarted(self, evt):
Ogre.FrameListener.frameStarted(self, evt)
self.elapsed += evt.timeSinceLastFrame
if self.debugflag == True:
pass
##OgreNewt.Debugger.getSingleton().showLines(self.World)
if ((self.elapsed > self.update) and (self.elapsed < (1.0)) ):
while (self.elapsed > self.update):
self.World.update( self.update )
self.elapsed -= self.update
else:
if (self.elapsed < self.update):
## not enough time has passed this loop, so ignore for now.
pass
else:
self.World.update( self.elapsed )
self.elapsed = 0.0 ## reset the elapsed time so we don't become "eternally behind"
return True


The main purpose of the code is to advance the physics system in a frame independent manner. However since the physics world cannot update by bigger step than 0.016666 i.e. 1/60, the line "self.World.update( self.elapsed )" doesn't work for the given condition: self.elapsed > 1.0. Maybe we can do:

def frameStarted(self, evt):
Ogre.FrameListener.frameStarted(self, evt)
self.elapsed += evt.timeSinceLastFrame
if self.debugflag == True:
pass
while (self.elapsed > self.update):
self.World.update( self.update )
self.elapsed -= self.update
if self.elapsed < self.udpate:
self.World.update(self.elapsed)
self.elapsed = 0
return True


Hope someone can tell me the reason. If this were a mistake maybe it should get fixed in the coming demo.

Game_Ender

03-12-2007 18:23:23

Its not a bug, its a safety feature. If the physics system is slowing the game down and you don't cap the self.elapsed time, it will grow every frameStarted event.

saladin

04-12-2007 00:17:49

Its not a bug, its a safety feature. If the physics system is slowing the game down and you don't cap the self.elapsed time, it will grow every frameStarted event.

So if self.elapsed is like 200, the physics will end up running for quite a while and this time will be accumulated into the next self.timeSinceLastFrame causing the next physics loop to fun for even longer huh?
I see, my bad.

Cheers.