From 6a260a57dddf49247a1cc1e96e62b8ac358f2e1b Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 6 Aug 2011 03:28:07 +0200 Subject: [PATCH] Reset frame counter properly. --- gfx/gfx_common.c | 17 +++++++++++------ gfx/gfx_common.h | 1 + gfx/gl.c | 9 +++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index 62c2bfe1e8..ee49e8b755 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -25,21 +25,26 @@ static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, i return frames/time; } +static unsigned gl_frames = 0; + +void gfx_window_title_reset(void) +{ + gl_frames = 0; +} + bool gfx_window_title(char *buf, size_t size) { - static int frames = 0; static struct timeval tv; struct timeval new_tv; bool ret = false; - if (frames == 0) + if (gl_frames == 0) { gettimeofday(&tv, NULL); snprintf(buf, size, "%s", g_extern.title_buf); ret = true; } - - if ((frames % 180) == 0 && frames > 0) + else if ((gl_frames % 180) == 0) { gettimeofday(&new_tv, NULL); struct timeval tmp_tv = tv; @@ -47,11 +52,11 @@ bool gfx_window_title(char *buf, size_t size) float fps = tv_to_fps(&tmp_tv, &new_tv, 180); - snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, frames); + snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, gl_frames); ret = true; } - frames++; + gl_frames++; return ret; } diff --git a/gfx/gfx_common.h b/gfx/gfx_common.h index 95486494c8..97baee203b 100644 --- a/gfx/gfx_common.h +++ b/gfx/gfx_common.h @@ -22,5 +22,6 @@ #include bool gfx_window_title(char *buf, size_t size); +void gfx_window_title_reset(void); #endif diff --git a/gfx/gl.c b/gfx/gl.c index 2866d4baad..ac6f469b0d 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1051,6 +1051,11 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo if (!SDL_SetVideoMode(video->width, video->height, g_settings.video.force_16bit ? 16 : 0, SDL_OPENGL | SDL_RESIZABLE | (video->fullscreen ? SDL_FULLSCREEN : 0))) return NULL; + gfx_window_title_reset(); + char buf[128]; + if (gfx_window_title(buf, sizeof(buf))) + SDL_WM_SetCaption(buf, NULL); + // Remove that ugly mouse :D SDL_ShowCursor(SDL_DISABLE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1138,10 +1143,6 @@ static void* gl_init(const video_info_t *video, const input_driver_t **input, vo glColor4f(1, 1, 1, 1); glClearColor(0, 0, 0, 1); - char buf[128]; - if (gfx_window_title(buf, sizeof(buf))) - SDL_WM_SetCaption(buf, NULL); - glMatrixMode(GL_MODELVIEW); glLoadIdentity();