diff options
author | oy <tom_adams@web.de> | 2023-06-12 22:34:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 22:34:13 +0200 |
commit | aae3024c54b1a048a89e0383f444a0955b82b0a2 (patch) | |
tree | ea63b8acf7f557c7b89e44768a45a8862490de38 | |
parent | f24ef24fa4672fc084be1464d592988f27010369 (diff) | |
parent | 030253cef6de0648c9be13310730a09955981838 (diff) |
Merge pull request #3126 from Robyt3/Demo-Tick-Compression
Fix bug when reading reading chunks with a tick delta of 0
-rw-r--r-- | src/engine/shared/demo.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/engine/shared/demo.cpp b/src/engine/shared/demo.cpp index 4eb7a0631..009154202 100644 --- a/src/engine/shared/demo.cpp +++ b/src/engine/shared/demo.cpp @@ -14,7 +14,9 @@ #include "snapshot.h" static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0}; -static const unsigned char gs_ActVersion = 4; +static const unsigned char gs_ActVersion = 5; +static const unsigned char gs_OldVersion = 4; +static const unsigned char gs_VersionTickCompression = 5; // demo files with this version or higher will use `CHUNKTICKFLAG_TICK_COMPRESSED` static const int gs_LengthOffset = 152; static const int gs_NumMarkersOffset = 176; @@ -144,8 +146,10 @@ enum { CHUNKTYPEFLAG_TICKMARKER = 0x80, CHUNKTICKFLAG_KEYFRAME = 0x40, // only when tickmarker is set + CHUNKTICKFLAG_TICK_COMPRESSED = 0x20, // when we store the tick value in the first chunk - CHUNKMASK_TICK = 0x3f, + CHUNKMASK_TICK = 0x1f, + CHUNKMASK_TICK_LEGACY = 0x3f, CHUNKMASK_TYPE = 0x60, CHUNKMASK_SIZE = 0x1f, @@ -158,7 +162,7 @@ enum void CDemoRecorder::WriteTickMarker(int Tick, int Keyframe) { - if(m_LastTickMarker == -1 || Tick-m_LastTickMarker > 63 || Keyframe) + if(m_LastTickMarker == -1 || Tick-m_LastTickMarker > CHUNKMASK_TICK || Keyframe) { unsigned char aChunk[5]; aChunk[0] = CHUNKTYPEFLAG_TICKMARKER; @@ -172,7 +176,7 @@ void CDemoRecorder::WriteTickMarker(int Tick, int Keyframe) else { unsigned char aChunk[1]; - aChunk[0] = CHUNKTYPEFLAG_TICKMARKER | (Tick-m_LastTickMarker); + aChunk[0] = CHUNKTYPEFLAG_TICKMARKER | CHUNKTICKFLAG_TICK_COMPRESSED | (Tick-m_LastTickMarker); io_write(m_File, aChunk, sizeof(aChunk)); } @@ -376,20 +380,25 @@ int CDemoPlayer::ReadChunkHeader(int *pType, int *pSize, int *pTick) if(Chunk&CHUNKTYPEFLAG_TICKMARKER) { // decode tick marker - int Tickdelta = Chunk&(CHUNKMASK_TICK); + int Tickdelta_legacy = Chunk&(CHUNKMASK_TICK_LEGACY); // compatibility *pType = Chunk&(CHUNKTYPEFLAG_TICKMARKER|CHUNKTICKFLAG_KEYFRAME); - if(Tickdelta == 0) + if(m_Info.m_Header.m_Version < gs_VersionTickCompression && Tickdelta_legacy != 0) + { + *pTick += Tickdelta_legacy; + } + else if(Chunk&(CHUNKTICKFLAG_TICK_COMPRESSED)) + { + int Tickdelta = Chunk&(CHUNKMASK_TICK); + *pTick += Tickdelta; + } + else { unsigned char aTickData[4]; if(io_read(m_File, aTickData, sizeof(aTickData)) != sizeof(aTickData)) return -1; *pTick = bytes_be_to_int(aTickData); } - else - { - *pTick += Tickdelta; - } } else { @@ -650,7 +659,7 @@ const char *CDemoPlayer::Load(const char *pFilename, int StorageType, const char return m_aErrorMsg; } - if(m_Info.m_Header.m_Version != gs_ActVersion) + if(m_Info.m_Header.m_Version < gs_OldVersion) { str_format(m_aErrorMsg, sizeof(m_aErrorMsg), "demo version %d is not supported", m_Info.m_Header.m_Version); m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", m_aErrorMsg); @@ -870,7 +879,7 @@ bool CDemoPlayer::GetDemoInfo(const char *pFilename, int StorageType, CDemoHeade return false; io_read(File, pDemoHeader, sizeof(CDemoHeader)); - bool Valid = mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) == 0 && pDemoHeader->m_Version == gs_ActVersion; + bool Valid = mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) == 0 && pDemoHeader->m_Version >= gs_OldVersion; io_close(File); return Valid; } |