mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #4961
4961: Minor refactoring: Move/Merge variable declarations with assignments in CServer and CClient r=def- a=Robyt3 ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
015df60677
|
@ -667,8 +667,7 @@ void CClient::SetState(int s)
|
|||
void CClient::OnEnterGame(bool Dummy)
|
||||
{
|
||||
// reset input
|
||||
int i;
|
||||
for(i = 0; i < 200; i++)
|
||||
for(int i = 0; i < 200; i++)
|
||||
{
|
||||
m_aInputs[Dummy][i].m_Tick = -1;
|
||||
}
|
||||
|
@ -966,9 +965,8 @@ int CClient::LoadData()
|
|||
|
||||
void *CClient::SnapGetItem(int SnapID, int Index, CSnapItem *pItem) const
|
||||
{
|
||||
CSnapshotItem *i;
|
||||
dbg_assert(SnapID >= 0 && SnapID < NUM_SNAPSHOT_TYPES, "invalid SnapID");
|
||||
i = m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap->GetItem(Index);
|
||||
CSnapshotItem *i = m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap->GetItem(Index);
|
||||
pItem->m_DataSize = m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap->GetItemSize(Index);
|
||||
pItem->m_Type = m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap->GetItemType(Index);
|
||||
pItem->m_ID = i->ID();
|
||||
|
@ -983,9 +981,8 @@ int CClient::SnapItemSize(int SnapID, int Index) const
|
|||
|
||||
void CClient::SnapInvalidateItem(int SnapID, int Index)
|
||||
{
|
||||
CSnapshotItem *i;
|
||||
dbg_assert(SnapID >= 0 && SnapID < NUM_SNAPSHOT_TYPES, "invalid SnapID");
|
||||
i = m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap->GetItem(Index);
|
||||
CSnapshotItem *i = m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap->GetItem(Index);
|
||||
if(i)
|
||||
{
|
||||
if((char *)i < (char *)m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap || (char *)i > (char *)m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_pAltSnap + m_aSnapshots[g_Config.m_ClDummy][SnapID]->m_SnapSize)
|
||||
|
@ -1076,8 +1073,7 @@ void CClient::DebugRender()
|
|||
// render rates
|
||||
{
|
||||
int y = 0;
|
||||
int i;
|
||||
for(i = 0; i < 256; i++)
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
if(m_SnapshotDelta.GetDataRate(i))
|
||||
{
|
||||
|
@ -1899,13 +1895,8 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
|
|||
}
|
||||
else if(Msg == NETMSG_SNAP || Msg == NETMSG_SNAPSINGLE || Msg == NETMSG_SNAPEMPTY)
|
||||
{
|
||||
int NumParts = 1;
|
||||
int Part = 0;
|
||||
int GameTick = Unpacker.GetInt();
|
||||
int DeltaTick = GameTick - Unpacker.GetInt();
|
||||
int PartSize = 0;
|
||||
unsigned int Crc = 0;
|
||||
const char *pData = 0;
|
||||
|
||||
// only allow packets from the server we actually want
|
||||
if(net_addr_comp(&pPacket->m_Address, &m_ServerAddress))
|
||||
|
@ -1915,19 +1906,23 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
|
|||
if(State() < IClient::STATE_LOADING)
|
||||
return;
|
||||
|
||||
int NumParts = 1;
|
||||
int Part = 0;
|
||||
if(Msg == NETMSG_SNAP)
|
||||
{
|
||||
NumParts = Unpacker.GetInt();
|
||||
Part = Unpacker.GetInt();
|
||||
}
|
||||
|
||||
unsigned int Crc = 0;
|
||||
int PartSize = 0;
|
||||
if(Msg != NETMSG_SNAPEMPTY)
|
||||
{
|
||||
Crc = Unpacker.GetInt();
|
||||
PartSize = Unpacker.GetInt();
|
||||
}
|
||||
|
||||
pData = (const char *)Unpacker.GetRaw(PartSize);
|
||||
const char *pData = (const char *)Unpacker.GetRaw(PartSize);
|
||||
|
||||
if(Unpacker.Error() || NumParts < 1 || NumParts > CSnapshot::MAX_PARTS || Part < 0 || Part >= NumParts || PartSize < 0 || PartSize > MAX_SNAPSHOT_PACKSIZE)
|
||||
return;
|
||||
|
@ -2165,7 +2160,6 @@ void CClient::ResetMapDownload()
|
|||
|
||||
void CClient::FinishMapDownload()
|
||||
{
|
||||
const char *pError;
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", "download complete, loading map");
|
||||
|
||||
int Prev = m_MapdownloadTotalsize;
|
||||
|
@ -2176,7 +2170,7 @@ void CClient::FinishMapDownload()
|
|||
Storage()->RenameFile(m_aMapdownloadFilenameTemp, m_aMapdownloadFilename, IStorage::TYPE_SAVE);
|
||||
|
||||
// load map
|
||||
pError = LoadMap(m_aMapdownloadName, m_aMapdownloadFilename, pSha256, m_MapdownloadCrc);
|
||||
const char *pError = LoadMap(m_aMapdownloadName, m_aMapdownloadFilename, pSha256, m_MapdownloadCrc);
|
||||
if(!pError)
|
||||
{
|
||||
ResetMapDownload();
|
||||
|
@ -2550,7 +2544,7 @@ void CClient::Update()
|
|||
if(m_ReceivedSnapshots[g_Config.m_ClDummy] >= 3)
|
||||
{
|
||||
// switch snapshot
|
||||
int Repredict = 0;
|
||||
bool Repredict = false;
|
||||
int64_t Now = m_GameTime[g_Config.m_ClDummy].Get(time_get());
|
||||
int64_t PredNow = m_PredictedTime.Get(time_get());
|
||||
|
||||
|
@ -2558,7 +2552,7 @@ void CClient::Update()
|
|||
{
|
||||
// Load snapshot for m_ClDummy
|
||||
GameClient()->OnNewSnapshot();
|
||||
Repredict = 1;
|
||||
Repredict = true;
|
||||
}
|
||||
|
||||
while(true)
|
||||
|
@ -2581,7 +2575,7 @@ void CClient::Update()
|
|||
if(m_aSnapshots[g_Config.m_ClDummy][SNAP_CURRENT] && m_aSnapshots[g_Config.m_ClDummy][SNAP_PREV])
|
||||
{
|
||||
GameClient()->OnNewSnapshot();
|
||||
Repredict = 1;
|
||||
Repredict = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2615,7 +2609,7 @@ void CClient::Update()
|
|||
if(NewPredTick > m_PredTick[g_Config.m_ClDummy])
|
||||
{
|
||||
m_PredTick[g_Config.m_ClDummy] = NewPredTick;
|
||||
Repredict = 1;
|
||||
Repredict = true;
|
||||
|
||||
// send input
|
||||
SendInput();
|
||||
|
@ -3590,11 +3584,11 @@ void CClient::SaveReplay(const int Length, const char *pFilename)
|
|||
{
|
||||
// First we stop the recorder to slice correctly the demo after
|
||||
DemoRecorder_Stop(RECORDER_REPLAYS);
|
||||
char aFilename[IO_MAX_PATH_LENGTH];
|
||||
|
||||
char aDate[64];
|
||||
str_timestamp(aDate, sizeof(aDate));
|
||||
|
||||
char aFilename[IO_MAX_PATH_LENGTH];
|
||||
if(str_comp(pFilename, "") == 0)
|
||||
str_format(aFilename, sizeof(aFilename), "demos/replays/%s_%s (replay).demo", m_aCurrentMap, aDate);
|
||||
else
|
||||
|
@ -3629,8 +3623,6 @@ void CClient::DemoSlice(const char *pDstPath, CLIENTFUNC_FILTER pfnFilter, void
|
|||
|
||||
const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
||||
{
|
||||
const char *pError;
|
||||
|
||||
IOHANDLE File = Storage()->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||
if(!File)
|
||||
return "error opening demo file";
|
||||
|
@ -3649,7 +3641,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
|||
// load map
|
||||
int Crc = m_DemoPlayer.GetMapInfo()->m_Crc;
|
||||
SHA256_DIGEST Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
|
||||
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, Sha != SHA256_ZEROED ? &Sha : nullptr, Crc);
|
||||
const char *pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, Sha != SHA256_ZEROED ? &Sha : nullptr, Crc);
|
||||
if(pError)
|
||||
{
|
||||
if(!m_DemoPlayer.ExtractMap(Storage()))
|
||||
|
@ -3694,8 +3686,7 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
|||
#if defined(CONF_VIDEORECORDER)
|
||||
const char *CClient::DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName, int SpeedIndex)
|
||||
{
|
||||
const char *pError;
|
||||
pError = DemoPlayer_Play(pFilename, StorageType);
|
||||
const char *pError = DemoPlayer_Play(pFilename, StorageType);
|
||||
if(pError)
|
||||
return pError;
|
||||
m_ButtonRender = true;
|
||||
|
|
|
@ -874,22 +874,13 @@ void CServer::DoSnapshot()
|
|||
continue;
|
||||
|
||||
{
|
||||
char aData[CSnapshot::MAX_SIZE];
|
||||
CSnapshot *pData = (CSnapshot *)aData; // Fix compiler warning for strict-aliasing
|
||||
char aDeltaData[CSnapshot::MAX_SIZE];
|
||||
char aCompData[CSnapshot::MAX_SIZE];
|
||||
int Crc;
|
||||
static CSnapshot s_EmptySnap;
|
||||
CSnapshot *pDeltashot = &s_EmptySnap;
|
||||
int DeltashotSize;
|
||||
int DeltaTick = -1;
|
||||
int DeltaSize;
|
||||
|
||||
m_SnapshotBuilder.Init(m_aClients[i].m_Sixup);
|
||||
|
||||
GameServer()->OnSnap(i);
|
||||
|
||||
// finish snapshot
|
||||
char aData[CSnapshot::MAX_SIZE];
|
||||
CSnapshot *pData = (CSnapshot *)aData; // Fix compiler warning for strict-aliasing
|
||||
int SnapshotSize = m_SnapshotBuilder.Finish(pData);
|
||||
|
||||
if(m_aDemoRecorder[i].IsRecording())
|
||||
|
@ -898,7 +889,7 @@ void CServer::DoSnapshot()
|
|||
m_aDemoRecorder[i].RecordSnapshot(Tick(), aData, SnapshotSize);
|
||||
}
|
||||
|
||||
Crc = pData->Crc();
|
||||
int Crc = pData->Crc();
|
||||
|
||||
// remove old snapshos
|
||||
// keep 3 seconds worth of snapshots
|
||||
|
@ -908,10 +899,13 @@ void CServer::DoSnapshot()
|
|||
m_aClients[i].m_Snapshots.Add(m_CurrentGameTick, time_get(), SnapshotSize, pData, 0);
|
||||
|
||||
// find snapshot that we can perform delta against
|
||||
static CSnapshot s_EmptySnap;
|
||||
s_EmptySnap.Clear();
|
||||
|
||||
int DeltaTick = -1;
|
||||
CSnapshot *pDeltashot = &s_EmptySnap;
|
||||
{
|
||||
DeltashotSize = m_aClients[i].m_Snapshots.Get(m_aClients[i].m_LastAckedSnapshot, 0, &pDeltashot, 0);
|
||||
int DeltashotSize = m_aClients[i].m_Snapshots.Get(m_aClients[i].m_LastAckedSnapshot, 0, &pDeltashot, 0);
|
||||
if(DeltashotSize >= 0)
|
||||
DeltaTick = m_aClients[i].m_LastAckedSnapshot;
|
||||
else
|
||||
|
@ -925,16 +919,17 @@ void CServer::DoSnapshot()
|
|||
// create delta
|
||||
m_SnapshotDelta.SetStaticsize(protocol7::NETEVENTTYPE_SOUNDWORLD, m_aClients[i].m_Sixup);
|
||||
m_SnapshotDelta.SetStaticsize(protocol7::NETEVENTTYPE_DAMAGE, m_aClients[i].m_Sixup);
|
||||
DeltaSize = m_SnapshotDelta.CreateDelta(pDeltashot, pData, aDeltaData);
|
||||
char aDeltaData[CSnapshot::MAX_SIZE];
|
||||
int DeltaSize = m_SnapshotDelta.CreateDelta(pDeltashot, pData, aDeltaData);
|
||||
|
||||
if(DeltaSize)
|
||||
{
|
||||
// compress it
|
||||
const int MaxSize = MAX_SNAPSHOT_PACKSIZE;
|
||||
int NumPackets;
|
||||
|
||||
char aCompData[CSnapshot::MAX_SIZE];
|
||||
SnapshotSize = CVariableInt::Compress(aDeltaData, DeltaSize, aCompData, sizeof(aCompData));
|
||||
NumPackets = (SnapshotSize + MaxSize - 1) / MaxSize;
|
||||
int NumPackets = (SnapshotSize + MaxSize - 1) / MaxSize;
|
||||
|
||||
for(int n = 0, Left = SnapshotSize; Left > 0; n++)
|
||||
{
|
||||
|
@ -1241,7 +1236,6 @@ void CServer::SendRconLineAuthed(const char *pLine, void *pUser, ColorRGBA Print
|
|||
{
|
||||
CServer *pThis = (CServer *)pUser;
|
||||
static int s_ReentryGuard = 0;
|
||||
int i;
|
||||
|
||||
if(s_ReentryGuard)
|
||||
return;
|
||||
|
@ -1273,7 +1267,7 @@ void CServer::SendRconLineAuthed(const char *pLine, void *pUser, ColorRGBA Print
|
|||
pLineWithoutIps = aLineWithoutIps;
|
||||
}
|
||||
|
||||
for(i = 0; i < MAX_CLIENTS; i++)
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(pThis->m_aClients[i].m_State != CClient::STATE_EMPTY && pThis->m_aClients[i].m_Authed >= pThis->m_RconAuthLevel && (pThis->m_RconRestrict == -1 || pThis->m_RconRestrict == i))
|
||||
pThis->SendRconLine(i, pThis->m_aClients[i].m_ShowIps ? pLine : pLineWithoutIps);
|
||||
|
|
Loading…
Reference in a new issue