Skip to content

Commit

Permalink
Fix collision issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Dec 18, 2023
1 parent f8e7139 commit 5bc15b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Client/game_sa/CPoolsSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,24 +364,31 @@ inline bool CPoolsSA::AddBuildingToPool(CClientBuilding* pClientBuilding, CBuild

CBuilding* CPoolsSA::AddBuilding(class CClientBuilding* pClientBuilding, uint16_t modelId, CVector vPos, CVector4D vRot, uint8_t interior)
{
CFileLoaderSA loader{};

// Load building
SFileObjectInstance instance;
instance.modelID = modelId;
instance.lod = -1;
instance.interiorID = interior;
instance.position = vPos;
instance.rotation = vRot;

CFileLoaderSA loader{};
auto pBuilding = loader.LoadFileObjectInstance(&instance);

// Disable lod and ipl
pBuilding->m_pLod = nullptr;
pBuilding->m_iplIndex = 0;

pBuilding->AddRect();
// Always stream model collosion
// TODO We can setup collison bounding box and use GTA streamer for it
auto modelInfo = pGame->GetModelInfo(modelId);
modelInfo->AddColRef();

// Add building in world
auto pBuildingSA = new CBuildingSA(pBuilding);
pGame->GetWorld()->Add(pBuildingSA, CBuildingPool_Constructor);

// Add CBuildingSA object in pool
AddBuildingToPool(pClientBuilding, pBuildingSA);

return pBuildingSA;
Expand All @@ -399,6 +406,14 @@ void CPoolsSA::RemoveBuilding(CBuilding* pBuilding)
return;
}

// Remove building from world
pGame->GetWorld()->Remove(pInterface, CBuildingPool_Destructor);

// Remove col reference
auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex());
modelInfo->RemoveColRef();

// Remove from BuildingSA pool
auto* pBuildingSA = m_buildingPool.arrayOfClientEntities[dwElementIndexInPool].pEntity;
m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {nullptr, nullptr};

Expand Down
2 changes: 2 additions & 0 deletions Client/sdk/game/CWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ enum eDebugCaller
CCivPed_Constructor,
CCivPed_Destructor,
CBuilding_Destructor,
CBuildingPool_Constructor,
CBuildingPool_Destructor,

};

Expand Down

0 comments on commit 5bc15b1

Please sign in to comment.