Make title handling more sane.

This commit is contained in:
Themaister 2011-03-26 18:34:58 +01:00
parent 3fda3effda
commit 12d21cf7a6
6 changed files with 110 additions and 44 deletions

View File

@ -2,7 +2,7 @@ include config.mk
TARGET = ssnes tools/ssnes-joyconfig
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o netplay.o
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o netplay.o gfx/gfx_common.o
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o
HEADERS = $(wildcard */*.h) $(wildcard *.h)

View File

@ -1,6 +1,6 @@
TARGET = ssnes.exe
JTARGET = ssnes-joyconfig.exe
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o netplay.o
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o netplay.o gfx/gfx_common.o
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
CC = gcc

58
gfx/gfx_common.c Normal file
View File

@ -0,0 +1,58 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "gfx_common.h"
#include "general.h"
#include <sys/time.h>
static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames)
{
float time = new_tv->tv_sec - tv->tv_sec + (new_tv->tv_usec - tv->tv_usec)/1000000.0;
return frames/time;
}
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)
{
gettimeofday(&tv, NULL);
snprintf(buf, size, g_extern.title_buf);
ret = true;
}
if ((frames % 180) == 0 && frames > 0)
{
gettimeofday(&new_tv, NULL);
struct timeval tmp_tv = tv;
tv = new_tv;
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);
ret = true;
}
frames++;
return ret;
}

26
gfx/gfx_common.h Normal file
View File

@ -0,0 +1,26 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GFX_COMMON_H
#define __GFX_COMMON_H
#include <stddef.h>
#include <stdbool.h>
bool gfx_window_title(char *buf, size_t size);
#endif

View File

@ -32,6 +32,7 @@
#endif
#include "gl_common.h"
#include "gfx_common.h"
#define NO_SDL_GLEXT
#include "SDL.h"
@ -527,37 +528,6 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f
//SSNES_LOG("Setting viewport @ %ux%u\n", width, height);
}
static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames)
{
float time = new_tv->tv_sec - tv->tv_sec + (new_tv->tv_usec - tv->tv_usec)/1000000.0;
return frames/time;
}
static void show_fps(void)
{
// Shows FPS in taskbar.
static int frames = 0;
static struct timeval tv;
struct timeval new_tv;
if (frames == 0)
gettimeofday(&tv, NULL);
if ((frames % 180) == 0 && frames > 0)
{
gettimeofday(&new_tv, NULL);
struct timeval tmp_tv = tv;
gettimeofday(&tv, NULL);
char tmpstr[256] = {0};
float fps = tv_to_fps(&tmp_tv, &new_tv, 180);
snprintf(tmpstr, sizeof(tmpstr), "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, frames);
SDL_WM_SetCaption(tmpstr, NULL);
}
frames++;
}
static bool gl_frame(void *data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
{
gl_t *gl = data;
@ -617,7 +587,6 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
//SSNES_LOG("Setting last rect: %ux%u\n", width, height);
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size);
glTexSubImage2D(GL_TEXTURE_2D,
0, 0, 0, width, height, gl->texture_type,
@ -687,7 +656,9 @@ static bool gl_frame(void *data, const void* frame, unsigned width, unsigned hei
if (msg)
gl_render_msg(gl, msg);
show_fps();
char buf[128];
if (gfx_window_title(buf, sizeof(buf)))
SDL_WM_SetCaption(buf, NULL);
SDL_GL_SwapBuffers();
return true;
@ -819,7 +790,9 @@ static void* gl_init(video_info_t *video, const input_driver_t **input, void **i
glColor4f(1, 1, 1, 1);
glClearColor(0, 0, 0, 1);
SDL_WM_SetCaption(g_extern.title_buf, NULL);
char buf[128];
if (gfx_window_title(buf, sizeof(buf)))
SDL_WM_SetCaption(buf, NULL);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

View File

@ -20,9 +20,11 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <math.h>
#ifdef HAVE_FREETYPE
#include "fonts.h"
#endif
#include "gfx_common.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@ -369,7 +371,11 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
XSetWindowBackground(xv->display, xv->window, 0);
XMapWindow(xv->display, xv->window);
XStoreName(xv->display, xv->window, g_extern.title_buf);
char buf[64];
if (gfx_window_title(buf, sizeof(buf)))
XStoreName(xv->display, xv->window, buf);
if (video->fullscreen)
set_fullscreen(xv);
hide_mouse(xv);
@ -537,21 +543,20 @@ static void calc_out_rect(bool keep_aspect, unsigned *x, unsigned *y, unsigned *
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
// assume they are actually equal.
if ( (int)(device_aspect*1000) > (int)(desired_aspect*1000) )
if (fabs(device_aspect - desired_aspect) < 0.0001)
{
*x = 0; *y = 0; *width = vp_width; *height = vp_height;
}
else if (device_aspect > desired_aspect)
{
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
*x = vp_width * (0.5 - delta); *y = 0; *width = 2.0 * vp_width * delta; *height = vp_height;
}
else if ( (int)(device_aspect*1000) < (int)(desired_aspect*1000) )
else
{
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
*x = 0; *y = vp_height * (0.5 - delta); *width = vp_width; *height = 2.0 * vp_height * delta;
}
else
{
*x = 0; *y = 0; *width = vp_width; *height = vp_height;
}
}
}
@ -629,6 +634,10 @@ static bool xv_frame(void *data, const void* frame, unsigned width, unsigned hei
x, y, owidth, oheight,
true);
char buf[64];
if (gfx_window_title(buf, sizeof(buf)))
XStoreName(xv->display, xv->window, buf);
return true;
}