From e43150a3cdd8f552096d0af515efaa2c614cf207 Mon Sep 17 00:00:00 2001 From: Walace Date: Tue, 12 Aug 2025 15:24:43 -0300 Subject: [PATCH 1/4] Add engineSetClothingCacheTime function --- Client/mods/deathmatch/logic/CClientGame.cpp | 1 + .../logic/luadefs/CLuaEngineDefs.cpp | 9 +++ .../deathmatch/logic/luadefs/CLuaEngineDefs.h | 1 + Client/multiplayer_sa/CMultiplayerSA.h | 2 + .../CMultiplayerSA_ClothesCache.cpp | 70 ++++++++++++++----- Client/sdk/multiplayer/CMultiplayer.h | 2 + 6 files changed, 67 insertions(+), 18 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index 49343f0c9e2..6017b4b1fe4 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -3465,6 +3465,7 @@ void CClientGame::Event_OnIngame() g_pGame->GetWaterManager()->Reset(); // Deletes all custom water elements, ResetMapInfo only reverts changes to water level g_pGame->GetWaterManager()->SetWaterDrawnLast(true); m_pCamera->SetCameraClip(true, true); + g_pMultiplayer->ResetClothingCacheTime(); // Deallocate all custom models m_pManager->GetModelManager()->RemoveAll(); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 3de38bbf76a..f3472f9c7f8 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -86,6 +86,7 @@ void CLuaEngineDefs::LoadFunctions() {"engineRestoreCOL", EngineRestoreCOL}, {"engineReplaceModel", EngineReplaceModel}, {"engineAddClothingModel", ArgumentParser}, + {"engineSetClothingCacheTime", ArgumentParser}, {"engineRestoreModel", EngineRestoreModel}, {"engineReplaceAnimation", EngineReplaceAnimation}, {"engineRestoreAnimation", EngineRestoreAnimation}, @@ -852,6 +853,14 @@ bool CLuaEngineDefs::EngineAddClothingModel(CClientDFF* pDFF, std::string strMod return true; } +bool CLuaEngineDefs::EngineSetClothingCacheTime(uint timeInMs) +{ + if (!g_pMultiplayer->SetClothingCacheTime(timeInMs)) + return false; + + return true; +} + int CLuaEngineDefs::EngineRestoreModel(lua_State* luaVM) { // Grab the model ID diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h index 48fa2706a41..20d1f4ffd15 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h @@ -60,6 +60,7 @@ class CLuaEngineDefs : public CLuaDefs LUA_DECLARE(EngineRestoreObjectGroupPhysicalProperties) static bool EngineAddClothingModel(CClientDFF* pDff, std::string strModelName); + static bool EngineSetClothingCacheTime(uint timeInMs); static bool EngineAddClothingTXD(CClientTXD* pTxd, std::string strModelName); static uint EngineGetModelFlags(uint uiModelID); static bool EngineSetModelFlags(uint uiModelID, uint uiFlags, std::optional bIdeFlags); diff --git a/Client/multiplayer_sa/CMultiplayerSA.h b/Client/multiplayer_sa/CMultiplayerSA.h index 75206d82114..9acb2d73e84 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.h +++ b/Client/multiplayer_sa/CMultiplayerSA.h @@ -345,6 +345,8 @@ class CMultiplayerSA : public CMultiplayer virtual void GetRwResourceStats(SRwResourceStats& outStats); virtual void GetClothesCacheStats(SClothesCacheStats& outStats); + virtual void ResetClothingCacheTime(); + virtual bool SetClothingCacheTime(uint timeInMs); virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected); virtual void SetMirrorsEnabled(bool bEnabled); diff --git a/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp b/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp index 3b5dd798ad3..822fe3033a1 100644 --- a/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp @@ -16,6 +16,8 @@ #define CLOTHES_REF_TEST 1 // Debug clothes geometry refs +static constexpr uint DEFAULT_CACHE_TIME = 1000; + //////////////////////////////////////////////// // // class CPedClothesDesc @@ -126,7 +128,7 @@ class CClumpStore { memset(&m_Stats, 0, sizeof(m_Stats)); m_uiMaxSize = 4; - m_uiMinCacheTime = 1000; + m_uiMinCacheTime = DEFAULT_CACHE_TIME; m_iCacheRevision = 1; } @@ -138,30 +140,34 @@ class CClumpStore uint GetNumCached() { uint uiNumCached = 0; - for (std::vector::iterator iter = savedClumpList.begin(); iter != savedClumpList.end(); ++iter) + + if (m_uiMinCacheTime > 0) { - SSavedClumpInfo& info = *iter; - RpGeometry* pGeometry = ((RpAtomic*)((info.pClump->atomics.root.next) - 0x8))->geometry; -#ifdef CLOTHES_REF_TEST - if (pGeometry->refs < 21) + for (std::vector::iterator iter = savedClumpList.begin(); iter != savedClumpList.end(); ++iter) { - AddReportLog(7521, SString("Clothes geometry refs below expected value: %d", pGeometry->refs)); - pGeometry->refs = 21; - } - if (pGeometry->refs == 21) + SSavedClumpInfo& info = *iter; + RpGeometry* pGeometry = ((RpAtomic*)((info.pClump->atomics.root.next) - 0x8))->geometry; +#ifdef CLOTHES_REF_TEST + if (pGeometry->refs < 21) + { + AddReportLog(7521, SString("Clothes geometry refs below expected value: %d", pGeometry->refs)); + pGeometry->refs = 21; + } + if (pGeometry->refs == 21) #else - if (pGeometry->refs == 1) + if (pGeometry->refs == 1) #endif - { - uiNumCached++; - if (!info.bUnused) { - info.timeUnused = CTickCount::Now(); - info.bUnused = true; + uiNumCached++; + if (!info.bUnused) + { + info.timeUnused = CTickCount::Now(); + info.bUnused = true; + } } + else + info.bUnused = false; } - else - info.bUnused = false; } m_Stats.uiNumTotal = savedClumpList.size(); @@ -402,6 +408,34 @@ void CMultiplayerSA::GetClothesCacheStats(SClothesCacheStats& outStats) outStats = ms_clumpStore.m_Stats; } +////////////////////////////////////////////////////////////////////////////////////////// +// +// CMultiplayerSA::SetClothingCacheTime +// +// +////////////////////////////////////////////////////////////////////////////////////////// +bool CMultiplayerSA::SetClothingCacheTime(uint timeInMs) +{ + if (timeInMs == ms_clumpStore.m_uiMinCacheTime) + return false; + + ms_clumpStore.savedClumpList.clear(); + ms_clumpStore.m_uiMinCacheTime = timeInMs; + + return true; +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +// CMultiplayerSA::ResetClothingCacheTime +// +// +////////////////////////////////////////////////////////////////////////////////////////// +void CMultiplayerSA::ResetClothingCacheTime() +{ + SetClothingCacheTime(DEFAULT_CACHE_TIME); +} + ////////////////////////////////////////////////////////////////////////////////////////// // // CMultiplayerSA::InitHooks_ClothesCache diff --git a/Client/sdk/multiplayer/CMultiplayer.h b/Client/sdk/multiplayer/CMultiplayer.h index e5e591ad5d3..ca404b550a3 100644 --- a/Client/sdk/multiplayer/CMultiplayer.h +++ b/Client/sdk/multiplayer/CMultiplayer.h @@ -455,6 +455,8 @@ class CMultiplayer virtual void GetRwResourceStats(SRwResourceStats& outStats) = 0; virtual void GetClothesCacheStats(SClothesCacheStats& outStats) = 0; + virtual void ResetClothingCacheTime() = 0; + virtual bool SetClothingCacheTime(uint timeInMs) = 0; virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected) = 0; virtual void SetMirrorsEnabled(bool bEnabled) = 0; From e10df126530d179f5ca9a085dee71dfc5e396fea Mon Sep 17 00:00:00 2001 From: Walace Date: Wed, 13 Aug 2025 10:43:16 -0300 Subject: [PATCH 2/4] Change DEFAULT_CACHE_TIME type to std::uint32_t --- Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp b/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp index 822fe3033a1..b0ed52f4933 100644 --- a/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp @@ -16,7 +16,7 @@ #define CLOTHES_REF_TEST 1 // Debug clothes geometry refs -static constexpr uint DEFAULT_CACHE_TIME = 1000; +static constexpr std::uint32_t DEFAULT_CACHE_TIME = 1000; //////////////////////////////////////////////// // From da4483634a745f9d6f5a75e3ff6841c4deafe8c6 Mon Sep 17 00:00:00 2001 From: Walace Date: Wed, 13 Aug 2025 13:56:07 -0300 Subject: [PATCH 3/4] Replace uint with std::uint32_t --- .../deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 2 +- .../mods/deathmatch/logic/luadefs/CLuaEngineDefs.h | 2 +- Client/multiplayer_sa/CMultiplayerSA.h | 2 +- .../multiplayer_sa/CMultiplayerSA_ClothesCache.cpp | 14 +++++++------- Client/sdk/multiplayer/CMultiplayer.h | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index f3472f9c7f8..c59a000a611 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -853,7 +853,7 @@ bool CLuaEngineDefs::EngineAddClothingModel(CClientDFF* pDFF, std::string strMod return true; } -bool CLuaEngineDefs::EngineSetClothingCacheTime(uint timeInMs) +bool CLuaEngineDefs::EngineSetClothingCacheTime(std::uint32_t timeInMs) { if (!g_pMultiplayer->SetClothingCacheTime(timeInMs)) return false; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h index 20d1f4ffd15..0395f57a972 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h @@ -60,7 +60,7 @@ class CLuaEngineDefs : public CLuaDefs LUA_DECLARE(EngineRestoreObjectGroupPhysicalProperties) static bool EngineAddClothingModel(CClientDFF* pDff, std::string strModelName); - static bool EngineSetClothingCacheTime(uint timeInMs); + static bool EngineSetClothingCacheTime(std::uint32_t timeInMs); static bool EngineAddClothingTXD(CClientTXD* pTxd, std::string strModelName); static uint EngineGetModelFlags(uint uiModelID); static bool EngineSetModelFlags(uint uiModelID, uint uiFlags, std::optional bIdeFlags); diff --git a/Client/multiplayer_sa/CMultiplayerSA.h b/Client/multiplayer_sa/CMultiplayerSA.h index 9acb2d73e84..4074aeffac8 100644 --- a/Client/multiplayer_sa/CMultiplayerSA.h +++ b/Client/multiplayer_sa/CMultiplayerSA.h @@ -346,7 +346,7 @@ class CMultiplayerSA : public CMultiplayer virtual void GetRwResourceStats(SRwResourceStats& outStats); virtual void GetClothesCacheStats(SClothesCacheStats& outStats); virtual void ResetClothingCacheTime(); - virtual bool SetClothingCacheTime(uint timeInMs); + virtual bool SetClothingCacheTime(std::uint32_t timeInMs); virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected); virtual void SetMirrorsEnabled(bool bEnabled); diff --git a/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp b/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp index b0ed52f4933..a6d342c1a1e 100644 --- a/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp +++ b/Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp @@ -115,7 +115,7 @@ class CClumpStore std::vector savedClumpList; uint m_uiMaxSize; - uint m_uiMinCacheTime; + std::uint32_t m_minCacheTime; SClothesCacheStats m_Stats; int m_iCacheRevision; @@ -128,7 +128,7 @@ class CClumpStore { memset(&m_Stats, 0, sizeof(m_Stats)); m_uiMaxSize = 4; - m_uiMinCacheTime = DEFAULT_CACHE_TIME; + m_minCacheTime = DEFAULT_CACHE_TIME; m_iCacheRevision = 1; } @@ -141,7 +141,7 @@ class CClumpStore { uint uiNumCached = 0; - if (m_uiMinCacheTime > 0) + if (m_minCacheTime > 0) { for (std::vector::iterator iter = savedClumpList.begin(); iter != savedClumpList.end(); ++iter) { @@ -242,7 +242,7 @@ class CClumpStore if (info.bUnused) { uint uiAge = (timeNow - info.timeUnused).ToInt(); - if (uiAge > m_uiMinCacheTime) + if (uiAge > m_minCacheTime) { if (uiAge > uiBestAge || uiBestAge == -1) { @@ -414,13 +414,13 @@ void CMultiplayerSA::GetClothesCacheStats(SClothesCacheStats& outStats) // // ////////////////////////////////////////////////////////////////////////////////////////// -bool CMultiplayerSA::SetClothingCacheTime(uint timeInMs) +bool CMultiplayerSA::SetClothingCacheTime(std::uint32_t timeInMs) { - if (timeInMs == ms_clumpStore.m_uiMinCacheTime) + if (timeInMs == ms_clumpStore.m_minCacheTime) return false; ms_clumpStore.savedClumpList.clear(); - ms_clumpStore.m_uiMinCacheTime = timeInMs; + ms_clumpStore.m_minCacheTime = timeInMs; return true; } diff --git a/Client/sdk/multiplayer/CMultiplayer.h b/Client/sdk/multiplayer/CMultiplayer.h index ca404b550a3..83eb39da8f9 100644 --- a/Client/sdk/multiplayer/CMultiplayer.h +++ b/Client/sdk/multiplayer/CMultiplayer.h @@ -456,7 +456,7 @@ class CMultiplayer virtual void GetRwResourceStats(SRwResourceStats& outStats) = 0; virtual void GetClothesCacheStats(SClothesCacheStats& outStats) = 0; virtual void ResetClothingCacheTime() = 0; - virtual bool SetClothingCacheTime(uint timeInMs) = 0; + virtual bool SetClothingCacheTime(std::uint32_t timeInMs) = 0; virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected) = 0; virtual void SetMirrorsEnabled(bool bEnabled) = 0; From 4c8e92bece40519f30ff7e95dc1a9c4a6f200226 Mon Sep 17 00:00:00 2001 From: Walace Date: Wed, 13 Aug 2025 15:17:52 -0300 Subject: [PATCH 4/4] Simplify EngineSetClothingCacheTime return logic --- Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index c59a000a611..4e68ffe03d0 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -855,10 +855,7 @@ bool CLuaEngineDefs::EngineAddClothingModel(CClientDFF* pDFF, std::string strMod bool CLuaEngineDefs::EngineSetClothingCacheTime(std::uint32_t timeInMs) { - if (!g_pMultiplayer->SetClothingCacheTime(timeInMs)) - return false; - - return true; + return g_pMultiplayer->SetClothingCacheTime(timeInMs); } int CLuaEngineDefs::EngineRestoreModel(lua_State* luaVM)