Fixed Time Step Game loop

Started by
15 comments, last by belfegor 10 years, 8 months ago

Thank you so much everyone! L. Spiro, thank you for clearing things up for me, that's two blogs you've made that've helped me out so far :)

Advertisement

No problem, glad I could help. That is for what they are there.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Sorry to bring this topic up, but i can't get this to work correctly.

I have made a minimal example (win32/dx9) cpp that shows the problem. I have read and follow L. Spiro tutorial but for me objects are moving at different speeds if vsync is on and off.

Please if can someone could try it and tell me where is my mistake?

http://pastebin.com/mmDUVELE

Thank you for your time.

Does not look like you ever call gTimer.update, and gTimer.get just returns a variable, which is initialised to 0 and updated via gTimer.update. So looks like gTimer.get is always zero. This leaves you with "while((0 - 0) > 33333)" which never runs.

Also you are moving stuff in onPreUpdate which is not part of your fixed step loop anyway ("vSprites[i]->moveRandom();"), it will be the rendering frame rate.

laugh.png OMG, forgat to update the timer, ok i fixed that now but again the moving speed is different.

Also you are moving stuff in onPreUpdate which is not part of your fixed step loop anyway ("vSprites[i]->moveRandom();"), it will be the rendering frame rate.

Imagine that onPreUpdate is using input from keyboard to move objects, i cannot call that in "fixed-step" loop, can i?

I though i just need to interpolate positions in that loop.

Thank you for your time.

If your moving objects outside the fixed step loop, it is not fixed step. For key pressed / released events you can possibly get away with it, but your not doing that there, you are moving the objects regardless by some amount that doesnt look like it even tries to account for the loop rate.

Your input needs to be using events (so when the user presses a key you do one thing once, not every loop), or if your polling (e.g. do something as long as a key is pressed) it really should be in the fixed step section.

That makes sense, thank you.

This topic is closed to new replies.

Advertisement