LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: ronophir on October 04, 2005, 07:36:35

Title: Unstable Performance
Post by: ronophir on October 04, 2005, 07:36:35
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 (http://alleg.sf.net) 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();
}
Title: Unstable Performance
Post by: Matzon on October 04, 2005, 07:53:37
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.
Title: Unstable Performance
Post by: elias4444 on October 04, 2005, 20:18:59
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:
Title: Unstable Performance
Post by: ronophir on October 05, 2005, 06:11:04
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?
Title: Unstable Performance
Post by: Matzon on October 05, 2005, 06:53:41
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.