diff --git a/src/engine/shared/demo.cpp b/src/engine/shared/demo.cpp index 016c6a457..6193e2755 100644 --- a/src/engine/shared/demo.cpp +++ b/src/engine/shared/demo.cpp @@ -371,18 +371,26 @@ int CDemoRecorder::Stop() void CDemoRecorder::AddDemoMarker() { - if(m_LastTickMarker < 0 || m_NumTimelineMarkers >= MAX_TIMELINE_MARKERS) + if(m_LastTickMarker < 0) + return; + AddDemoMarker(m_LastTickMarker); +} + +void CDemoRecorder::AddDemoMarker(int Tick) +{ + dbg_assert(Tick >= 0, "invalid marker tick"); + if(m_NumTimelineMarkers >= MAX_TIMELINE_MARKERS) return; // not more than 1 marker in a second if(m_NumTimelineMarkers > 0) { - int Diff = m_LastTickMarker - m_aTimelineMarkers[m_NumTimelineMarkers - 1]; + int Diff = Tick - m_aTimelineMarkers[m_NumTimelineMarkers - 1]; if(Diff < (float)SERVER_TICK_SPEED) return; } - m_aTimelineMarkers[m_NumTimelineMarkers++] = m_LastTickMarker; + m_aTimelineMarkers[m_NumTimelineMarkers++] = Tick; if(m_pConsole) m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", "Added timeline marker", gs_DemoPrintColor); @@ -1172,6 +1180,15 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int break; } + // Copy timeline markers to sliced demo + for(int i = 0; i < pInfo->m_Info.m_NumTimelineMarkers; i++) + { + if((m_SliceFrom == -1 || pInfo->m_Info.m_aTimelineMarkers[i] >= m_SliceFrom) && (m_SliceTo == -1 || pInfo->m_Info.m_aTimelineMarkers[i] <= m_SliceTo)) + { + m_pDemoRecorder->AddDemoMarker(pInfo->m_Info.m_aTimelineMarkers[i]); + } + } + m_pDemoPlayer->Stop(); m_pDemoRecorder->Stop(); } // NOLINT(clang-analyzer-unix.Malloc) diff --git a/src/engine/shared/demo.h b/src/engine/shared/demo.h index f301c35d0..589f6ec38 100644 --- a/src/engine/shared/demo.h +++ b/src/engine/shared/demo.h @@ -40,7 +40,9 @@ public: int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, SHA256_DIGEST *pSha256, unsigned MapCrc, const char *pType, unsigned MapSize, unsigned char *pMapData, IOHANDLE MapFile = nullptr, DEMOFUNC_FILTER pfnFilter = nullptr, void *pUser = nullptr); int Stop() override; + void AddDemoMarker(); + void AddDemoMarker(int Tick); void RecordSnapshot(int Tick, const void *pData, int Size); void RecordMessage(const void *pData, int Size);