PDA

View Full Version : Time stepping



Allan Walton
10-02-2001, 03:44 AM
Hi there,

Where can i get info regarding time-stepping so a program doesnt run faster on more powerful machines?

Cheers

TrXtR
10-02-2001, 04:51 AM
If you are using sound, use your sound to time.

Or you could use v-retrace (I'm new to openGL and dont know much about that)

Else ... you can use the timeGetTime function
(Check your neares msdn)

And keep timing with that. And just erm .. I geuss wait for the next moment to display, and then display.

But for your part, I hope someone else replies that has a better idea http://www.opengl.org/discussion_boards/ubb/smile.gif

These are just my idea's (which could be terrible)

Bob
10-02-2001, 05:08 AM
TrXtR is on the right track here. Use a time function.

There are two ways most people do.

#1: Lock the framerate at a certain speed. Easiest to implement, but is not a very good solution in my oppinion. On very powerfull machines, the application is waiting to continue most of the time = major waste of computer power. Undefined behaviour un computers that cannot keep the framerate you set as a minimum. Easy to code movements, since one frame is always a fixed timestep. If an object is supposed to move 30 units in one second, and you lock your program at 60 fps, the object will be moved 0.5 units each frame.

#2: Let the program run as fast as it can, and update the scene according to the time spend in last frame. In my oppinion, the best compared to how easy it is to implement. A littel more difficult than #1, but utilizes the computer all the time. More power = higher framerate, but not faster game movements. Will work on slower computers aswell, without problems. A bit more difficult to code movements, since you don't know the timestep. You specify your movements in units per second, and multiply this movement with the number of seconds in last frame. Your object is moving at a speed of 30 units per second. Last frame took 0.02 seconds (~50 fps), the next frame will move the object 30*0.02=0.6 units forward.

Time can be measured with timeGetTime, or with QueryPerformanceCounter (Win32 only).