gameprogcpp / code

Game Programming in C++ Code
Other
1.03k stars 355 forks source link

Program still works fine without while loop waiting 16ms #39

Closed birminghamallen closed 3 years ago

birminghamallen commented 3 years ago

Commented out this code and it use useless. What is it for?

// Wait until 16ms has elapsed since last frame //while (!SDL_TICKS_PASSED(SDL_GetTicks(), mTicksCount)) //;

gustavopezzi commented 3 years ago

It is not useless. A game loop can run without a limit of frames per second, and game object movement will be ok if you still multiply things by deltatime. But the reason the author decided to introduce an FPS limit is just to make the game run at exactly 60 frames per second. If you want your game to have a consistent FPS count, wasting some milliseconds every frame is one way of doing so.

birminghamallen commented 3 years ago

It is not useless. A game loop can run without a limit of frames per second, and game object movement will be ok if you still multiply things by deltatime. But the reason the author decided to introduce an FPS limit is just to make the game run at exactly 60 frames per second. If you want your game to have a consistent FPS count, wasting some milliseconds every frame is one way of doing so.

Cool, thank you so much! :-)