Skip to content

Commit

Permalink
Merge branch 'master' into 190824_DiscordIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
TracerDS authored Aug 27, 2024
2 parents d34c847 + 4e7afa2 commit d0efa41
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 65 deletions.
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
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
17 changes: 1 addition & 16 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3927,22 +3927,7 @@ void CClientPed::_ChangeModel()
// So make sure clothes geometry is built now...
m_pClothes->AddAllToModel();
m_pPlayerPed->RebuildPlayer();

// ...and decrement the extra ref
#ifdef NO_CRASH_FIX_TEST2
m_pPlayerPed->RemoveGeometryRef();
#endif
}
else
{
// When the local player changes to another (non CJ) model, the geometry gets an extra ref from somewhere, causing a memory leak.
// So decrement the extra ref here
#ifdef NO_CRASH_FIX_TEST
m_pPlayerPed->RemoveGeometryRef();
#endif
// As we will have problem removing the geometry later, we might as well keep the model cached until exit
g_pCore->AddModelToPersistentCache((ushort)m_ulModel);
}
}

// Remove reference to the old model we used (Flag extra GTA reference to be removed as well)
pLoadedModel->RemoveRef(true);
Expand Down
6 changes: 5 additions & 1 deletion Client/mods/deathmatch/logic/CResourceModelStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ void CResourceModelStreamer::ReleaseAll()

void CResourceModelStreamer::FullyReleaseModel(std::uint16_t modelId)
{
std::uint16_t &refsCount = m_requestedModels[modelId];
auto refs = m_requestedModels.find(modelId);
if (refs == m_requestedModels.end())
return;

std::uint16_t& refsCount = refs->second;

if (refsCount > 0)
{
Expand Down
1 change: 0 additions & 1 deletion Client/sdk/core/CCoreInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class CCoreInterface
virtual EDiagnosticDebugType GetDiagnosticDebug() = 0;
virtual void SetDiagnosticDebug(EDiagnosticDebugType value) = 0;
virtual CModelCacheManager* GetModelCacheManager() = 0;
virtual void AddModelToPersistentCache(ushort usModelId) = 0;
virtual void UpdateDummyProgress(int iValue = -1, const char* szType = "") = 0;
virtual void SetDummyProgressUpdateAlways(bool bAlways) = 0;

Expand Down
1 change: 0 additions & 1 deletion Client/sdk/game/CPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class CPed : public virtual CPhysical
virtual void Respawn(CVector* position, bool bCameraCut) = 0;

virtual void SetModelIndex(unsigned long ulModel) = 0;
virtual void RemoveGeometryRef() = 0;

virtual float GetHealth() = 0;
virtual void SetHealth(float fHealth) = 0;
Expand Down

0 comments on commit d0efa41

Please sign in to comment.