light cleanup

This commit is contained in:
Shaun Inman 2023-01-28 20:24:01 -05:00
parent 103e21d54a
commit b3283adf0b

View file

@ -55,7 +55,7 @@ static int show_debug = 0;
static int max_ff_speed = 3; // 4x static int max_ff_speed = 3; // 4x
static int fast_forward = 0; static int fast_forward = 0;
static struct { static struct Renderer {
int src_w; int src_w;
int src_h; int src_h;
int src_p; int src_p;
@ -490,7 +490,7 @@ enum {
CONFIG_GAME, CONFIG_GAME,
}; };
static struct { static struct Config {
OptionList core; OptionList core;
OptionList frontend; OptionList frontend;
ButtonMapping* controls; ButtonMapping* controls;
@ -990,10 +990,10 @@ static void input_poll_callback(void) {
} }
// TODO: tmp? // TODO: tmp?
if ((PAD_isPressed(BTN_L2) && PAD_justPressed(BTN_R2)) || PAD_isPressed(BTN_R2) && PAD_justPressed(BTN_L2)) { // if ((PAD_isPressed(BTN_L2) && PAD_justPressed(BTN_R2)) || PAD_isPressed(BTN_R2) && PAD_justPressed(BTN_L2)) {
show_debug = !show_debug; // show_debug = !show_debug;
config.frontend.options[FE_OPT_DEBUG].value = show_debug; // TODO: standardize this for all config.frontend? // config.frontend.options[FE_OPT_DEBUG].value = show_debug; // TODO: standardize this for all config.frontend?
} // }
// TODO: test fast_forward once implemented // TODO: test fast_forward once implemented
for (int i=0; i<SHORTCUT_COUNT; i++) { for (int i=0; i<SHORTCUT_COUNT; i++) {
@ -2051,7 +2051,7 @@ static void selectScaler(int width, int height, int pitch) {
} }
static void video_refresh_callback(const void *data, unsigned width, unsigned height, size_t pitch) { static void video_refresh_callback(const void *data, unsigned width, unsigned height, size_t pitch) {
if (!data) return; if (!data) return;
fps_ticks += 1; // comment out with threaded renderer fps_ticks += 1;
if (width!=renderer.src_w || height!=renderer.src_h) { if (width!=renderer.src_w || height!=renderer.src_h) {
renderer.src_w = width; renderer.src_w = width;
@ -2060,12 +2060,6 @@ static void video_refresh_callback(const void *data, unsigned width, unsigned he
selectScaler(width,height,pitch); selectScaler(width,height,pitch);
GFX_clearAll(); GFX_clearAll();
// if (renderer.src) {
// free(renderer.src);
// renderer.src = NULL;
// }
// renderer.src = malloc(height * pitch);
} }
static int top_width = 0; static int top_width = 0;
@ -2153,21 +2147,6 @@ static void video_refresh_callback(const void *data, unsigned width, unsigned he
} }
GFX_flip(screen); GFX_flip(screen);
return; // TODO: tmp
// measure framerate
// static int ticks = 0;
// static uint32_t start = -1;
// ticks += 1;
// uint32_t now = SDL_GetTicks();
// if (start==-1) start = now;
// if (now-start>=1000) {
// start = now;
// printf("fps: %i\n", ticks);
// fflush(stdout);
// ticks = 0;
// }
} }
/////////////////////////////// ///////////////////////////////
@ -3477,6 +3456,25 @@ finish:
return ticks; return ticks;
} }
static void trackFPS(void) {
cpu_ticks += 1;
static int last_use_ticks = 0;
uint32_t now = SDL_GetTicks();
if (now - sec_start>=1000) {
double last_time = (double)(now - sec_start) / 1000;
fps_double = fps_ticks / last_time;
cpu_double = cpu_ticks / last_time;
use_ticks = getUsage();
if (use_ticks && last_use_ticks) {
use_double = (use_ticks - last_use_ticks) / last_time;
}
last_use_ticks = use_ticks;
sec_start = now;
cpu_ticks = 0;
fps_ticks = 0;
}
}
int main(int argc , char* argv[]) { int main(int argc , char* argv[]) {
// force a stack overflow to ensure asan is linked and actually working // force a stack overflow to ensure asan is linked and actually working
// char tmp[2]; // char tmp[2];
@ -3492,9 +3490,6 @@ int main(int argc , char* argv[]) {
screen = GFX_init(MODE_MENU); screen = GFX_init(MODE_MENU);
// doesn't even help that much with Star Fox after overclocking
// GFX_setVsync(VSYNC_STRICT);
MSG_init(); MSG_init();
InitSettings(); InitSettings();
@ -3502,9 +3497,6 @@ int main(int argc , char* argv[]) {
Core_init(); Core_init();
// TODO: find a better place to do this, mixing static and loaded data is messy // TODO: find a better place to do this, mixing static and loaded data is messy
// char core_desc[MAX_PATH];
// sprintf(core_desc, "%s / %s", core.tag, core.version);
// options_menu.items[1].desc = core_desc;
options_menu.items[1].desc = (char*)core.version; options_menu.items[1].desc = (char*)core.version;
Game_open(rom_path); Game_open(rom_path);
@ -3527,26 +3519,7 @@ int main(int argc , char* argv[]) {
if (show_menu) Menu_loop(); if (show_menu) Menu_loop();
if (1) { trackFPS();
cpu_ticks += 1;
static int last_use_ticks = 0;
uint32_t now = SDL_GetTicks();
if (now - sec_start>=1000) {
double last_time = (double)(now - sec_start) / 1000;
fps_double = fps_ticks / last_time;
cpu_double = cpu_ticks / last_time;
use_ticks = getUsage();
if (use_ticks && last_use_ticks) {
use_double = (use_ticks - last_use_ticks) / last_time;
}
last_use_ticks = use_ticks;
sec_start = now;
cpu_ticks = 0;
fps_ticks = 0;
// printf("fps: %f (%f)\n", fps_double, cpu_double); fflush(stdout);
}
}
} }
Menu_quit(); Menu_quit();