Skip to content

Commit

Permalink
Do NOT busy wait for a new game tick inside doom, return control to b…
Browse files Browse the repository at this point in the history
…rowser 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/
  • Loading branch information
diekmann committed Mar 28, 2021
1 parent 56bc37b commit f1685b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion doom/linuxdoom-1.10/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions doom/linuxdoom-1.10/d_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void GetPackets (void)
// Builds ticcmds for console player,
// sends out a packet
//
int gametime;
int gametime = 0;

void NetUpdate (void)
{
Expand Down Expand Up @@ -633,7 +633,7 @@ int oldnettics;

extern boolean advancedemo;

void TryRunTics (void)
int TryRunTics (void)
{
int i;
int lowtic;
Expand All @@ -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;
Expand Down Expand Up @@ -728,7 +733,7 @@ void TryRunTics (void)
if (I_GetTime ()/ticdup - entertic >= 20)
{
M_Ticker ();
return;
return 1;
}
}

Expand Down Expand Up @@ -764,4 +769,7 @@ void TryRunTics (void)
}
NetUpdate (); // check for new console commands
}


return 1;
}
2 changes: 1 addition & 1 deletion doom/linuxdoom-1.10/d_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void NetUpdate (void);
void D_QuitNetGame (void);

//? how many ticks to run?
void TryRunTics (void);
int TryRunTics (void);


#endif
Expand Down

0 comments on commit f1685b1

Please sign in to comment.