Start demo playback only when spectator enters game

Move pause check from SV_Frame (which blocked connection handshake)
into SVD_PlaybackFrame. The server runs frames normally so clients
can connect and load, but demo data isn't consumed until a client
reaches CS_ACTIVE. The spectator sees the demo from the very first
frame without missing any gameplay.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
serge_shubin 2026-03-23 23:46:46 +08:00
parent fcd5fc6ce8
commit 0b4eb7b69f
2 changed files with 9 additions and 8 deletions

View file

@ -828,12 +828,6 @@ void SV_Frame( int msec ) {
if (com_dedicated->integer) SV_BotFrame( svs.time );
// demo playback: pause if no spectators are watching
if ( SVD_IsPlaying() && SVD_ShouldPause() ) {
sv.timeResidual = 0;
return;
}
// run the game simulation in chunks
while ( sv.timeResidual >= frameMsec ) {
sv.timeResidual -= frameMsec;

View file

@ -1007,6 +1007,13 @@ qboolean SVD_PlaybackFrame( void ) {
return qfalse;
}
// wait for a spectator to be fully in-game before starting playback.
// the server keeps running frames (so the connection handshake completes)
// but no demo data is consumed until someone is CS_ACTIVE.
if ( SVD_ShouldPause() ) {
return qfalse;
}
// apply recorded configstrings once after map load
if ( demo.needConfigstrings ) {
SVD_ApplyConfigstrings();
@ -1047,8 +1054,8 @@ qboolean SVD_ShouldPause( void ) {
}
for ( i = 0; i < sv_maxclients->integer; i++ ) {
if ( svs.clients[i].state >= CS_CONNECTED ) {
return qfalse; // someone is connected or connecting
if ( svs.clients[i].state == CS_ACTIVE ) {
return qfalse; // someone is in-game and watching
}
}