Multiple issues fixed for seamless transitions:
Server lifecycle:
- SV_Shutdown before devmap in SVD_Play_f: drops old clients so
spectator doesn't land in slot 0 (recorded player collision)
- SVD_IsStarting flag prevents cleanup hooks from destroying demo
state during our own SV_Shutdown/SV_SpawnServer calls
- SV_SpawnServer stops demo playback on non-demo map changes
via SVD_CleanupPlayback (no disconnect, just state cleanup)
- SVD_CleanupPlayback made non-static for use from sv_init.c
Cvar handling:
- Use Cvar_Set2 with force=qtrue for CVAR_ROM sv_demoplaying
- Set cvar AFTER SV_Shutdown (old game module gone) but BEFORE
devmap (so new G_InitGame reads correct value)
- Set CS_SVDEMO configstring after devmap as backup for cgame
Game module:
- ClientBegin: set pm_type=PM_SPECTATOR after ClientSpawn (which
memsets ps). ClientThink_real normally sets this but is disabled
in demo mode.
- G_WriteSessionData: skip during demo playback so forced
TEAM_SPECTATOR doesn't persist to next normal game
- ClientThink: return early in demo mode (no server-side movement)
Removed debug prints and unused SVD_GetPlayMaxClients.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Delta-compressed entity/playerState bitstreams have minimal
redundancy for LZ4 to exploit. The per-block 8-byte header
overhead was comparable to the compression savings.
Removed: lz4.h include, SVD_WriteBlock/ReadBlock functions,
SVDEMO_FLAG_COMPRESSED, demo.compressed field, svdemo_compress
cvar, lz4.c from build. Direct size+data writes replace block I/O.
Demo format v3 (flags field reserved, always 0).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
svdemo_pauseEmpty (default: 1) pauses frame processing when no
client is CS_ACTIVE during demo playback. Prevents the demo from
advancing with nobody watching. Time residual is cleared so the
demo resumes from where it paused when a spectator connects.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Per-frame entity and playerState blocks are compressed with LZ4
when svdemo_compress is set (default: 1). The block format writes
[original_size][compressed_size][data] — compressed_size=0 means
uncompressed. Playback auto-detects based on header flags.
Demo format bumped to version 2 with SVDEMO_FLAG_COMPRESSED flag.
Version 1 (uncompressed) demos are no longer compatible.
Uses the lz4.c/lz4.h library already in the server code directory.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Set svdemo_autorecord 1 to automatically record a demo on every
map load. Demo files are named <mapname>_YYYYMMDD_HHMMSS.svdm
in the svdemos/ directory.
Refactored SVD_Record_f to use SVD_StartRecording helper so both
manual and auto recording share the same code path. Also fixed
prevPlayers delta state not being cleared on recording start.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SV_SpawnServer reinitializes the game module, invalidating all
entity and configstring state. Recording across a map boundary
would produce corrupt deltas. Stop recording automatically at
the start of SV_SpawnServer (before game shutdown).
map_restart is unaffected — it has its own path (SV_MapRestart_f)
which doesn't call SV_SpawnServer.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract SVD_CleanupPlayback for shared cleanup logic
- Called on demo end (SVD_PlaybackFrame) and manual stop
- Frees zombie client slots, saved configstrings, file handle
- Clears sv_demoplaying cvar so game module exits demo mode
- Hook into SV_Shutdown to clean up on server shutdown/map change
- Allows playing another demo after one finishes
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>