Skip to content

Add function to change clothing cache time #4356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 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,11 @@ bool CLuaEngineDefs::EngineAddClothingModel(CClientDFF* pDFF, std::string strMod
return true;
}

bool CLuaEngineDefs::EngineSetClothingCacheTime(std::uint32_t timeInMs)
{
return g_pMultiplayer->SetClothingCacheTime(timeInMs);
}

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(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<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(std::uint32_t timeInMs);
virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected);
virtual void SetMirrorsEnabled(bool bEnabled);

Expand Down
74 changes: 54 additions & 20 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 @@ -113,7 +115,7 @@ class CClumpStore

std::vector<SSavedClumpInfo> savedClumpList;
uint m_uiMaxSize;
uint m_uiMinCacheTime;
std::uint32_t m_minCacheTime;
SClothesCacheStats m_Stats;
int m_iCacheRevision;

Expand All @@ -126,7 +128,7 @@ class CClumpStore
{
memset(&m_Stats, 0, sizeof(m_Stats));
m_uiMaxSize = 4;
m_uiMinCacheTime = 1000;
m_minCacheTime = 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_minCacheTime > 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 @@ -236,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)
{
Expand Down Expand Up @@ -402,6 +408,34 @@ void CMultiplayerSA::GetClothesCacheStats(SClothesCacheStats& outStats)
outStats = ms_clumpStore.m_Stats;
}

//////////////////////////////////////////////////////////////////////////////////////////
//
// CMultiplayerSA::SetClothingCacheTime
//
//
//////////////////////////////////////////////////////////////////////////////////////////
bool CMultiplayerSA::SetClothingCacheTime(std::uint32_t timeInMs)
{
if (timeInMs == ms_clumpStore.m_minCacheTime)
return false;

ms_clumpStore.savedClumpList.clear();
ms_clumpStore.m_minCacheTime = 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(std::uint32_t timeInMs) = 0;
virtual void SetIsMinimizedAndNotConnected(bool bIsMinimizedAndNotConnected) = 0;
virtual void SetMirrorsEnabled(bool bEnabled) = 0;

Expand Down