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

Method Load

src/engine/shared/demo.cpp:815–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

813}
814
815int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType)
816{
817 dbg_assert(m_File == 0, "Demo player already playing");
818
819 m_pConsole = pConsole;
820 str_copy(m_aFilename, pFilename);
821 str_copy(m_aErrorMessage, "");
822
823 if(m_pConsole)
824 {
825 char aBuf[32 + IO_MAX_PATH_LENGTH];
826 str_format(aBuf, sizeof(aBuf), "Loading demo '%s'", pFilename);
827 m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf);
828 }
829
830 // clear the playback info
831 mem_zero(&m_Info, sizeof(m_Info));
832 m_Info.m_Info.m_FirstTick = -1;
833 m_Info.m_Info.m_LastTick = -1;
834 m_Info.m_NextTick = -1;
835 m_Info.m_Info.m_CurrentTick = -1;
836 m_Info.m_PreviousTick = -1;
837 m_Info.m_Info.m_Speed = 1;
838 m_SpeedIndex = DEMO_SPEED_INDEX_DEFAULT;
839 m_LastSnapshotDataSize = -1;
840
841 if(!GetDemoInfo(pStorage, m_pConsole, pFilename, StorageType, &m_Info.m_Header, &m_Info.m_TimelineMarkers, &m_MapInfo, &m_File, m_aErrorMessage, sizeof(m_aErrorMessage)))
842 {
843 str_copy(m_aFilename, "");
844 return -1;
845 }
846 m_Sixup = str_startswith(m_Info.m_Header.m_aNetversion, "0.7");
847
848 // save byte offset of map for later use
849 m_MapOffset = io_tell(m_File);
850 if(m_MapOffset < 0 || io_skip(m_File, m_MapInfo.m_Size) != 0)
851 {
852 Stop("Error skipping map data");
853 return -1;
854 }
855
856 if(m_Info.m_Header.m_Version > gs_OldVersion)
857 {
858 // get timeline markers
859 int Num = bytes_be_to_uint(m_Info.m_TimelineMarkers.m_aNumTimelineMarkers);
860 m_Info.m_Info.m_NumTimelineMarkers = std::clamp<int>(Num, 0, MAX_TIMELINE_MARKERS);
861 for(int i = 0; i < m_Info.m_Info.m_NumTimelineMarkers; i++)
862 {
863 m_Info.m_Info.m_aTimelineMarkers[i] = bytes_be_to_uint(m_Info.m_TimelineMarkers.m_aTimelineMarkers[i]);
864 }
865 }
866
867 // Scan the file for interesting points
868 if(ScanFile() == EScanFileResult::ERROR_UNRECOVERABLE)
869 {
870 Stop("Error scanning demo file");
871 return -1;
872 }

Callers 1

SliceMethod · 0.45

Calls 8

str_formatFunction · 0.85
mem_zeroFunction · 0.85
str_startswithFunction · 0.85
io_tellFunction · 0.85
io_skipFunction · 0.85
bytes_be_to_uintFunction · 0.85
str_copyFunction · 0.50
PrintMethod · 0.45

Tested by

no test coverage detected