Rewrite gfx_get_fps - now outputs proper string for FPS output

This commit is contained in:
twinaphex 2013-10-07 20:17:07 +02:00
parent 80079e297b
commit c0c6ecc6cb
18 changed files with 41 additions and 47 deletions

View File

@ -380,8 +380,8 @@ void apple_gfx_ctx_get_video_size(unsigned* width, unsigned* height)
void apple_gfx_ctx_update_window_title(void)
{
#ifdef OSX
static char buf[128];
bool got_text = gfx_get_fps(buf, sizeof(buf), false);
static char buf[128], buf_fps[128];
bool got_text = gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps));
static const char* const text = buf; // < Can't access buf directly in the block
if (got_text)

View File

@ -196,8 +196,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
gfx_get_fps(buf, sizeof(buf), false);
char buf[128], buf_fps[128];
gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps));
}
static bool gfx_ctx_set_video_mode(

View File

@ -322,8 +322,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
gfx_get_fps(buf, sizeof(buf), false);
char buf[128], buf_fps[128];
gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps));
}
static bool gfx_ctx_set_video_mode(

View File

@ -215,8 +215,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
gfx_get_fps(buf, sizeof(buf), false);
char buf[128], buf_fps[128];
gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps));
}
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)

View File

@ -82,8 +82,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
if (gfx_get_fps(buf, sizeof(buf), false))
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps))
RARCH_LOG("%s\n", buf);
}

View File

@ -166,13 +166,13 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
gl_t *gl = (gl_t*)driver.video_data;
char buf[128];
if (gfx_get_fps(buf, sizeof(buf), true))
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), true, buf_fps, sizeof(buf_fps)))
XStoreName(g_dpy, g_win, buf);
if ((g_extern.lifecycle_mode_state & (1ULL << MODE_FPS_DRAW)) &&
gl->font_ctx)
msg_queue_push(g_extern.msg_queue, buf, 1, 1);
msg_queue_push(g_extern.msg_queue, buf_fps, 1, 1);
}
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)

View File

@ -63,8 +63,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
gfx_get_fps(buf, sizeof(buf), false);
char buf[128], buf_fps[128];
gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps));
}
static bool gfx_ctx_set_video_mode(

View File

@ -189,9 +189,9 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height) { }
static void gfx_ctx_update_window_title(void)
{
gl_t *gl = (gl_t*)driver.video_data;
char buf[128];
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), false) &&
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)) &&
(g_extern.lifecycle_mode_state & (1ULL << MODE_FPS_DRAW)) &&
gl->font_ctx)
{

View File

@ -109,8 +109,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
gfx_get_fps(buf, sizeof(buf), false);
char buf[128], buf_fps[128]
gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps));
}
static void gfx_ctx_get_video_size(unsigned *width, unsigned *height)

View File

@ -277,8 +277,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
if (gfx_get_fps(buf, sizeof(buf), false))
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)))
SetWindowText(g_hwnd, buf);
}

View File

@ -83,10 +83,10 @@ extern unsigned font_x, font_y;
static void gfx_ctx_xdk_update_window_title(void)
{
char buf[128];
char buf[128], buf_fps[128];
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
if (gfx_get_fps(buf, sizeof(buf), false) &&
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)) &&
g_extern.lifecycle_mode_state & (1ULL << MODE_FPS_DRAW))
{
MEMORYSTATUS stat;

View File

@ -179,8 +179,8 @@ static void gfx_ctx_set_resize(unsigned width, unsigned height)
static void gfx_ctx_update_window_title(void)
{
char buf[128];
if (gfx_get_fps(buf, sizeof(buf), false))
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)))
XStoreName(g_dpy, g_win, buf);
}

View File

@ -489,8 +489,8 @@ D3DVideo::D3DVideo(const video_info_t *info) :
win_height = rect.bottom - rect.top;
}
char buffer[128];
gfx_get_fps(buffer, sizeof(buffer), false);
char buffer[128], buffer_fps[128];
gfx_get_fps(buffer, sizeof(buffer), false, buffer_fps, sizeof(buffer_fps));
std::string title = buffer;
title += " || Direct3D9";
@ -1006,8 +1006,8 @@ void D3DVideo::deinit_font()
void D3DVideo::update_title()
{
char buffer[128];
if (gfx_get_fps(buffer, sizeof(buffer), false))
char buffer[128], buffer_fps[128];
if (gfx_get_fps(buffer, sizeof(buffer), false, buffer_fps, sizeof(buffer_fps)))
{
std::string title = buffer;
title += " || Direct3D9";

View File

@ -24,7 +24,7 @@ static inline float time_to_fps(rarch_time_t last_time, rarch_time_t new_time, i
}
#define FPS_UPDATE_INTERVAL 256
bool gfx_get_fps(char *buf, size_t size, bool always_write)
bool gfx_get_fps(char *buf, size_t size, bool always_write, char *buf_fps, size_t size_fps)
{
static rarch_time_t time;
static rarch_time_t fps_time;
@ -45,20 +45,14 @@ bool gfx_get_fps(char *buf, size_t size, bool always_write)
last_fps = time_to_fps(time, new_time, FPS_UPDATE_INTERVAL);
time = new_time;
#ifdef RARCH_CONSOLE
snprintf(buf, size, "FPS: %6.1f || Frames: %d", last_fps, g_extern.frame_count);
#else
snprintf(buf_fps, size_fps, "FPS: %6.1f || Frames: %d", last_fps, g_extern.frame_count);
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, g_extern.frame_count);
#endif
ret = true;
}
else if (always_write)
{
#ifdef RARCH_CONSOLE
snprintf(buf, size, "FPS: %6.1f || Frames: %d", last_fps, g_extern.frame_count);
#else
snprintf(buf_fps, size_fps, "FPS: %6.1f || Frames: %d", last_fps, g_extern.frame_count);
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, last_fps, g_extern.frame_count);
#endif
}
}
else

View File

@ -30,7 +30,7 @@ extern "C" {
// If always_write is true, will always update FPS value
// If always_write is false, returns true if FPS value was updated.
bool gfx_get_fps(char *buf, size_t size, bool always_write);
bool gfx_get_fps(char *buf, size_t size, bool always_write, char *buf_fps, size_t size_fps);
#ifdef _WIN32
void gfx_set_dwm(void);

View File

@ -311,8 +311,8 @@ static bool sdl_gfx_frame(void *data, const void *frame, unsigned width, unsigne
if (SDL_MUSTLOCK(vid->screen))
SDL_UnlockSurface(vid->screen);
char buf[128];
if (gfx_get_fps(buf, sizeof(buf), false))
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)))
SDL_WM_SetCaption(buf, NULL);
SDL_Flip(vid->screen);

View File

@ -338,7 +338,7 @@ static void *xv_init(const video_info_t *video, const input_driver_t **input, vo
int visualmatches = 0;
XSetWindowAttributes attributes = {0};
unsigned width = 0, height = 0;
char buf[128];
char buf[128], buf_fps[128];
Atom atom = 0;
void *xinput = NULL;
XVisualInfo *visualinfo = NULL;
@ -409,7 +409,7 @@ static void *xv_init(const video_info_t *video, const input_driver_t **input, vo
XMapWindow(xv->display, xv->window);
if (gfx_get_fps(buf, sizeof(buf), false))
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)))
XStoreName(xv->display, xv->window, buf);
x11_set_window_attr(xv->display, xv->window);
@ -700,8 +700,8 @@ static bool xv_frame(void *data, const void *frame, unsigned width, unsigned hei
true);
XSync(xv->display, False);
char buf[128];
if (gfx_get_fps(buf, sizeof(buf), false))
char buf[128], buf_fps[128];
if (gfx_get_fps(buf, sizeof(buf), false, buf_fps, sizeof(buf_fps)))
XStoreName(xv->display, xv->window, buf);
g_extern.frame_count++;

View File

@ -943,8 +943,8 @@ static bool gx_frame(void *data, const void *frame,
GX_DrawDone();
}
char fps_txt[128];
gfx_get_fps(fps_txt, sizeof(fps_txt), lifecycle_mode_state & (1ULL << MODE_FPS_DRAW) ? true : false);
char fps_txt[128], fps_text_buf[128];
gfx_get_fps(fps_txt, sizeof(fps_txt), lifecycle_mode_state & (1ULL << MODE_FPS_DRAW) ? true : false, fps_text_buf, sizeof(fps_text_buf));
if (lifecycle_mode_state & (1ULL << MODE_FPS_DRAW))
{