Unstable Performance

Started by ronophir, October 04, 2005, 07:36:35

Previous topic - Next topic

ronophir

Hello all!

While writing my nice little platformer, I stumbled upon the need to regulate the logic of my game, this is, To make it run the same speed all the time. However, I didn't find an easy way to do so. You see, I come from Allegro and with Allegro you use timers to regulate the time. However, I didn't find a parallel way to do so in LWJGL. Please help me!

P.S: My game loop is as follows:
while(!exit) {
   do_logic();
   render();
}

Matzon

The easiest way to do this, is to limit your framerate to say 60 fps. Just call Display.sync(60);

A more  advanced way would be to check whether you're able to sustain the framerate and if so just sleep - if not, stop rendering and only update state (perhaps render a couple of keyframes every nth frame).

The best way, and by far the most complex, is to do all your movement and updates based on time elapsed since last update.

elias4444

QuoteThe best way, and by far the most complex, is to do all your movement and updates based on time elapsed since last update.
Really? Drats... why do I always do things the hard way?  :oops:
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

ronophir

QuoteJust call Display.sync(60);
Where? How many times?

QuoteThe best way, and by far the most complex, is to do all your movement and updates based on time elapsed since last update.
How?

Matzon

Quote from: "ronophir"
QuoteJust call Display.sync(60);
Where? How many times?
after a call to Display.update();

Quote from: "ronophir"
QuoteThe best way, and by far the most complex, is to do all your movement and updates based on time elapsed since last update.
How?
well, you decide how many units you move per second and the just move the fraction that matches with the time elapsed since last render.