Typically, I use something like this:
[source lang="cpp"]while (1){ Uint32 time_before = SDL_GetTicks(); render(); Uint32 time_after = SDL_GetTicks(); int delta = time_after - time_before; int time_wait = (1000 / 60) - delta; // cap at 60 fps if (time_wait > 0){ SDL_Delay(time_wait) }}[/source]
It might not be 100% accurate, but it does what I want.
Show differencesHistory of post edits
#1Goran Milovanovic
Posted 26 August 2012 - 01:08 PM
Typically, I use something like this:
[source lang="cpp"]while (1){ Uint32 time_before = SDL_GetTicks(); render(); Uint32 time_after = SDL_GetTicks(); int delta = time_after - time_before; int time_wait = (60 / 1000) - delta; // cap at 60 fps if (time_wait > 0){ SDL_Delay(time_wait) }}[/source]
It might not be 100% accurate, but it does what I want.
[source lang="cpp"]while (1){ Uint32 time_before = SDL_GetTicks(); render(); Uint32 time_after = SDL_GetTicks(); int delta = time_after - time_before; int time_wait = (60 / 1000) - delta; // cap at 60 fps if (time_wait > 0){ SDL_Delay(time_wait) }}[/source]
It might not be 100% accurate, but it does what I want.