EXPERIMENTAL: Dedicated server idling system

- If no clients at server start or after 10 seconds of GS_LEVEL, and no Netxcmd waiting to be digested, halt all SV_MakeTic.
- It's absolutely netsafe to only have enabled on the host's end, the only risk is that a dedicated server might not re-awaken when presented with certain stimuli
This commit is contained in:
toaster 2022-11-05 22:48:39 +00:00
parent c77147fd1c
commit 0da626807c

View file

@ -5767,6 +5767,9 @@ void NetKeepAlive(void)
FileSendTicker(); FileSendTicker();
} }
// If a tree falls in the forest but nobody is around to hear it, does it make a tic?
#define DEDICATEDIDLETIME (10*TICRATE)
void NetUpdate(void) void NetUpdate(void)
{ {
static tic_t resptime = 0; static tic_t resptime = 0;
@ -5779,6 +5782,7 @@ void NetUpdate(void)
if (realtics <= 0) // nothing new to update if (realtics <= 0) // nothing new to update
return; return;
if (realtics > 5) if (realtics > 5)
{ {
if (server) if (server)
@ -5787,6 +5791,55 @@ void NetUpdate(void)
realtics = 5; realtics = 5;
} }
#ifdef DEDICATEDIDLETIME
if (server && dedicated && gamestate == GS_LEVEL)
{
static tic_t dedicatedidle = 0;
for (i = 1; i < MAXNETNODES; ++i)
if (nodeingame[i])
{
if (dedicatedidle == DEDICATEDIDLETIME)
{
CONS_Printf("DEDICATED: Awakening from idle (Node %d detected...)\n", i);
dedicatedidle = 0;
}
break;
}
if (i == MAXNETNODES)
{
if (leveltime == 2)
{
// On next tick...
dedicatedidle = DEDICATEDIDLETIME-1;
}
else if (dedicatedidle == DEDICATEDIDLETIME)
{
if (D_GetExistingTextcmd(gametic, 0) || D_GetExistingTextcmd(gametic+1, 0))
{
CONS_Printf("DEDICATED: Awakening from idle (Netxcmd detected...)\n");
dedicatedidle = 0;
}
else
{
realtics = 0;
}
}
else if ((dedicatedidle += realtics) >= DEDICATEDIDLETIME)
{
const char *idlereason = "at round start";
if (leveltime > 3)
idlereason = va("for %d seconds", dedicatedidle/TICRATE);
CONS_Printf("DEDICATED: No nodes %s, idling...\n", idlereason);
realtics = 0;
dedicatedidle = DEDICATEDIDLETIME;
}
}
}
#endif
gametime = nowtime; gametime = nowtime;
UpdatePingTable(); UpdatePingTable();
@ -5824,7 +5877,7 @@ void NetUpdate(void)
} }
else else
{ {
if (!demo.playback) if (!demo.playback && realtics > 0)
{ {
INT32 counts; INT32 counts;