Skip to content

Commit

Permalink
Merge branch 'master' into 050824_Async-dbConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS authored Sep 12, 2024
2 parents 29be4e4 + 6e127fd commit 29fd04b
Show file tree
Hide file tree
Showing 124 changed files with 1,944 additions and 1,147 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/dockerimage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ on:
- 'Dockerfile.i386'
- 'Dockerfile.armhf'
- 'Dockerfile.arm64'
- 'Dockerfile.osx-x64'
- 'Dockerfile.osx-arm64'

jobs:
build:
Expand All @@ -28,10 +26,6 @@ jobs:
dockerfile: Dockerfile.armhf
- tag: arm64
dockerfile: Dockerfile.arm64
- tag: osx-x64
dockerfile: Dockerfile.osx-x64
- tag: osx-arm64
dockerfile: Dockerfile.osx-arm64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 0 additions & 5 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,11 +2181,6 @@ CModelCacheManager* CCore::GetModelCacheManager()
return m_pModelCacheManager;
}

void CCore::AddModelToPersistentCache(ushort usModelId)
{
return GetModelCacheManager()->AddModelToPersistentCache(usModelId);
}

void CCore::StaticIdleHandler()
{
g_pCore->IdleHandler();
Expand Down
1 change: 0 additions & 1 deletion Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
EDiagnosticDebugType GetDiagnosticDebug();
void SetDiagnosticDebug(EDiagnosticDebugType value);
CModelCacheManager* GetModelCacheManager();
void AddModelToPersistentCache(ushort usModelId);

static void StaticIdleHandler();
void IdleHandler();
Expand Down
28 changes: 1 addition & 27 deletions Client/core/CModelCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class CModelCacheManagerImpl : public CModelCacheManager
virtual void OnClientClose();
virtual void UpdatePedModelCaching(const std::map<ushort, float>& newNeedCacheList);
virtual void UpdateVehicleModelCaching(const std::map<ushort, float>& newNeedCacheList);
virtual void AddModelToPersistentCache(ushort usModelId);
virtual void SetCustomLimits(std::optional<size_t> numVehicles, std::optional<size_t> numPeds);

// CModelCacheManagerImpl methods
Expand All @@ -72,7 +71,6 @@ class CModelCacheManagerImpl : public CModelCacheManager
bool m_IsUsingCustomVehicleCacheLimit{}; //< If `true` the value is set by the scripter, otherwise is calculated in `DoPulse()`
std::map<ushort, SModelCacheInfo> m_PedModelCacheInfoMap{};
std::map<ushort, SModelCacheInfo> m_VehicleModelCacheInfoMap{};
std::set<ushort> m_PermoLoadedModels{};
};

///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -266,22 +264,6 @@ void CModelCacheManagerImpl::DoPulse()
}
}

///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::AddModelToPersistentCache
//
// Keep this model around 4 evar now
//
///////////////////////////////////////////////////////////////
void CModelCacheManagerImpl::AddModelToPersistentCache(ushort usModelId)
{
if (!MapContains(m_PermoLoadedModels, usModelId))
{
AddModelRefCount(usModelId);
MapInsert(m_PermoLoadedModels, usModelId);
}
}

///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::UpdatePedModelCaching
Expand Down Expand Up @@ -542,13 +524,5 @@ void CModelCacheManagerImpl::OnRestreamModel(ushort usModelId)
OutputDebugLine(SString("[Cache] End caching model %d (OnRestreamModel)", usModelId));
}
}
}

// Also check the permo list
if (MapContains(m_PermoLoadedModels, usModelId))
{
SubModelRefCount(usModelId);
MapRemove(m_PermoLoadedModels, usModelId);
OutputDebugLine(SString("[Cache] End permo-caching model %d (OnRestreamModel)", usModelId));
}
}
}
1 change: 0 additions & 1 deletion Client/core/CModelCacheManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class CModelCacheManager
virtual void OnClientClose() = 0;
virtual void UpdatePedModelCaching(const std::map<ushort, float>& newNeedCacheList) = 0;
virtual void UpdateVehicleModelCaching(const std::map<ushort, float>& newNeedCacheList) = 0;
virtual void AddModelToPersistentCache(ushort usModelId) = 0;
virtual void SetCustomLimits(std::optional<size_t> numVehicles, std::optional<size_t> numPeds) = 0;
};

Expand Down
9 changes: 8 additions & 1 deletion Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
// Remove plant
pGame->GetPlantManager()->RemovePlant(pInterface);

RemoveBuildingFromWorld(pInterface);
// Remove shadow
pInterface->RemoveShadows();

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

// Call virtual destructor
((void*(__thiscall*)(void*, char))pInterface->vtbl->SCALAR_DELETING_DESTRUCTOR)(pInterface, 0);

// Remove col reference
auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex());
Expand Down
49 changes: 49 additions & 0 deletions Client/game_sa/CEntitySA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,28 @@ bool CEntitySA::GetBoneRotation(eBone boneId, float& yaw, float& pitch, float& r
return false;
}

bool CEntitySA::GetBoneRotationQuat(eBone boneId, float& x, float& y, float& z, float& w)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
x = boneOrientation->imag.x;
y = boneOrientation->imag.y;
z = boneOrientation->imag.z;
w = boneOrientation->real;
return true;
}
}
return false;
}

bool CEntitySA::SetBoneRotation(eBone boneId, float yaw, float pitch, float roll)
{
RpClump* clump = GetRpClump();
Expand All @@ -628,6 +650,33 @@ bool CEntitySA::SetBoneRotation(eBone boneId, float yaw, float pitch, float roll
return false;
}

bool CEntitySA::SetBoneRotationQuat(eBone boneId, float x, float y, float z, float w)
{
RpClump* clump = GetRpClump();
if (clump)
{
// updating the bone frame orientation will also update its children
// This rotation is only applied when UpdateElementRpHAnim is called
CAnimBlendClumpDataSAInterface* clumpDataInterface = *pGame->GetClumpData(clump);
AnimBlendFrameData* frameData = clumpDataInterface->GetFrameDataByNodeId(boneId);
if (frameData)
{
RtQuat* boneOrientation = &frameData->m_pIFrame->orientation;
boneOrientation->imag.x = x;
boneOrientation->imag.y = y;
boneOrientation->imag.z = z;
boneOrientation->real = w;
CEntitySAInterface* theInterface = GetInterface();
if (theInterface)
{
theInterface->bDontUpdateHierarchy = false;
}
return true;
}
}
return false;
}

bool CEntitySA::GetBonePosition(eBone boneId, CVector& position)
{
RwMatrix* rwBoneMatrix = GetBoneRwMatrix(boneId);
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CEntitySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ class CEntitySA : public virtual CEntity
bool SetBoneMatrix(eBone boneId, const CMatrix& matrix);

bool GetBoneRotation(eBone boneId, float& yaw, float& pitch, float& roll);
bool GetBoneRotationQuat(eBone boneId, float& x, float& y, float& z, float& w);
bool SetBoneRotation(eBone boneId, float yaw, float pitch, float roll);
bool SetBoneRotationQuat(eBone boneId, float x, float y, float z, float w);
bool GetBonePosition(eBone boneId, CVector& position);
bool SetBonePosition(eBone boneId, const CVector& position);

Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ CGameSA::CGameSA()
m_pPlantManager = new CPlantManagerSA();
m_pBuildingRemoval = new CBuildingRemovalSA();

m_pRenderer = std::make_unique<CRendererSA>();

// Normal weapon types (WEAPONSKILL_STD)
for (int i = 0; i < NUM_WeaponInfosStdSkill; i++)
{
Expand Down
6 changes: 5 additions & 1 deletion Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "CStreamingSA.h"
#include "CCoverManagerSA.h"
#include "CPlantManagerSA.h"
#include "CRendererSA.h"

class CAnimBlendClumpDataSAInterface;
class CObjectGroupPhysicalPropertiesSA;
Expand Down Expand Up @@ -172,7 +173,8 @@ class CGameSA : public CGame
CCoverManagerSA* GetCoverManager() const noexcept { return m_pCoverManager; };
CPlantManagerSA* GetPlantManager() const noexcept { return m_pPlantManager; };
CBuildingRemoval* GetBuildingRemoval() { return m_pBuildingRemoval; }

CRenderer* GetRenderer() const noexcept override { return m_pRenderer.get(); }

CWeaponInfo* GetWeaponInfo(eWeaponType weapon, eWeaponSkill skill = WEAPONSKILL_STD);
CModelInfo* GetModelInfo(DWORD dwModelID, bool bCanBeInvalid = false);
CObjectGroupPhysicalProperties* GetObjectGroupPhysicalProperties(unsigned char ucObjectGroup);
Expand Down Expand Up @@ -346,6 +348,8 @@ class CGameSA : public CGame
CPlantManagerSA* m_pPlantManager;
CBuildingRemoval* m_pBuildingRemoval;

std::unique_ptr<CRendererSA> m_pRenderer;

CPad* m_pPad;
CAERadioTrackManager* m_pCAERadioTrackManager;
CAudioEngine* m_pAudioEngine;
Expand Down
37 changes: 37 additions & 0 deletions Client/game_sa/CHeliSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,47 @@

class CHeliSAInterface : public CAutomobileSAInterface
{
public:
std::uint8_t m_heliFlags;

std::uint8_t _pad1[3];
std::uint32_t m_leftRightSkid;
std::uint32_t m_steeringUpDown;
std::uint32_t m_steeringLeftRight;
std::uint32_t m_accelerationBreakStatus;
std::uint32_t field_99C;
std::uint32_t m_rotorZ;
std::uint32_t m_secondRotorZ;
std::uint32_t m_maxAltitude;
std::uint32_t field_9AC;
std::uint32_t m_minAltitude;
std::uint32_t field_9B4;
std::uint8_t field_9B8;
std::uint8_t m_numSwatOccupants;
std::uint8_t m_swatIDs[4];

std::uint8_t _pad2[2];
std::uint32_t field_9C0[4];
std::uint32_t field_9D0;

std::uint32_t m_particlesList;
std::uint8_t field_9D8[24];
std::uint32_t field_9F0;
CVector m_searchLightTarget;
std::uint32_t m_searchLightIntensity;
std::uint32_t field_A04;
std::uint32_t field_A08;
std::uint32_t m_gunflashFx;
std::uint8_t m_firingMultiplier;
std::uint8_t m_searchLightEnabled;
std::uint8_t _pad3[2];
std::uint32_t field_A14;
};
static_assert(sizeof(CHeliSAInterface) == 0xA18, "Invalid size for CHeliSAInterface");

class CHeliSA final : public virtual CHeli, public virtual CAutomobileSA
{
public:
CHeliSA(CHeliSAInterface* pInterface);
CHeliSAInterface* GetHeliInterface() noexcept { return reinterpret_cast<CHeliSAInterface*>(GetInterface()); }
};
5 changes: 4 additions & 1 deletion Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,10 @@ void CModelInfoSA::RestoreAllObjectsPropertiesGroups()

eModelInfoType CModelInfoSA::GetModelType()
{
return ((eModelInfoType(*)())m_pInterface->VFTBL->GetModelType)();
if (auto pInterface = GetInterface())
return ((eModelInfoType(*)())pInterface->VFTBL->GetModelType)();

return eModelInfoType::UNKNOWN;
}

bool CModelInfoSA::IsTowableBy(CModelInfo* towingModel)
Expand Down
16 changes: 5 additions & 11 deletions Client/game_sa/CPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ void CPedSA::Init()

void CPedSA::SetModelIndex(DWORD dwModelIndex)
{
DWORD dwFunction = FUNC_SetModelIndex;
// Delete any existing RwObject first
GetPedInterface()->DeleteRwObject();

// Set new model
DWORD dwThis = (DWORD)GetInterface();
DWORD dwFunction = FUNC_SetModelIndex;
_asm
{
mov ecx, dwThis
Expand All @@ -116,16 +120,6 @@ void CPedSA::SetModelIndex(DWORD dwModelIndex)
}
}

// Hacky thing done for the local player when changing model
void CPedSA::RemoveGeometryRef()
{
RpClump* pClump = (RpClump*)GetInterface()->m_pRwObject;
RpAtomic* pAtomic = (RpAtomic*)((pClump->atomics.root.next) - 0x8);
RpGeometry* pGeometry = pAtomic->geometry;
if (pGeometry->refs > 1)
pGeometry->refs--;
}

bool CPedSA::IsInWater()
{
CTask* pTask = m_pPedIntelligence->GetTaskManager()->GetTask(TASK_PRIORITY_EVENT_RESPONSE_NONTEMP);
Expand Down
1 change: 0 additions & 1 deletion Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
CPedSAInterface* GetPedInterface() { return (CPedSAInterface*)GetInterface(); }
void Init();
void SetModelIndex(DWORD dwModelIndex);
void RemoveGeometryRef();
void AttachPedToEntity(DWORD dwEntityInterface, CVector* vector, unsigned short sDirection, float fRotationLimit, eWeaponType weaponType,
bool bChangeCamera);
void DetachPedFromEntity();
Expand Down
55 changes: 55 additions & 0 deletions Client/game_sa/CRendererSA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CRendererSA.cpp
* PURPOSE: Game renderer class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#include "StdInc.h"
#include "CRendererSA.h"
#include "CModelInfoSA.h"
#include "CMatrix.h"
#include "gamesa_renderware.h"

CRendererSA::CRendererSA()
{
}

CRendererSA::~CRendererSA()
{
}

void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix)
{
CBaseModelInfoSAInterface* pModelInfoSAInterface = pModelInfo->GetInterface();
if (!pModelInfoSAInterface)
return;

RwObject* pRwObject = pModelInfoSAInterface->pRwObject;
if (!pRwObject)
return;

RwFrame* pFrame = RpGetFrame(pRwObject);

static RwMatrix rwMatrix;
rwMatrix.right = (RwV3d&)matrix.vRight;
rwMatrix.up = (RwV3d&)matrix.vFront;
rwMatrix.at = (RwV3d&)matrix.vUp;
rwMatrix.pos = (RwV3d&)matrix.vPos;
RwFrameTransform(pFrame, &rwMatrix, rwCOMBINEREPLACE);

if (pRwObject->type == RP_TYPE_ATOMIC)
{
RpAtomic* pRpAtomic = reinterpret_cast<RpAtomic*>(pRwObject);
pRpAtomic->renderCallback(reinterpret_cast<RpAtomic*>(pRwObject));
}
else
{
RpClump* pClump = reinterpret_cast<RpClump*>(pRwObject);
RpClumpRender(pClump);
}
}
Loading

0 comments on commit 29fd04b

Please sign in to comment.