Problem with Limiting Frame

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
GameCreator
Posts: 22
Joined: Wed Jun 08, 2005 2:44 pm

Problem with Limiting Frame

Post by GameCreator »

Currently, in my source, I am limiting the frame rate to about 60FPS so that it runs the same speed on my computer and any computer faster than mine. (My searches never came up with a good way to do timers.)

Here's the relevant code:

Code: Select all

while(!game.gameover)
{
	//  Cheap way to limit a system to 60FPS
	while((device->getTimer()->getTime())-game.lasttime<16)
	{
	}

	playerthink();
	render();

	game.lasttime = device->getTimer()->getTime();
}
My problem is that since I've implemented it the camera got ... weird. The camera is locked on to the character. There is no rotation in any way. The game would play like Lode Runner. But when the character changes run direction, or falls to the ground or any change the camera "bumps." I have a skybox (which shouldn't move since there is no rotation, so it just acts as a static background right now) but these bumps also nudge the background back and forth. It gets kind of annoying. Any ideas as to why this happens when everything played perfectly before the time limitation? Does limiting the time like this impact Irrlicht internals in anyway that I may need to compensate for?
Guest

Post by Guest »

do a search (on google not irrlicht forum) for "time based modeling" and "delta time".. use this calculated delta time to adjust ALL animations/movements and DO NOT hard lock any frame counts - that is a poor mans method - this way the rendering can do 20 fps or 200 fps and it will still MOVE the same amount of time.

AFter you have that then you can think about frame limiting but it will be as a design choice rather than a logic "must" which could go wrong.
GameCreator
Posts: 22
Joined: Wed Jun 08, 2005 2:44 pm

Post by GameCreator »

Thanks, and I actually did that already but even if I did implement that method, it still won't solve my problem (of the camera being jittery). Does anyone have any ideas of how to fix that?
Guest

Post by Guest »

i had this problem too. this solved it:

Code: Select all

//put this before anything is drawn (before smgr->drawAll(); in the main loop)

camera->updateAbsolutePosition();
Guest

Post by Guest »

If that is your whole main loop, I'm not surprised that it doesn't work very well.
Right now, you're forcing each and every system to wait 16 milliseconds, not just the faster systems, because you're ignoring render time and processing time.

Try placing your time measurement before all the heavy lifting, so the measurement actually takes rendering and processing into account:

Code: Select all

   while((device->getTimer()->getTime())-game.lasttime<16) 
   { 
   } 

   game.lasttime = device->getTimer()->getTime();  // <--- here

   playerthink(); 
   render(); 

GameCreator
Posts: 22
Joined: Wed Jun 08, 2005 2:44 pm

Post by GameCreator »

GFXstyLER, you seriously made my week! Thank you very much for that solution.

Guest, your post helped too. I didn't even notice that I put that line in the wrong place. Thank you as well.

One day, hopefully, we'll have a good virtual timer to use in Irrlicht. Until then I think I'll have to just go with this awkward method. I formerly coded using Allegro which allowed the code to be desiged at 60fps (or whatever) and it adjusted things for you automatically. Here's some documentation on it for those who are curious:
http://docs.mandragor.org/files/Common_ ... ex005.html
Post Reply