From f1685b14fe1f875b9a7f25e3f11de69acd493199 Mon Sep 17 00:00:00 2001 From: diekmann Date: Sun, 28 Mar 2021 21:18:11 +0200 Subject: [PATCH] Do NOT busy wait for a new game tick inside doom, return control to browser sooner. This improves the following: * the Animation frames per second went up from the ~35 to the target of 60! * my CPU fan stops spinning at full speed when playing doom in the browser, since the browser is better at controlling animations than busy waiting for time to progress. * The chrome developer console shows almost no more dropped frames. * the gameplay feels smoother, since there are no longer any hiccups. Do we give the browser more room for GC? * Firefox performance debugger now says: most "expensive function" with over 70% of time consumed is the browser's idle function! \m/ --- doom/linuxdoom-1.10/d_main.c | 5 ++++- doom/linuxdoom-1.10/d_net.c | 14 +++++++++++--- doom/linuxdoom-1.10/d_net.h | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doom/linuxdoom-1.10/d_main.c b/doom/linuxdoom-1.10/d_main.c index 4999f7f..56f8ef8 100644 --- a/doom/linuxdoom-1.10/d_main.c +++ b/doom/linuxdoom-1.10/d_main.c @@ -387,7 +387,10 @@ void D_DoomLoop_loop (void) { } else { - TryRunTics (); // will run at least one tic + if (TryRunTics() == 0){ + return; // web modification: do NOT busy wait for a new tick, return control to browser. + }; + // we did run at least one tic. } S_UpdateSounds (players[consoleplayer].mo);// move positional sounds diff --git a/doom/linuxdoom-1.10/d_net.c b/doom/linuxdoom-1.10/d_net.c index 75b5436..a1a4216 100644 --- a/doom/linuxdoom-1.10/d_net.c +++ b/doom/linuxdoom-1.10/d_net.c @@ -363,7 +363,7 @@ void GetPackets (void) // Builds ticcmds for console player, // sends out a packet // -int gametime; +int gametime = 0; void NetUpdate (void) { @@ -633,7 +633,7 @@ int oldnettics; extern boolean advancedemo; -void TryRunTics (void) +int TryRunTics (void) { int i; int lowtic; @@ -643,6 +643,11 @@ void TryRunTics (void) int availabletics; int counts; int numplaying; + + // web modification: do NOT busy wait for a new tick, return control to browser. + if (I_GetTime()/ticdup <= gametime){ + return 0; // no new tics available. + } // get real tics entertic = I_GetTime ()/ticdup; @@ -728,7 +733,7 @@ void TryRunTics (void) if (I_GetTime ()/ticdup - entertic >= 20) { M_Ticker (); - return; + return 1; } } @@ -764,4 +769,7 @@ void TryRunTics (void) } NetUpdate (); // check for new console commands } + + + return 1; } diff --git a/doom/linuxdoom-1.10/d_net.h b/doom/linuxdoom-1.10/d_net.h index b277472..ed779a6 100644 --- a/doom/linuxdoom-1.10/d_net.h +++ b/doom/linuxdoom-1.10/d_net.h @@ -136,7 +136,7 @@ void NetUpdate (void); void D_QuitNetGame (void); //? how many ticks to run? -void TryRunTics (void); +int TryRunTics (void); #endif