Copy the demo timeline markers when slicing a demo

When slicing a demo, also copy the demo markers that are within the sliced segment to the new demo.

This also fixes timeline markers not being added to replay demos, as the replay demos are always created by slicing.

Closes #6116.
This commit is contained in:
Robert Müller 2022-12-11 13:53:20 +01:00
parent 63187f565f
commit 7958b999a3
2 changed files with 22 additions and 3 deletions

View file

@ -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)

View file

@ -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);