Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void CLuaEngineDefs::LoadFunctions()
{"engineRestoreCOL", EngineRestoreCOL},
{"engineReplaceModel", EngineReplaceModel},
{"engineAddClothingModel", ArgumentParser<EngineAddClothingModel>},
{"engineSetClothingCacheTime", ArgumentParser<EngineSetClothingCacheTime>},
{"engineRestoreModel", EngineRestoreModel},
{"engineReplaceAnimation", EngineReplaceAnimation},
{"engineRestoreAnimation", EngineRestoreAnimation},
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> bIdeFlags);
Expand Down
2 changes: 2 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
70 changes: 52 additions & 18 deletions Client/multiplayer_sa/CMultiplayerSA_ClothesCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#define CLOTHES_REF_TEST 1 // Debug clothes geometry refs

static constexpr std::uint32_t DEFAULT_CACHE_TIME = 1000;

////////////////////////////////////////////////
//
// class CPedClothesDesc
Expand Down Expand Up @@ -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;
}

Expand All @@ -138,30 +140,34 @@ class CClumpStore
uint GetNumCached()
{
uint uiNumCached = 0;
for (std::vector<SSavedClumpInfo>::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<SSavedClumpInfo>::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();
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Client/sdk/multiplayer/CMultiplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down