Skip to content

Commit

Permalink
Add CopyWorldClean to fix ASan
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrc6 committed Dec 19, 2024
1 parent bfd2d66 commit 53cd576
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@ void CGameClient::OnPredict()

if(g_Config.m_ClRemoveAnti)
{
m_ExtraPredictedWorld.CopyWorld(&m_PredictedWorld);
m_ExtraPredictedWorld.CopyWorldClean(&m_PredictedWorld);

// Remove other tees to reduce lag and because they aren't really important in this case
for(int i = 0; i < MAX_CLIENTS; i++)
Expand Down Expand Up @@ -2687,7 +2687,7 @@ void CGameClient::OnPredict()
// Copy the current pred world so on the next tick we have the "previous" pred world to advance and test against

if(m_NewPredictedTick)
m_PredSmoothingWorld.CopyWorld(&m_PredictedWorld);
m_PredSmoothingWorld.CopyWorldClean(&m_PredictedWorld);

for(int i = 0; i < MAX_CLIENTS; i++)
{
Expand Down
49 changes: 49 additions & 0 deletions src/game/client/prediction/gameworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,55 @@ void CGameWorld::NetObjEnd()
}
}

void CGameWorld::CopyWorldClean(CGameWorld *pFrom)
{
if(pFrom == this || !pFrom)
return;
m_IsValidCopy = false;

m_GameTick = pFrom->m_GameTick;
m_pCollision = pFrom->m_pCollision;
m_WorldConfig = pFrom->m_WorldConfig;
for(int i = 0; i < 2; i++)
{
m_Core.m_aTuning[i] = pFrom->m_Core.m_aTuning[i];
}
m_pTuningList = pFrom->m_pTuningList;
m_Teams = pFrom->m_Teams;
m_Core.m_vSwitchers = pFrom->m_Core.m_vSwitchers;
// delete the previous entities
Clear();
for(int i = 0; i < MAX_CLIENTS; i++)
{
m_apCharacters[i] = 0;
m_Core.m_apCharacters[i] = 0;
}
// copy and add the new entities
for(int Type = 0; Type < NUM_ENTTYPES; Type++)
{
for(CEntity *pEnt = pFrom->FindLast(Type); pEnt; pEnt = pEnt->TypePrev())
{
CEntity *pCopy = 0;
if(Type == ENTTYPE_PROJECTILE)
pCopy = new CProjectile(*((CProjectile *)pEnt));
else if(Type == ENTTYPE_LASER)
pCopy = new CLaser(*((CLaser *)pEnt));
else if(Type == ENTTYPE_DRAGGER)
pCopy = new CDragger(*((CDragger *)pEnt));
else if(Type == ENTTYPE_CHARACTER)
pCopy = new CCharacter(*((CCharacter *)pEnt));
else if(Type == ENTTYPE_PICKUP)
pCopy = new CPickup(*((CPickup *)pEnt));
if(pCopy)
{
pCopy->m_pParent = nullptr;
pCopy->m_pChild = nullptr;
this->InsertEntity(pCopy);
}
}
}
}

void CGameWorld::CopyWorld(CGameWorld *pFrom)
{
if(pFrom == this || !pFrom)
Expand Down
1 change: 1 addition & 0 deletions src/game/client/prediction/gameworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CGameWorld
void NetObjAdd(int ObjId, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx);
void NetObjEnd();
void CopyWorld(CGameWorld *pFrom);
void CopyWorldClean(CGameWorld *pFrom); //TClient
CEntity *FindMatch(int ObjId, int ObjType, const void *pObjData);
void Clear();

Expand Down

0 comments on commit 53cd576

Please sign in to comment.