Skip to content

Commit

Permalink
Merge branch 'master' into TheNormalnij/engine_set_pool_size
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij authored May 26, 2024
2 parents 1889af3 + 545f54b commit 26ea3f9
Show file tree
Hide file tree
Showing 29 changed files with 726 additions and 309 deletions.
49 changes: 49 additions & 0 deletions Client/game_sa/CBuildingSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,57 @@

#include "StdInc.h"
#include "CBuildingSA.h"
#include <game/CWorld.h>
#include "CGameSA.h"

extern CGameSA* pGame;

CBuildingSA::CBuildingSA(CBuildingSAInterface* pInterface)
{
SetInterface(pInterface);
}

void CBuildingSA::SetLod(CBuilding* pLod)
{
if (pLod)
{
if (m_pInterface->m_pLod)
{
SetLod(nullptr);
}

CBuildingSAInterface* pLodInterface = dynamic_cast<CBuildingSA*>(pLod)->GetBuildingInterface();
assert(pLodInterface);

// We should recreate buildings...
pGame->GetWorld()->Remove(pLodInterface, CBuilding_SetLod);
pGame->GetWorld()->Remove(m_pInterface, CBuilding_SetLod);

m_pInterface->m_pLod = pLodInterface;
pLodInterface->bUsesCollision = 0;
pLodInterface->numLodChildren = 1;

if (pGame->GetModelInfo(pLodInterface->m_nModelIndex)->GetLODDistance() > 300)
{
pLodInterface->bIsBIGBuilding = 1;
}

// Only this specific order works
pGame->GetWorld()->Add(m_pInterface, CBuilding_SetLod);
pGame->GetWorld()->Add(pLodInterface, CBuilding_SetLod);
}
else
{
CEntitySAInterface* pCurrentLod = m_pInterface->m_pLod;
if (pCurrentLod)
{
pGame->GetWorld()->Remove(pCurrentLod, CBuilding_SetLod);

m_pInterface->m_pLod = nullptr;
pCurrentLod->bIsBIGBuilding = false;
pCurrentLod->numLodChildren = 0;

pGame->GetWorld()->Add(pCurrentLod, CBuilding_SetLod);
}
}
}
4 changes: 3 additions & 1 deletion Client/game_sa/CBuildingSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ class CBuildingSA final : public virtual CBuilding, public virtual CEntitySA
public:
CBuildingSA(CBuildingSAInterface* pInterface);

CBuildingSAInterface* GetBuildingInterface() { return reinterpret_cast<CBuildingSAInterface*>(GetInterface()); };
CBuildingSAInterface* GetBuildingInterface() { return static_cast<CBuildingSAInterface*>(GetInterface()); };

void SetLod(CBuilding* pLod) override;
};
18 changes: 6 additions & 12 deletions Client/game_sa/CPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ extern CGameSA* pGame;

int g_bOnlyUpdateRotations = false;

CPedSA::CPedSA() : m_pPedIntelligence(NULL), m_pPedInterface(NULL), m_pPedSound(NULL),
m_pDefaultPedSound(NULL), m_iCustomMoveAnim(0)
{
MemSetFast(m_pWeapons, 0, sizeof(CWeaponSA*) * WEAPONSLOT_MAX);
}

CPedSA::CPedSA(CPedSAInterface* pPedInterface) : m_pPedIntelligence(NULL), m_pPedInterface(pPedInterface),
m_pPedSound(NULL), m_pDefaultPedSound(NULL), m_iCustomMoveAnim(0)
CPedSA::CPedSA(CPedSAInterface* pPedInterface) noexcept
: m_pPedInterface(pPedInterface)
{
MemSetFast(m_pWeapons, 0, sizeof(CWeaponSA*) * WEAPONSLOT_MAX);
}
Expand All @@ -50,8 +44,6 @@ CPedSA::~CPedSA()
delete m_pPedIntelligence;
if (m_pPedSound)
delete m_pPedSound;
if (m_pDefaultPedSound)
delete m_pDefaultPedSound;

for (int i = 0; i < WEAPONSLOT_MAX; i++)
{
Expand Down Expand Up @@ -94,7 +86,9 @@ void CPedSA::Init()
CPedIntelligenceSAInterface* m_pPedIntelligenceInterface = (CPedIntelligenceSAInterface*)(dwPedIntelligence);
m_pPedIntelligence = new CPedIntelligenceSA(m_pPedIntelligenceInterface, this);
m_pPedSound = new CPedSoundSA(&pedInterface->pedSound);
m_pDefaultPedSound = new CPedSoundSA(&pedInterface->pedSound);

m_sDefaultVoiceType = m_pPedSound->GetVoiceTypeID();
m_sDefaultVoiceID = m_pPedSound->GetVoiceID();

for (int i = 0; i < WEAPONSLOT_MAX; i++)
m_pWeapons[i] = new CWeaponSA(&(pedInterface->Weapons[i]), this, (eWeaponSlot)i);
Expand Down Expand Up @@ -953,7 +947,7 @@ void CPedSA::SetVoice(const char* szVoiceType, const char* szVoice)

void CPedSA::ResetVoice()
{
SetVoice(m_pDefaultPedSound->GetVoiceTypeID(), m_pDefaultPedSound->GetVoiceID());
SetVoice(m_sDefaultVoiceType, m_sDefaultVoiceID);
}

// GetCurrentWeaponStat will only work if the game ped context is currently set to this ped
Expand Down
19 changes: 10 additions & 9 deletions Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,23 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
friend class CPoolsSA;

private:
CWeaponSA* m_pWeapons[WEAPONSLOT_MAX];
CPedIKSA* m_pPedIK;
CPedIntelligenceSA* m_pPedIntelligence;
CPedSAInterface* m_pPedInterface;
CPedSoundSA* m_pPedSound;
CPedSoundSA* m_pDefaultPedSound;
CWeaponSA* m_pWeapons[WEAPONSLOT_MAX]{};
CPedIKSA* m_pPedIK{};
CPedIntelligenceSA* m_pPedIntelligence{};
CPedSAInterface* m_pPedInterface{};
CPedSoundSA* m_pPedSound{};

short m_sDefaultVoiceType;
short m_sDefaultVoiceID;

DWORD m_dwType;
unsigned char m_ucOccupiedSeat;

protected:
int m_iCustomMoveAnim;
int m_iCustomMoveAnim{ 0 };

public:
CPedSA();
CPedSA(CPedSAInterface* pedInterface);
CPedSA(CPedSAInterface* pedInterface = nullptr) noexcept;
~CPedSA();

void SetInterface(CEntitySAInterface* intInterface);
Expand Down
67 changes: 63 additions & 4 deletions Client/mods/deathmatch/logic/CClientBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, u
m_vPos(pos),
m_vRot(rot),
m_interior(interior),
m_pBuilding(nullptr)
m_pBuilding(nullptr),
m_pHighBuilding(nullptr),
m_pLowBuilding(nullptr)
{
m_pManager = pManager;
SetTypeName("building");
Expand All @@ -29,6 +31,18 @@ CClientBuilding::CClientBuilding(class CClientManager* pManager, ElementID ID, u
CClientBuilding::~CClientBuilding()
{
m_pBuildingManager->RemoveFromList(this);
}

void CClientBuilding::Unlink()
{
if (m_pHighBuilding)
{
m_pHighBuilding->SetLowLodBuilding();
}
if (m_pLowBuilding)
{
SetLowLodBuilding();
}
Destroy();
}

Expand Down Expand Up @@ -93,17 +107,62 @@ void CClientBuilding::Create()
if (m_pBuilding)
return;

if (m_bBeingDeleted)
return;

CVector4D vRot4D;
ConvertZXYEulersToQuaternion(m_vRot, vRot4D);

m_pBuilding = g_pGame->GetPools()->GetBuildingsPool().AddBuilding(this, m_usModelId, &m_vPos, &vRot4D, m_interior);

if (m_pHighBuilding)
{
m_pHighBuilding->GetBuildingEntity()->SetLod(m_pBuilding);
}
}

void CClientBuilding::Destroy()
{
if (m_pBuilding)
if (!m_pBuilding)
return;

if (m_pHighBuilding)
{
g_pGame->GetPools()->GetBuildingsPool().RemoveBuilding(m_pBuilding);
m_pBuilding = nullptr;
m_pHighBuilding->GetBuildingEntity()->SetLod(nullptr);
}
g_pGame->GetPools()->GetBuildingsPool().RemoveBuilding(m_pBuilding);
m_pBuilding = nullptr;
}

bool CClientBuilding::SetLowLodBuilding(CClientBuilding* pLod)
{
if (pLod)
{
// Remove prev LOD
SetLowLodBuilding();

// Unlink old high lod element
CClientBuilding* pOveridedBuilding = pLod->GetHighLodBuilding();
if (pOveridedBuilding && pOveridedBuilding != this)
{
pOveridedBuilding->SetLowLodBuilding();
}

// Add new LOD
m_pLowBuilding = pLod;
m_pBuilding->SetLod(pLod->GetBuildingEntity());

pLod->SetHighLodBuilding(this);
}
else
{
// Remove LOD
if (m_pLowBuilding)
{
m_pLowBuilding->SetHighLodBuilding();
}
m_pBuilding->SetLod(nullptr);
m_pLowBuilding = nullptr;
}
return true;
}
17 changes: 15 additions & 2 deletions Client/mods/deathmatch/logic/CClientBuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ class CClientBuilding : public CClientEntity
CClientBuilding(class CClientManager* pManager, ElementID ID, uint16_t usModelId, const CVector &pos, const CVector &rot, uint8_t interior);
~CClientBuilding();

void Unlink(){};
void Unlink();
void GetPosition(CVector& vecPosition) const override { vecPosition = m_vPos; };
void SetPosition(const CVector& vecPosition) override;

void GetRotationRadians(CVector& vecOutRadians) const override { vecOutRadians = m_vRot; };
void SetRotationRadians(const CVector& vecRadians) override;

CBuilding* GetBuildingEntity() const { return m_pBuilding; };
CEntity* GetGameEntity() override { return m_pBuilding; };
const CEntity* GetGameEntity() const override { return m_pBuilding; };

Expand All @@ -40,14 +41,23 @@ class CClientBuilding : public CClientEntity
uint16_t GetModel() const noexcept { return m_usModelId; };
void SetModel(uint16_t ulModel);

eClientEntityType GetType() const noexcept { return CCLIENTBUILDING; }
eClientEntityType GetType() const { return CCLIENTBUILDING; }

bool IsValid() const noexcept { return m_pBuilding != nullptr; };


CClientBuilding* GetLowLodBuilding() const noexcept { return m_pLowBuilding; };
bool SetLowLodBuilding(CClientBuilding* pLod = nullptr);
bool IsLod() const noexcept { return m_pHighBuilding != nullptr; };


private:
void Create();
void Destroy();

CClientBuilding* GetHighLodBuilding() const { return m_pHighBuilding; };
void SetHighLodBuilding(CClientBuilding* pHighBuilding = nullptr) { m_pHighBuilding = pHighBuilding; };

void Recreate()
{
Destroy();
Expand All @@ -62,4 +72,7 @@ class CClientBuilding : public CClientEntity
CVector m_vPos;
CVector m_vRot;
uint8_t m_interior;

CClientBuilding* m_pHighBuilding;
CClientBuilding* m_pLowBuilding;
};
Loading

0 comments on commit 26ea3f9

Please sign in to comment.