From 97b31a97d19884ee92f686321181d34f01c501b3 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sat, 18 Sep 2021 23:21:40 +0200 Subject: [PATCH] Rate-limit the game at 35 tics/s (17.5 FPS by default) --- cgdoom/hu_stuff.c | 2 +- cgdoom/i_system.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cgdoom/hu_stuff.c b/cgdoom/hu_stuff.c index d867302..0c27d23 100644 --- a/cgdoom/hu_stuff.c +++ b/cgdoom/hu_stuff.c @@ -232,7 +232,7 @@ void HU_Start(void) /* CGDoom: Create the FPS counter widget */ HUlib_initSText(&w_fpscounter, - SCREENWIDTH-48, HU_MSGY, HU_MSGHEIGHT, + SCREENWIDTH-44, HU_MSGY, HU_MSGHEIGHT, hu_font, HU_FONTSTART, &fpscounter_on); diff --git a/cgdoom/i_system.c b/cgdoom/i_system.c index 0e90d6b..32a68d8 100644 --- a/cgdoom/i_system.c +++ b/cgdoom/i_system.c @@ -245,6 +245,28 @@ void I_StartTic (void) { extern int giRefreshMask; + //--- + // Rate limiter + //--- + + static boolean ratelimit_started = false; + static prof_t ratelimit_ctx = prof_make(); + + /* Rate limit the game at 35 tics per second, but only extend tics where we + display frames, because that's when all the work is done */ + if(!(gametic & giRefreshMask)) { + if(ratelimit_started) { + while(1) { + prof_t temp = ratelimit_ctx; + prof_leave(temp); + if(prof_time(temp) >= 28571 * (giRefreshMask + 1)) break; + } + ratelimit_ctx = prof_make(); + } + prof_enter(ratelimit_ctx); + ratelimit_started = true; + } + //--- // FPS counter //---