From d8c96b82fa68bdc5b3a89780d0d2178a329f3293 Mon Sep 17 00:00:00 2001 From: Shaun Inman Date: Fri, 13 Jan 2023 20:12:47 -0500 Subject: [PATCH] only wait for vsync if under frame budget --- src/common/api.c | 18 +++++++++++------- src/common/api.h | 1 + src/minarch/main.c | 1 + src/minui/main.c | 11 +++++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/common/api.c b/src/common/api.c index 11f38ed..fee0de9 100644 --- a/src/common/api.c +++ b/src/common/api.c @@ -192,18 +192,22 @@ void GFX_clearAll(void) { memset(gfx.map, 0, gfx.map_size); } +static int frame_start = 0; +void GFX_startFrame(void) { + frame_start = SDL_GetTicks(); +} void GFX_flip(SDL_Surface* screen) { + static int ticks = 0; + ticks += 1; #ifdef GFX_ENABLE_VSYNC - int arg = 1; - ioctl(gfx.fb, OWLFB_WAITFORVSYNC, &arg); // TODO: this doesn't wait but it also doesn't error out like FBIO_WAITFORVSYNC... +#define FRAME_BUDGET 17 // 60fps + if (frame_start==0 || SDL_GetTicks()-frame_start