Skip to content

Commit e43150a

Browse files
committed
Add engineSetClothingCacheTime function
1 parent c684463 commit e43150a

File tree

6 files changed

+67
-18
lines changed

6 files changed

+67
-18
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,7 @@ void CClientGame::Event_OnIngame()
34653465
g_pGame->GetWaterManager()->Reset(); // Deletes all custom water elements, ResetMapInfo only reverts changes to water level
34663466
g_pGame->GetWaterManager()->SetWaterDrawnLast(true);
34673467
m_pCamera->SetCameraClip(true, true);
3468+
g_pMultiplayer->ResetClothingCacheTime();
34683469

34693470
// Deallocate all custom models
34703471
m_pManager->GetModelManager()->RemoveAll();

Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void CLuaEngineDefs::LoadFunctions()
8686
{"engineRestoreCOL", EngineRestoreCOL},
8787
{"engineReplaceModel", EngineReplaceModel},
8888
{"engineAddClothingModel", ArgumentParser<EngineAddClothingModel>},
89+
{"engineSetClothingCacheTime", ArgumentParser<EngineSetClothingCacheTime>},
8990
{"engineRestoreModel", EngineRestoreModel},
9091
{"engineReplaceAnimation", EngineReplaceAnimation},
9192
{"engineRestoreAnimation", EngineRestoreAnimation},
@@ -852,6 +853,14 @@ bool CLuaEngineDefs::EngineAddClothingModel(CClientDFF* pDFF, std::string strMod
852853
return true;
853854
}
854855

856+
bool CLuaEngineDefs::EngineSetClothingCacheTime(uint timeInMs)
857+
{
858+
if (!g_pMultiplayer->SetClothingCacheTime(timeInMs))
859+
return false;
860+
861+
return true;
862+
}
863+
855864
int CLuaEngineDefs::EngineRestoreModel(lua_State* luaVM)
856865
{
857866
// Grab the model ID

Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class CLuaEngineDefs : public CLuaDefs
6060
LUA_DECLARE(EngineRestoreObjectGroupPhysicalProperties)
6161

6262
static bool EngineAddClothingModel(CClientDFF* pDff, std::string strModelName);
63+
static bool EngineSetClothingCacheTime(uint timeInMs);
6364
static bool EngineAddClothingTXD(CClientTXD* pTxd, std::string strModelName);
6465
static uint EngineGetModelFlags(uint uiModelID);
6566
static bool EngineSetModelFlags(uint uiModelID, uint uiFlags, std::optional<bool> bIdeFlags);

Client/multiplayer_sa/CMultiplayerSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ class CMultiplayerSA : public CMultiplayer
345345

346346
virtual void GetRwResourceStats(SRwResourceStats& outStats);
347347
virtual void GetClothesCacheStats(SClothesCacheStats& outStats);
348+
virtual void ResetClothingCacheTime();
349+
virtual bool SetClothingCacheTime(uint timeInMs);
348350
virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected);
349351
virtual void SetMirrorsEnabled(bool bEnabled);
350352

Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#define CLOTHES_REF_TEST 1 // Debug clothes geometry refs
1818

19+
static constexpr uint DEFAULT_CACHE_TIME = 1000;
20+
1921
////////////////////////////////////////////////
2022
//
2123
// class CPedClothesDesc
@@ -126,7 +128,7 @@ class CClumpStore
126128
{
127129
memset(&m_Stats, 0, sizeof(m_Stats));
128130
m_uiMaxSize = 4;
129-
m_uiMinCacheTime = 1000;
131+
m_uiMinCacheTime = DEFAULT_CACHE_TIME;
130132
m_iCacheRevision = 1;
131133
}
132134

@@ -138,30 +140,34 @@ class CClumpStore
138140
uint GetNumCached()
139141
{
140142
uint uiNumCached = 0;
141-
for (std::vector<SSavedClumpInfo>::iterator iter = savedClumpList.begin(); iter != savedClumpList.end(); ++iter)
143+
144+
if (m_uiMinCacheTime > 0)
142145
{
143-
SSavedClumpInfo& info = *iter;
144-
RpGeometry* pGeometry = ((RpAtomic*)((info.pClump->atomics.root.next) - 0x8))->geometry;
145-
#ifdef CLOTHES_REF_TEST
146-
if (pGeometry->refs < 21)
146+
for (std::vector<SSavedClumpInfo>::iterator iter = savedClumpList.begin(); iter != savedClumpList.end(); ++iter)
147147
{
148-
AddReportLog(7521, SString("Clothes geometry refs below expected value: %d", pGeometry->refs));
149-
pGeometry->refs = 21;
150-
}
151-
if (pGeometry->refs == 21)
148+
SSavedClumpInfo& info = *iter;
149+
RpGeometry* pGeometry = ((RpAtomic*)((info.pClump->atomics.root.next) - 0x8))->geometry;
150+
#ifdef CLOTHES_REF_TEST
151+
if (pGeometry->refs < 21)
152+
{
153+
AddReportLog(7521, SString("Clothes geometry refs below expected value: %d", pGeometry->refs));
154+
pGeometry->refs = 21;
155+
}
156+
if (pGeometry->refs == 21)
152157
#else
153-
if (pGeometry->refs == 1)
158+
if (pGeometry->refs == 1)
154159
#endif
155-
{
156-
uiNumCached++;
157-
if (!info.bUnused)
158160
{
159-
info.timeUnused = CTickCount::Now();
160-
info.bUnused = true;
161+
uiNumCached++;
162+
if (!info.bUnused)
163+
{
164+
info.timeUnused = CTickCount::Now();
165+
info.bUnused = true;
166+
}
161167
}
168+
else
169+
info.bUnused = false;
162170
}
163-
else
164-
info.bUnused = false;
165171
}
166172

167173
m_Stats.uiNumTotal = savedClumpList.size();
@@ -402,6 +408,34 @@ void CMultiplayerSA::GetClothesCacheStats(SClothesCacheStats& outStats)
402408
outStats = ms_clumpStore.m_Stats;
403409
}
404410

411+
//////////////////////////////////////////////////////////////////////////////////////////
412+
//
413+
// CMultiplayerSA::SetClothingCacheTime
414+
//
415+
//
416+
//////////////////////////////////////////////////////////////////////////////////////////
417+
bool CMultiplayerSA::SetClothingCacheTime(uint timeInMs)
418+
{
419+
if (timeInMs == ms_clumpStore.m_uiMinCacheTime)
420+
return false;
421+
422+
ms_clumpStore.savedClumpList.clear();
423+
ms_clumpStore.m_uiMinCacheTime = timeInMs;
424+
425+
return true;
426+
}
427+
428+
//////////////////////////////////////////////////////////////////////////////////////////
429+
//
430+
// CMultiplayerSA::ResetClothingCacheTime
431+
//
432+
//
433+
//////////////////////////////////////////////////////////////////////////////////////////
434+
void CMultiplayerSA::ResetClothingCacheTime()
435+
{
436+
SetClothingCacheTime(DEFAULT_CACHE_TIME);
437+
}
438+
405439
//////////////////////////////////////////////////////////////////////////////////////////
406440
//
407441
// CMultiplayerSA::InitHooks_ClothesCache

Client/sdk/multiplayer/CMultiplayer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ class CMultiplayer
455455

456456
virtual void GetRwResourceStats(SRwResourceStats& outStats) = 0;
457457
virtual void GetClothesCacheStats(SClothesCacheStats& outStats) = 0;
458+
virtual void ResetClothingCacheTime() = 0;
459+
virtual bool SetClothingCacheTime(uint timeInMs) = 0;
458460
virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected) = 0;
459461
virtual void SetMirrorsEnabled(bool bEnabled) = 0;
460462

0 commit comments

Comments
 (0)