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

Method Update

src/engine/shared/demo.cpp:1119–1232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1117}
1118
1119void CDemoPlayer::Update(bool RealTime)
1120{
1121 const int64_t Now = Time();
1122 const int64_t Freq = time_freq();
1123 const int64_t DeltaTime = Now - m_Info.m_LastUpdate;
1124 m_Info.m_LastUpdate = Now;
1125
1126 if(m_Info.m_LiveStateUpdating)
1127 {
1128 // Determine if demo is live and still being written to, by scanning
1129 // file again and checking if more ticks are available than before.
1130 if(Now - m_Info.m_LastScan > Freq)
1131 {
1132 const int PreviousLastTick = m_Info.m_Info.m_LastTick;
1133 const EScanFileResult ScanResult = ScanFile();
1134 if(ScanResult == EScanFileResult::ERROR_UNRECOVERABLE)
1135 {
1136 Stop("Unrecoverable error on incrementally scanning demo file to determine live state");
1137 return;
1138 }
1139 else if(ScanResult == EScanFileResult::SUCCESS)
1140 {
1141 // Live state is known when ScanFile succeeded.
1142 m_Info.m_LiveStateUpdating = false;
1143 }
1144 else
1145 {
1146 m_Info.m_LiveStateFailedCount++;
1147 if(m_Info.m_LiveStateFailedCount >= 15)
1148 {
1149 // ScanFile keeps failing, which should be unlikely, so this is probably
1150 // not a live demo but a regular demo that is truncated at the end.
1151 m_Info.m_LiveStateUpdating = false;
1152 }
1153 }
1154 // Check if we got more ticks also when ScanFile failed, because
1155 // it could still have found more ticks.
1156 if(m_Info.m_Info.m_LastTick > PreviousLastTick)
1157 {
1158 m_Info.m_Info.m_LiveDemo = true;
1159 m_Info.m_LiveStateUpdating = false;
1160 m_Info.m_LiveStateUnchangedCount = 0;
1161 }
1162 m_Info.m_LastScan = Now;
1163 // Try again later if ScanFile failed and no more ticks were found.
1164 }
1165 }
1166 else if(m_Info.m_Info.m_LiveDemo)
1167 {
1168 // Scan live demo at tick frequency to smoothly update total time.
1169 if(Now - m_Info.m_LastScan > Freq / SERVER_TICK_SPEED)
1170 {
1171 const int PreviousLastTick = m_Info.m_Info.m_LastTick;
1172 const EScanFileResult ScanResult = ScanFile();
1173 if(ScanResult == EScanFileResult::ERROR_UNRECOVERABLE)
1174 {
1175 Stop("Unrecoverable error on incrementally scanning live demo file");
1176 return;

Callers 1

SliceMethod · 0.45

Calls 1

time_freqFunction · 0.85

Tested by

no test coverage detected