improve frame limiter accuracy

This commit is contained in:
Andrei Alexeyev 2017-10-01 00:13:39 +03:00
parent 03893907a1
commit 8add469c20
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4

View file

@ -279,9 +279,9 @@ void limit_frame_rate(uint64_t *lasttime) {
double passed = (double)(SDL_GetPerformanceCounter() - *lasttime) / SDL_GetPerformanceFrequency();
double delay = max(0, 1.0 / FPS - passed);
uint32_t delay_ms = (uint32_t)(delay * 1000.0);
int32_t delay_ms = (int32_t)rint(delay * 1000.0);
if(delay > 0 && delay_ms > 0) {
if(delay_ms > 0) {
SDL_Delay(delay_ms);
}