Rate-limit the game at 35 tics/s (17.5 FPS by default)

This commit is contained in:
Lephenixnoir 2021-09-18 23:21:40 +02:00
parent f13aeb14e7
commit 97b31a97d1
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 23 additions and 1 deletions

View File

@ -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);

View File

@ -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
//---