MCPcopy Create free account
hub / github.com/ddnet/ddnet / Slice

Method Slice

src/engine/shared/demo.cpp:1417–1480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1415}
1416
1417bool CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int EndTick, DEMOFUNC_FILTER pfnFilter, void *pUser)
1418{
1419 CDemoPlayer DemoPlayer(m_pSnapshotDelta, false);
1420 if(DemoPlayer.Load(m_pStorage, m_pConsole, pDemo, IStorage::TYPE_ALL_OR_ABSOLUTE) == -1)
1421 return false;
1422
1423 const CMapInfo *pMapInfo = DemoPlayer.GetMapInfo();
1424 const CDemoPlayer::CPlaybackInfo *pInfo = DemoPlayer.Info();
1425
1426 std::optional<SHA256_DIGEST> Sha256 = pMapInfo->m_Sha256;
1427 if(pInfo->m_Header.m_Version < gs_Sha256Version)
1428 {
1429 if(DemoPlayer.ExtractMap(m_pStorage))
1430 {
1431 Sha256 = pMapInfo->m_Sha256;
1432 }
1433 }
1434 if(!Sha256.has_value())
1435 {
1436 log_error_color(DEMO_PRINT_COLOR, "demo/slice", "Failed to start demo slicing because map SHA256 could not be determined.");
1437 return false;
1438 }
1439
1440 CDemoRecorder DemoRecorder(m_pSnapshotDelta);
1441 unsigned char *pMapData = DemoPlayer.GetMapData(m_pStorage);
1442 const int Result = DemoRecorder.Start(m_pStorage, m_pConsole, pDst, pInfo->m_Header.m_aNetversion, pMapInfo->m_aName, Sha256.value(), pMapInfo->m_Crc, pInfo->m_Header.m_aType, pMapInfo->m_Size, pMapData, nullptr, pfnFilter, pUser) == -1;
1443 free(pMapData);
1444 if(Result != 0)
1445 {
1446 DemoPlayer.Stop();
1447 return false;
1448 }
1449
1450 CDemoRecordingListener Listener;
1451 Listener.m_pDemoRecorder = &DemoRecorder;
1452 Listener.m_pDemoPlayer = &DemoPlayer;
1453 Listener.m_Stop = false;
1454 Listener.m_StartTick = StartTick;
1455 Listener.m_EndTick = EndTick;
1456 DemoPlayer.SetListener(&Listener);
1457
1458 DemoPlayer.Play();
1459
1460 while(DemoPlayer.IsPlaying() && !Listener.m_Stop)
1461 {
1462 DemoPlayer.Update(false);
1463
1464 if(pInfo->m_Info.m_Paused)
1465 break;
1466 }
1467
1468 // Copy timeline markers to sliced demo
1469 for(int i = 0; i < pInfo->m_Info.m_NumTimelineMarkers; i++)
1470 {
1471 if((StartTick == -1 || pInfo->m_Info.m_aTimelineMarkers[i] >= StartTick) && (EndTick == -1 || pInfo->m_Info.m_aTimelineMarkers[i] <= EndTick))
1472 {
1473 DemoRecorder.AddDemoMarker(pInfo->m_Info.m_aTimelineMarkers[i]);
1474 }

Callers 2

DemoSliceMethod · 0.80
RunMethod · 0.80

Calls 12

GetMapInfoMethod · 0.80
InfoMethod · 0.80
ExtractMapMethod · 0.80
GetMapDataMethod · 0.80
SetListenerMethod · 0.80
AddDemoMarkerMethod · 0.80
LoadMethod · 0.45
StartMethod · 0.45
StopMethod · 0.45
PlayMethod · 0.45
IsPlayingMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected