Skip to content

Commit

Permalink
Optimization Handling (part 3) and Remove big use eVehicleTypes (#3848)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Moris authored Dec 21, 2024
1 parent 6a70cf7 commit c0376c9
Show file tree
Hide file tree
Showing 44 changed files with 1,200 additions and 1,240 deletions.
38 changes: 18 additions & 20 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ CGameSA::CGameSA()
m_pAESoundManager = new CAESoundManagerSA((CAESoundManagerSAInterface*)CLASS_CAESoundManager);
m_pAudioContainer = new CAudioContainerSA();
m_pWorld = new CWorldSA();
m_pPools = new CPoolsSA();
m_Pools = std::make_unique<CPoolsSA>();
m_pClock = new CClockSA();
m_pRadar = new CRadarSA();
m_pCamera = new CCameraSA((CCameraSAInterface*)CLASS_CCamera);
Expand All @@ -125,7 +125,7 @@ CGameSA::CGameSA()
m_pControllerConfigManager = new CControllerConfigManagerSA();
m_pProjectileInfo = new CProjectileInfoSA();
m_pRenderWare = new CRenderWareSA();
m_pHandlingManager = new CHandlingManagerSA();
m_HandlingManager = std::make_unique<CHandlingManagerSA>();
m_pEventList = new CEventListSA();
m_pGarages = new CGaragesSA((CGaragesSAInterface*)CLASS_CGarages);
m_pTasks = new CTasksSA((CTaskManagementSystemSA*)m_pTaskManagementSystem);
Expand Down Expand Up @@ -208,17 +208,17 @@ CGameSA::CGameSA()
m_Cheats[CHEAT_HEALTARMORMONEY] = new SCheatSA((BYTE*)VAR_HealthArmorMoney, false);

// Change pool sizes here
m_pPools->SetPoolCapacity(TASK_POOL, 5000); // Default is 500
m_pPools->SetPoolCapacity(OBJECT_POOL, MAX_OBJECTS); // Default is 350
m_pPools->SetPoolCapacity(EVENT_POOL, 5000); // Default is 200
m_pPools->SetPoolCapacity(COL_MODEL_POOL, 12000); // Default is 10150
m_pPools->SetPoolCapacity(ENV_MAP_MATERIAL_POOL, 16000); // Default is 4096
m_pPools->SetPoolCapacity(ENV_MAP_ATOMIC_POOL, 4000); // Default is 1024
m_pPools->SetPoolCapacity(SPEC_MAP_MATERIAL_POOL, 16000); // Default is 4096
m_pPools->SetPoolCapacity(ENTRY_INFO_NODE_POOL, MAX_ENTRY_INFO_NODES); // Default is 500
m_pPools->SetPoolCapacity(POINTER_SINGLE_LINK_POOL, MAX_POINTER_SINGLE_LINKS); // Default is 70000
m_pPools->SetPoolCapacity(POINTER_DOUBLE_LINK_POOL, MAX_POINTER_DOUBLE_LINKS); // Default is 3200
dassert(m_pPools->GetPoolCapacity(POINTER_SINGLE_LINK_POOL) == MAX_POINTER_SINGLE_LINKS);
m_Pools->SetPoolCapacity(TASK_POOL, 5000); // Default is 500
m_Pools->SetPoolCapacity(OBJECT_POOL, MAX_OBJECTS); // Default is 350
m_Pools->SetPoolCapacity(EVENT_POOL, 5000); // Default is 200
m_Pools->SetPoolCapacity(COL_MODEL_POOL, 12000); // Default is 10150
m_Pools->SetPoolCapacity(ENV_MAP_MATERIAL_POOL, 16000); // Default is 4096
m_Pools->SetPoolCapacity(ENV_MAP_ATOMIC_POOL, 4000); // Default is 1024
m_Pools->SetPoolCapacity(SPEC_MAP_MATERIAL_POOL, 16000); // Default is 4096
m_Pools->SetPoolCapacity(ENTRY_INFO_NODE_POOL, MAX_ENTRY_INFO_NODES); // Default is 500
m_Pools->SetPoolCapacity(POINTER_SINGLE_LINK_POOL, MAX_POINTER_SINGLE_LINKS); // Default is 70000
m_Pools->SetPoolCapacity(POINTER_DOUBLE_LINK_POOL, MAX_POINTER_DOUBLE_LINKS); // Default is 3200
dassert(m_Pools->GetPoolCapacity(POINTER_SINGLE_LINK_POOL) == MAX_POINTER_SINGLE_LINKS);

// Increase streaming object instances list size
MemPut<WORD>(0x05B8E55, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12
Expand Down Expand Up @@ -261,7 +261,6 @@ CGameSA::~CGameSA()
delete reinterpret_cast<CAnimManagerSA*>(m_pAnimManager);
delete reinterpret_cast<CTasksSA*>(m_pTasks);
delete reinterpret_cast<CTaskManagementSystemSA*>(m_pTaskManagementSystem);
delete reinterpret_cast<CHandlingManagerSA*>(m_pHandlingManager);
delete reinterpret_cast<CStatsSA*>(m_pStats);
delete reinterpret_cast<CWeatherSA*>(m_pWeather);
delete reinterpret_cast<CAERadioTrackManagerSA*>(m_pCAERadioTrackManager);
Expand All @@ -276,7 +275,6 @@ CGameSA::~CGameSA()
delete reinterpret_cast<CCameraSA*>(m_pCamera);
delete reinterpret_cast<CRadarSA*>(m_pRadar);
delete reinterpret_cast<CClockSA*>(m_pClock);
delete reinterpret_cast<CPoolsSA*>(m_pPools);
delete reinterpret_cast<CWorldSA*>(m_pWorld);
delete reinterpret_cast<CAudioEngineSA*>(m_pAudioEngine);
delete reinterpret_cast<CAEAudioHardwareSA*>(m_pAEAudioHardware);
Expand Down Expand Up @@ -1039,8 +1037,8 @@ void CGameSA::RemoveAllBuildings()
{
m_pIplStore->SetDynamicIplStreamingEnabled(false);

m_pPools->GetDummyPool().RemoveAllBuildingLods();
m_pPools->GetBuildingsPool().RemoveAllBuildings();
m_Pools->GetDummyPool().RemoveAllBuildingLods();
m_Pools->GetBuildingsPool().RemoveAllBuildings();

auto pBuildingRemoval = static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval);
pBuildingRemoval->DropCaches();
Expand All @@ -1050,8 +1048,8 @@ void CGameSA::RemoveAllBuildings()

void CGameSA::RestoreGameBuildings()
{
m_pPools->GetBuildingsPool().RestoreAllBuildings();
m_pPools->GetDummyPool().RestoreAllBuildingsLods();
m_Pools->GetBuildingsPool().RestoreAllBuildings();
m_Pools->GetDummyPool().RestoreAllBuildingsLods();

m_pIplStore->SetDynamicIplStreamingEnabled(true, [](CIplSAInterface* ipl) { return memcmp("barriers", ipl->name, 8) != 0; });
m_isBuildingsRemoved = false;
Expand All @@ -1069,7 +1067,7 @@ bool CGameSA::SetBuildingPoolSize(size_t size)
static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval)->DropCaches();
}

bool status = m_pPools->GetBuildingsPool().Resize(size);
bool status = m_Pools->GetBuildingsPool().Resize(size);

if (shouldRemoveBuilding)
{
Expand Down
76 changes: 38 additions & 38 deletions Client/game_sa/CGameSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CGameSA : public CGame
CGameSA();
~CGameSA();

CPools* GetPools() { return m_pPools; }
CPools* GetPools() const noexcept { return m_Pools.get(); }
CPlayerInfo* GetPlayerInfo() { return m_pPlayerInfo; }
CProjectileInfo* GetProjectileInfo() { return m_pProjectileInfo; }
CRadar* GetRadar() { return m_pRadar; }
Expand Down Expand Up @@ -155,7 +155,7 @@ class CGameSA : public CGame
CCarEnterExit* GetCarEnterExit() { return m_pCarEnterExit; }
CControllerConfigManager* GetControllerConfigManager() { return m_pControllerConfigManager; }
CRenderWare* GetRenderWare() { return m_pRenderWare; }
CHandlingManager* GetHandlingManager() { return m_pHandlingManager; }
CHandlingManager* GetHandlingManager() const noexcept { return m_HandlingManager.get(); }
CAnimManager* GetAnimManager() { return m_pAnimManager; }
CStreaming* GetStreaming() { return m_pStreaming; }
CVisibilityPlugins* GetVisibilityPlugins() { return m_pVisibilityPlugins; }
Expand Down Expand Up @@ -313,42 +313,42 @@ class CGameSA : public CGame
bool SetBuildingPoolSize(size_t size);

private:
CPools* m_pPools;
CPlayerInfo* m_pPlayerInfo;
CProjectileInfo* m_pProjectileInfo;
CRadar* m_pRadar;
CClock* m_pClock;
CCoronas* m_pCoronas;
CCheckpoints* m_pCheckpoints;
CEventList* m_pEventList;
CFireManager* m_pFireManager;
CGarages* m_pGarages;
CHud* m_pHud;
CWeather* m_pWeather;
CWorld* m_pWorld;
CCamera* m_pCamera;
CModelInfo* m_pModelInfo;
CPickups* m_pPickups;
CWeaponInfo* m_pWeaponInfo;
CExplosionManager* m_pExplosionManager;
C3DMarkers* m_p3DMarkers;
CRenderWareSA* m_pRenderWare;
CHandlingManager* m_pHandlingManager;
CAnimManager* m_pAnimManager;
CStreaming* m_pStreaming;
CVisibilityPlugins* m_pVisibilityPlugins;
CKeyGen* m_pKeyGen;
CRopes* m_pRopes;
CFx* m_pFx;
CFxManagerSA* m_pFxManager;
CWaterManager* m_pWaterManager;
CWeaponStatManager* m_pWeaponStatsManager;
CPointLights* m_pPointLights;
CColStore* m_collisionStore;
CObjectGroupPhysicalProperties* m_pObjectGroupPhysicalProperties;
CCoverManagerSA* m_pCoverManager;
CPlantManagerSA* m_pPlantManager;
CBuildingRemoval* m_pBuildingRemoval;
std::unique_ptr<CPools> m_Pools;
CPlayerInfo* m_pPlayerInfo;
CProjectileInfo* m_pProjectileInfo;
CRadar* m_pRadar;
CClock* m_pClock;
CCoronas* m_pCoronas;
CCheckpoints* m_pCheckpoints;
CEventList* m_pEventList;
CFireManager* m_pFireManager;
CGarages* m_pGarages;
CHud* m_pHud;
CWeather* m_pWeather;
CWorld* m_pWorld;
CCamera* m_pCamera;
CModelInfo* m_pModelInfo;
CPickups* m_pPickups;
CWeaponInfo* m_pWeaponInfo;
CExplosionManager* m_pExplosionManager;
C3DMarkers* m_p3DMarkers;
CRenderWareSA* m_pRenderWare;
std::unique_ptr<CHandlingManager> m_HandlingManager;
CAnimManager* m_pAnimManager;
CStreaming* m_pStreaming;
CVisibilityPlugins* m_pVisibilityPlugins;
CKeyGen* m_pKeyGen;
CRopes* m_pRopes;
CFx* m_pFx;
CFxManagerSA* m_pFxManager;
CWaterManager* m_pWaterManager;
CWeaponStatManager* m_pWeaponStatsManager;
CPointLights* m_pPointLights;
CColStore* m_collisionStore;
CObjectGroupPhysicalProperties* m_pObjectGroupPhysicalProperties;
CCoverManagerSA* m_pCoverManager;
CPlantManagerSA* m_pPlantManager;
CBuildingRemoval* m_pBuildingRemoval;

std::unique_ptr<CRendererSA> m_pRenderer;

Expand Down
43 changes: 22 additions & 21 deletions Client/game_sa/CHandlingEntrySA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,48 @@ extern CGameSA* pGame;
CHandlingEntrySA::CHandlingEntrySA()
{
// Create a new interface and zero it
m_pHandlingSA = new tHandlingDataSA;
memset(m_pHandlingSA, 0, sizeof(tHandlingDataSA));
m_bDeleteInterface = true;
if (m_HandlingSA = std::make_unique<tHandlingDataSA>())
{
MemSet(m_HandlingSA.get(), 0, sizeof(tHandlingDataSA));
}
}

CHandlingEntrySA::CHandlingEntrySA(tHandlingDataSA* pOriginal)
CHandlingEntrySA::CHandlingEntrySA(const tHandlingDataSA* const pOriginal)
{
// Store gta's pointer
m_pHandlingSA = nullptr;
m_bDeleteInterface = false;
memcpy(&m_Handling, pOriginal, sizeof(tHandlingDataSA));
}

CHandlingEntrySA::~CHandlingEntrySA()
{
if (m_bDeleteInterface)
m_HandlingSA = nullptr;
if (pOriginal)
{
SAFE_DELETE(m_pHandlingSA);
MemCpy(&m_Handling, pOriginal, sizeof(tHandlingDataSA));

This comment has been minimized.

Copy link
@botder

botder Dec 22, 2024

Member

This triggers the assertation from SharedUtil::OpenMemWrite: dassert(0 && "Should use Mem*Fast function");

}
}

// Apply the handlingdata from another data
void CHandlingEntrySA::Assign(const CHandlingEntry* pEntry)
void CHandlingEntrySA::Assign(const CHandlingEntry* const pEntry) noexcept
{
if (!pEntry)
return;

// Copy the data
const CHandlingEntrySA* pEntrySA = static_cast<const CHandlingEntrySA*>(pEntry);
const CHandlingEntrySA* const pEntrySA = static_cast<const CHandlingEntrySA const*>(pEntry);
m_Handling = pEntrySA->m_Handling;
}

void CHandlingEntrySA::Recalculate()
void CHandlingEntrySA::Recalculate() noexcept
{
// Real GTA class?
if (!m_pHandlingSA)
if (!m_HandlingSA)
return;

// Copy our stored field to GTA's
memcpy(m_pHandlingSA, &m_Handling, sizeof(m_Handling));
((void(_stdcall*)(tHandlingDataSA*))FUNC_HandlingDataMgr_ConvertDataToGameUnits)(m_pHandlingSA);
try
{
// Copy our stored field to GTA's
MemCpy(m_HandlingSA.get(), &m_Handling, sizeof(m_Handling));
((void(_stdcall*)(tHandlingDataSA*))FUNC_HandlingDataMgr_ConvertDataToGameUnits)(m_HandlingSA.get());
}
catch (...)
{
}
}

void CHandlingEntrySA::SetSuspensionForceLevel(float fForce) noexcept
Expand Down Expand Up @@ -104,7 +105,7 @@ void CHandlingEntrySA::SetSuspensionAntiDiveMultiplier(float fAntidive) noexcept
m_Handling.fSuspensionAntiDiveMultiplier = fAntidive;
}

void CHandlingEntrySA::CheckSuspensionChanges() noexcept
void CHandlingEntrySA::CheckSuspensionChanges() const noexcept
{
pGame->GetHandlingManager()->CheckSuspensionChanges(this);
}
Loading

0 comments on commit c0376c9

Please sign in to comment.