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

Method DoSnapshot

src/engine/server/server.cpp:998–1137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

996}
997
998void CServer::DoSnapshot()
999{
1000 bool IsGlobalSnap = Config()->m_SvHighBandwidth || (m_CurrentGameTick % 2) == 0;
1001
1002 if(m_aDemoRecorder[RECORDER_MANUAL].IsRecording() || m_aDemoRecorder[RECORDER_AUTO].IsRecording())
1003 {
1004 // create snapshot for demo recording
1005 char aData[CSnapshot::MAX_SIZE];
1006
1007 // build snap and possibly add some messages
1008 m_SnapshotBuilder.Init();
1009 GameServer()->OnSnap(-1, IsGlobalSnap, true);
1010 int SnapshotSize = m_SnapshotBuilder.Finish(aData);
1011
1012 // write snapshot
1013 if(m_aDemoRecorder[RECORDER_MANUAL].IsRecording())
1014 m_aDemoRecorder[RECORDER_MANUAL].RecordSnapshot(Tick(), aData, SnapshotSize);
1015 if(m_aDemoRecorder[RECORDER_AUTO].IsRecording())
1016 m_aDemoRecorder[RECORDER_AUTO].RecordSnapshot(Tick(), aData, SnapshotSize);
1017 }
1018
1019 // create snapshots for all clients
1020 for(int i = 0; i < MaxClients(); i++)
1021 {
1022 // client must be ingame to receive snapshots
1023 if(m_aClients[i].m_State != CClient::STATE_INGAME)
1024 continue;
1025
1026 // this client is trying to recover, don't spam snapshots
1027 if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_RECOVER && (Tick() % TickSpeed()) != 0)
1028 continue;
1029
1030 // this client is trying to recover, don't spam snapshots
1031 if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_INIT && (Tick() % 10) != 0)
1032 continue;
1033
1034 // only allow clients with forced high bandwidth on spectate to receive snapshots on non-global ticks
1035 if(!IsGlobalSnap && !(m_aClients[i].m_ForceHighBandwidthOnSpectate && GameServer()->IsClientHighBandwidth(i)))
1036 continue;
1037
1038 {
1039 m_SnapshotBuilder.Init(m_aClients[i].m_Sixup);
1040
1041 // only snap events on global ticks
1042 GameServer()->OnSnap(i, IsGlobalSnap, m_aDemoRecorder[i].IsRecording());
1043
1044 // finish snapshot
1045 char aData[CSnapshot::MAX_SIZE];
1046 CSnapshot *pData = (CSnapshot *)aData; // Fix compiler warning for strict-aliasing
1047 int SnapshotSize = m_SnapshotBuilder.Finish(pData);
1048
1049 if(m_aDemoRecorder[i].IsRecording())
1050 {
1051 // write snapshot
1052 m_aDemoRecorder[i].RecordSnapshot(Tick(), aData, SnapshotSize);
1053 }
1054
1055 int Crc = pData->Crc();

Callers

nothing calls this directly

Calls 15

time_getFunction · 0.85
OnSnapMethod · 0.80
RecordSnapshotMethod · 0.80
IsClientHighBandwidthMethod · 0.80
PurgeUntilMethod · 0.80
SetStaticsizeMethod · 0.80
CreateDeltaMethod · 0.80
AddIntMethod · 0.80
AddRawMethod · 0.80
OnPostGlobalSnapMethod · 0.80
ConfigFunction · 0.50
IsRecordingMethod · 0.45

Tested by

no test coverage detected