Skip to content

Commit

Permalink
Fix from review
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Dec 25, 2023
1 parent f6f39cd commit 84fa9a0
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 46 deletions.
8 changes: 4 additions & 4 deletions Client/game_sa/CFileLoaderSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void CFileLoaderSA::StaticSetHooks()
HookInstall(0x538690, (DWORD)CFileLoader_LoadObjectInstance, 5);
}

CBuildingSAInterface* CFileLoaderSA::LoadFileObjectInstance(SFileObjectInstance* obj)
CEntitySAInterface* CFileLoaderSA::LoadFileObjectInstance(SFileObjectInstance* obj)
{
return ((CBuildingSAInterface * (__cdecl*)(SFileObjectInstance*))0x538090)(obj);
return ((CEntitySAInterface * (__cdecl*)(SFileObjectInstance*))0x538090)(obj);
}

class CAtomicModelInfo
Expand Down Expand Up @@ -206,7 +206,7 @@ RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo*
return atomic;
}

CBuildingSAInterface* CFileLoader_LoadObjectInstance(const char* szLine)
CEntitySAInterface* CFileLoader_LoadObjectInstance(const char* szLine)
{
char szModelName[24];
SFileObjectInstance inst;
Expand All @@ -222,5 +222,5 @@ CBuildingSAInterface* CFileLoader_LoadObjectInstance(const char* szLine)
if (fLenSq > 0.0f && std::fabs(fLenSq - 1.0f) > std::numeric_limits<float>::epsilon())
inst.rotation /= std::sqrt(fLenSq);

return ((CBuildingSAInterface * (__cdecl*)(SFileObjectInstance*))0x538090)(&inst);
return ((CEntitySAInterface * (__cdecl*)(SFileObjectInstance*))0x538090)(&inst);
}
6 changes: 3 additions & 3 deletions Client/game_sa/CFileLoaderSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "CVector.h"
#include "CVector4D.h"

class CBuildingSAInterface;
class CEntitySAInterface;
struct RpAtomic;
struct RpClump;
struct RwStream;
Expand All @@ -29,11 +29,11 @@ class CFileLoaderSA
CFileLoaderSA();
~CFileLoaderSA();

CBuildingSAInterface* LoadFileObjectInstance(SFileObjectInstance*);
CEntitySAInterface* LoadFileObjectInstance(SFileObjectInstance*);

static void StaticSetHooks();
};

bool CFileLoader_LoadAtomicFile(RwStream* stream, unsigned int modelId);
RpAtomic* CFileLoader_SetRelatedModelInfoCB(RpAtomic* atomic, SRelatedModelInfo* pRelatedModelInfo);
CBuildingSAInterface* CFileLoader_LoadObjectInstance(const char* szLine);
CEntitySAInterface* CFileLoader_LoadObjectInstance(const char* szLine);
4 changes: 2 additions & 2 deletions Client/game_sa/CPoolsSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ CBuilding* CPoolsSA::AddBuilding(CClientBuilding* pClientBuilding, uint16_t mode
instance.rotation.fW = -instance.rotation.fW;

CFileLoaderSA loader{};
auto pBuilding = loader.LoadFileObjectInstance(&instance);
auto pBuilding = static_cast<CBuildingSAInterface*>(loader.LoadFileObjectInstance(&instance));

// Disable lod and ipl
pBuilding->m_pLod = nullptr;
Expand Down Expand Up @@ -807,7 +807,7 @@ DWORD CPoolsSA::GetObjectPoolIndex(std::uint8_t* pInterface)

DWORD CPoolsSA::GetBuildingPoolIndex(std::uint8_t* pInterface)
{
DWORD dwAlignedSize = 412;
DWORD dwAlignedSize = sizeof(CBuildingSAInterface);
std::uint8_t* pTheObjects = (std::uint8_t*)(*m_ppBuildingPoolInterface)->m_pObjects;
DWORD dwMaxIndex = MAX_BUILDINGS - 1;
if (pInterface < pTheObjects || pInterface > pTheObjects + (dwMaxIndex * dwAlignedSize))
Expand Down
17 changes: 10 additions & 7 deletions Client/mods/deathmatch/logic/CClientBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

#include "StdInc.h"

CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, uint16_t usModelId, CVector &pos, CVector &rot, uint8_t interior)
CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, uint16_t usModelId, const CVector &pos, const CVector &rot, uint8_t interior)
: ClassInit(this),
CClientEntity(ID),
m_pBuildingManager(pManager->GetBuildingManager()),
m_usModelId(usModelId),
m_vPos(pos),
m_vRot(rot),
m_interior(interior)
m_interior(interior),
m_pBuilding(nullptr)
{
m_pBuilding = nullptr;
m_pManager = pManager;
SetTypeName("building");
m_pBuildingManager->AddToList(this);
Expand All @@ -29,26 +29,29 @@ CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, u
CClientBuilding::~CClientBuilding()
{
m_pBuildingManager->RemoveFromList(this);
if (m_pBuilding)
{
Destroy();
}
Destroy();
}

void CClientBuilding::SetPosition(const CVector& vecPosition)
{
if (m_vPos == vecPosition)
return;
m_vPos = vecPosition;
Recreate();
}

void CClientBuilding::SetRotationRadians(const CVector& vecRadians)
{
if (m_vRot == vecRadians)
return;
m_vRot = vecRadians;
Recreate();
}

void CClientBuilding::SetInterior(uint8_t ucInterior)
{
if (m_interior == ucInterior)
return;
m_interior = ucInterior;
Recreate();
}
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientBuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CClientBuilding : public CClientEntity
friend class CClientBuildingManager;

public:
CClientBuilding(class CClientManager* pManager, ElementID ID, uint16_t usModelId, CVector &pos, CVector &rot, uint8_t interior);
CClientBuilding(class CClientManager* pManager, ElementID ID, uint16_t usModelId, const CVector &pos, const CVector &rot, uint8_t interior);
~CClientBuilding();

void Unlink(){};
Expand Down
22 changes: 5 additions & 17 deletions Client/mods/deathmatch/logic/CClientBuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,20 @@ void CClientBuildingManager::RemoveAll()
m_bRemoveFromList = false;

// Run through our list deleting the buildings
auto iter = m_List.begin();
for (; iter != m_List.end(); iter++)
for (CClientBuilding* building : m_List)
{
delete *iter;
delete building;
}

m_List.clear();

// Allow list removal again
m_bRemoveFromList = true;
}

bool CClientBuildingManager::Exists(CClientBuilding* pBuilding)
{
// Matches given DFF?
auto iter = m_List.begin();
for (; iter != m_List.end(); iter++)
{
// Match?
if (pBuilding == *iter)
{
// It exists
return true;
}
}

// It doesn't
return false;
return std::find(m_List.begin(), m_List.end(), pBuilding) != m_List.end();
}

void CClientBuildingManager::RemoveFromList(CClientBuilding* pBuilding)
Expand Down
6 changes: 1 addition & 5 deletions Client/mods/deathmatch/logic/CClientBuildingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ class CClientBuildingManager
void RemoveAll();
bool Exists(CClientBuilding* pBuilding);

std::list<CClientBuilding*>::const_iterator IterBegin() { return m_List.begin(); }
std::list<CClientBuilding*>::const_iterator IterEnd() { return m_List.end(); }
const std::list<CClientBuilding*>& GetBuildings() { return m_List; };

private:
void AddToList(CClientBuilding* pBuilding) { m_List.push_back(pBuilding); }
void RemoveFromList(CClientBuilding* pBuilding);

class CClientObjectManager* m_pObjectManager;
class CClientVehicleManager* m_pVehicleManager;

std::list<CClientBuilding*> m_List;
bool m_bRemoveFromList;
};
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CClientManager
CClientEffectManager* GetEffectManager() { return m_pEffectManager; }
CClientPointLightsManager* GetPointLightsManager() { return m_pPointLightsManager; }
CClientIMGManager* GetIMGManager() { return m_pImgManager; }
CClientBuildingManager* GetBuildingManager() { return m_pBuildingManager; }
CClientBuildingManager* GetBuildingManager() const noexcept { return m_pBuildingManager; }

bool IsGameLoaded() { return g_pGame->GetSystemState() == 9 && !m_bGameUnloadedFlag && g_pCore->GetNetwork()->GetServerBitStreamVersion(); }
bool IsBeingDeleted() { return m_bBeingDeleted; }
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ void CClientModel::RestoreDFF(CModelInfo* pModelInfo)

// Restore buildings
CClientBuildingManager* pBuildingsManager = g_pClientGame->GetManager()->GetBuildingManager();

unloadModelsAndCallEventsNonStreamed(pBuildingsManager->IterBegin(), pBuildingsManager->IterEnd(), usParentID,
auto& buildingsList = pBuildingsManager->GetBuildings();
unloadModelsAndCallEventsNonStreamed(buildingsList.begin(), buildingsList.end(), usParentID,
[=](auto& element) { element.SetModel(usParentID); });

// Restore COL
Expand Down
5 changes: 2 additions & 3 deletions Client/mods/deathmatch/logic/luadefs/CLuaBuildingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ CClientBuilding* CLuaBuildingDefs::CreateBuilding(lua_State* const luaVM, uint16
if (pos.fX < -3000.0f || pos.fX > 3000.0f || pos.fY < -3000.0f || pos.fY > 3000.0f)
throw std::invalid_argument("Position is outside of game world");

// Grab the resource root entity
CClientEntity* pRoot = pResource->GetResourceDynamicEntity();
ConvertDegreesToRadians(rot);

// Create the building handle
CClientBuilding* pBuilding = new CClientBuilding(m_pManager, INVALID_ELEMENT_ID, modelId, pos, rot, interior);

CClientEntity* pRoot = pResource->GetResourceDynamicEntity();
pBuilding->SetParent(pRoot);

return pBuilding;
Expand Down
2 changes: 1 addition & 1 deletion Shared/mods/deathmatch/logic/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ inline float GetSmallestWrapUnsigned(float fValue, float fHigh)

void RotateVector(CVector& vecLine, const CVector& vecRotation);

inline void ConvertEulersToQuaternion(const CVector& vecFrom, CVector4D vecTo)
inline void ConvertEulersToQuaternion(const CVector& vecFrom, CVector4D &vecTo)
{
double cy = cos(vecFrom.fZ * 0.5);
double sy = sin(vecFrom.fZ * 0.5);
Expand Down

0 comments on commit 84fa9a0

Please sign in to comment.