Add gfx_fps_title.

This commit is contained in:
Themaister 2012-11-15 17:30:31 +01:00
parent 4057b054b1
commit ed8433bd73
3 changed files with 27 additions and 8 deletions

View File

@ -79,11 +79,12 @@ static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, i
return frames/time;
}
static unsigned gl_frames = 0;
static unsigned gl_frames;
static bool gfx_get_fps(char *buf, size_t size)
static bool gfx_get_fps(char *buf, size_t size, bool always_write)
{
static struct timeval tv;
static float last_fps;
struct timeval new_tv;
bool ret = false;
@ -99,15 +100,23 @@ static bool gfx_get_fps(char *buf, size_t size)
struct timeval tmp_tv = tv;
tv = new_tv;
float fps = tv_to_fps(&tmp_tv, &new_tv, 180);
last_fps = tv_to_fps(&tmp_tv, &new_tv, 180);
#ifdef RARCH_CONSOLE
snprintf(buf, size, "FPS: %6.1f || Frames: %d", fps, gl_frames);
snprintf(buf, size, "FPS: %6.1f || Frames: %d", last_fps, gl_frames);
#else
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, gl_frames);
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, gl_frames);
#endif
ret = true;
}
else if (always_write)
{
#ifdef RARCH_CONSOLE
snprintf(buf, size, "FPS: %6.1f || Frames: %d", last_fps, gl_frames);
#else
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, gl_frames);
#endif
}
return ret;
}
@ -119,12 +128,18 @@ void gfx_window_title_reset(void)
bool gfx_window_title(char *buf, size_t size)
{
bool ret = gfx_get_fps(buf, size);
bool ret = gfx_get_fps(buf, size, false);
gl_frames++;
return ret;
}
void gfx_fps_title(char *buf, size_t size)
{
gfx_get_fps(buf, size, true);
gl_frames++;
}
#if defined(_WIN32) && !defined(_XBOX)
#include <windows.h>
#include "../dynamic.h"

View File

@ -27,9 +27,13 @@ extern "C" {
#include "../config.h"
#endif
// Returns true if FPS value was updated.
bool gfx_window_title(char *buf, size_t size);
void gfx_window_title_reset(void);
// Like gfx_window_title, but always updates FPS value.
void gfx_fps_title(char *buf, size_t size);
#ifdef _WIN32
void gfx_set_dwm(void);
#endif

View File

@ -1121,8 +1121,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
bool fps_enable = g_extern.console.rmenu.state.msg_fps.enable;
if (fps_enable)
{
static char fps_txt[128];
gfx_window_title(fps_txt, sizeof(fps_txt));
char fps_txt[128];
gfx_fps_title(fps_txt, sizeof(fps_txt));
gl_render_msg_place(gl, g_settings.video.msg_pos_x, 0.56f, 1.04f, WHITE, fps_txt);
}
#endif