From 3f687cc326ddce7587316dcfb87676e1dbfc134c Mon Sep 17 00:00:00 2001 From: FileEX Date: Thu, 26 Sep 2024 21:48:14 +0200 Subject: [PATCH] Cleanup 2/2 --- Client/game_sa/CModelInfoSA.cpp | 86 ++++++------------- Client/game_sa/CModelInfoSA.h | 2 +- Client/mods/deathmatch/logic/CClient2DFX.cpp | 2 +- .../deathmatch/logic/CClient2DFXManager.cpp | 2 +- .../logic/luadefs/CLuaEngineDefs.cpp | 1 + Client/sdk/game/CModelInfo.h | 2 +- 6 files changed, 33 insertions(+), 62 deletions(-) diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 6f5cd7ec78..5a6f950280 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -1206,6 +1206,7 @@ void CModelInfoSA::StaticReset2DFXEffects() // Delete copy of the default effect delete innerIter->second; + innerIter->second = nullptr; innerIter = iter->second.erase(innerIter); } @@ -2177,8 +2178,7 @@ bool CModelInfoSA::Reset2DFXEffects(bool removeCustomEffects) // Clear maps map.clear(); - ms_DefaultEffectsMap.clear(); - removedDefaultEffects.clear(); + ms_DefaultEffectsMap.erase(m_dwModelID); // Remove all custom effects if (removeCustomEffects) @@ -2190,18 +2190,8 @@ bool CModelInfoSA::Reset2DFXEffects(bool removeCustomEffects) if (!effect) continue; - // If this is not custom effect, continue - auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect); - if (it == d2fxEffects.end()) - continue; - - m_pInterface->ucNumOf2DEffects--; - MapGet(m_numCustom2dfxEffects, m_pInterface)--; - - Remove2DFX(effect, true); + Remove2DFX(effect, false); } - - d2fxEffects.clear(); } return true; @@ -2228,10 +2218,30 @@ C2DEffectSAInterface* CModelInfoSA::Add2DFXEffect(const CVector& position, const return effectInterface; } -void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom, bool decrementCounters) +bool CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool includeDefault) { + m_pInterface = ppModelInfo[m_dwModelID]; + if (!m_pInterface) + return false; + if (!effect) - return; + return false; + + auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect); + bool isCustomEffect = it != d2fxEffects.end(); + + if (!includeDefault && !isCustomEffect) + return false; + + if (!isCustomEffect) + StoreDefault2DFXEffect(effect); + + m_pInterface->ucNumOf2DEffects--; + if (isCustomEffect) + { + MapGet(m_numCustom2dfxEffects, m_pInterface)--; + d2fxEffects.erase(it); + } switch (effect->type) { @@ -2296,18 +2306,8 @@ void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom, bool } } - if (decrementCounters) - { - m_pInterface->ucNumOf2DEffects--; - MapGet(m_numCustom2dfxEffects, m_pInterface)--; - - auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect); - if (it != d2fxEffects.end()) - d2fxEffects.erase(it); - } - // If it's custom effect then delete it. If it's default effect then store it as removed - if (isCustom) + if (isCustomEffect) { delete effect; effect = nullptr; @@ -2326,24 +2326,7 @@ bool CModelInfoSA::Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefa if (!effect) return false; - auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect); - bool isCustomEffect = it != d2fxEffects.end(); - - if (!includeDefault && !isCustomEffect) - return false; - - if (!isCustomEffect) - StoreDefault2DFXEffect(effect); - - m_pInterface->ucNumOf2DEffects--; - if (isCustomEffect) - { - MapGet(m_numCustom2dfxEffects, m_pInterface)--; - d2fxEffects.erase(it); - } - - Remove2DFX(effect, isCustomEffect); - return true; + return Remove2DFX(effect, includeDefault); } bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault) @@ -2359,23 +2342,10 @@ bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault) if (!effect) continue; - auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect); - bool isCustomEffect = it != d2fxEffects.end(); - if (!includeDefault && !isCustomEffect) - continue; - - if (!isCustomEffect) - StoreDefault2DFXEffect(effect); - - m_pInterface->ucNumOf2DEffects--; - if (isCustomEffect) - MapGet(m_numCustom2dfxEffects, m_pInterface)--; - - Remove2DFX(effect, isCustomEffect); + Remove2DFX(effect, includeDefault); } d2fxEffects.clear(); - return true; } diff --git a/Client/game_sa/CModelInfoSA.h b/Client/game_sa/CModelInfoSA.h index da195f4cf7..6c5691a893 100644 --- a/Client/game_sa/CModelInfoSA.h +++ b/Client/game_sa/CModelInfoSA.h @@ -472,7 +472,7 @@ class CModelInfoSA : public CModelInfo // 2DFX functions C2DEffectSAInterface* Add2DFXEffect(const CVector& position, const e2dEffectType& type); - void Remove2DFX(C2DEffectSAInterface* effect, bool isCustom = false, bool decrementCounters = false); + bool Remove2DFX(C2DEffectSAInterface* effect, bool includeDefault); bool Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefault = false); bool RemoveAll2DFXEffects(bool includeDefault); C2DEffectSAInterface* Get2DFXFromIndex(std::uint32_t index); diff --git a/Client/mods/deathmatch/logic/CClient2DFX.cpp b/Client/mods/deathmatch/logic/CClient2DFX.cpp index a3b0ce7810..3bbe11e5ad 100644 --- a/Client/mods/deathmatch/logic/CClient2DFX.cpp +++ b/Client/mods/deathmatch/logic/CClient2DFX.cpp @@ -29,7 +29,7 @@ CClient2DFX::~CClient2DFX() if (!modelInfo) return; - modelInfo->Remove2DFX(m_effectInterface, true, true); + modelInfo->Remove2DFX(m_effectInterface, false); } bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, const effectDataMap& effectData) diff --git a/Client/mods/deathmatch/logic/CClient2DFXManager.cpp b/Client/mods/deathmatch/logic/CClient2DFXManager.cpp index 5a8372d476..d3f1ed3810 100644 --- a/Client/mods/deathmatch/logic/CClient2DFXManager.cpp +++ b/Client/mods/deathmatch/logic/CClient2DFXManager.cpp @@ -305,7 +305,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d { if (std::holds_alternative(propertyValue)) { - unsigned long colorValue = static_cast(std::get(propertyValue)); + std::uint32_t colorValue = static_cast(std::get(propertyValue)); light.color = RwColor{static_cast((colorValue >> 16) & mask(8)), static_cast((colorValue >> 8) & mask(8)), static_cast((colorValue >> 0) & mask(8)), static_cast((colorValue >> 24) & mask(8))}; return true; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp index 69ebd9068f..f701664ef8 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp @@ -2691,6 +2691,7 @@ bool CLuaEngineDefs::EngineSetModel2DFXProperty(std::uint32_t modelID, std::uint if (!effect) return false; + modelInfo->StoreDefault2DFXEffect(effect); return m_p2DFXManager->Set2DFXProperty(effect, property, propertyValue); } diff --git a/Client/sdk/game/CModelInfo.h b/Client/sdk/game/CModelInfo.h index bb1036d498..6de796075b 100644 --- a/Client/sdk/game/CModelInfo.h +++ b/Client/sdk/game/CModelInfo.h @@ -346,7 +346,7 @@ class CModelInfo // 2dfx functions virtual C2DEffectSAInterface* Add2DFXEffect(const CVector& position, const e2dEffectType& type) = 0; - virtual void Remove2DFX(C2DEffectSAInterface* effect, bool isCustom = false, bool decrementCounters = false) = 0; + virtual bool Remove2DFX(C2DEffectSAInterface* effect, bool includeDefault) = 0; virtual bool Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefault = false) = 0; virtual bool RemoveAll2DFXEffects(bool includeDefault = false) = 0;