From d2d3956e72555d07bfaad9315c648f88c300d5b9 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Tue, 29 Mar 2011 23:16:54 +0100 Subject: Improved frame rate limiting diff --git a/src/main.c b/src/main.c index a722c16..68d978b 100644 --- a/src/main.c +++ b/src/main.c @@ -2059,7 +2059,8 @@ int main(int argc, char *argv[]) int currentTime = 0; int FPS = 0; int pastFPS = 0; - int past = 0; + int elapsedTime = 0; + int limitFPS = 60; void *http_ver_check; void *http_session_check = NULL; char *ver_data=NULL, *check_data=NULL, *tmp; @@ -3659,21 +3660,22 @@ int main(int argc, char *argv[]) drawrect(vid_buf, XRES-19-old_ver_len, YRES-22, old_ver_len+5, 13, 255, 216, 32, 255); } - if (hud_enable) + FPS++; + currentTime = SDL_GetTicks(); + elapsedTime = currentTime-pastFPS; + if (elapsedTime>=1000) { - currentTime = SDL_GetTicks(); - if (currentTime-past>=16) - { - past = SDL_GetTicks(); - FPS++; - } - if (currentTime-pastFPS>=1000) - { - FPSB = FPS; - FPS = 0; - pastFPS = currentTime; - } + FPSB = FPS; + FPS = 0; + pastFPS = currentTime; + } + else if (elapsedTime>20 && FPS*1000/elapsedTime>limitFPS) + { + SDL_Delay(5); + } + if (hud_enable) + { #ifdef BETA sprintf(uitext, "Version %d Beta %d FPS:%d Parts:%d Generation:%d Gravity:%d Air:%d", SAVE_VERSION, MINOR_VERSION, FPSB, NUM_PARTS, GENERATION, gravityMode, airMode); #else -- cgit v0.9.2-21-gd62e