Skip to content

Commit

Permalink
Cleanup 2/2
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Sep 26, 2024
1 parent 0f8cbc1 commit 3f687cc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 62 deletions.
86 changes: 28 additions & 58 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ void CModelInfoSA::StaticReset2DFXEffects()

// Delete copy of the default effect
delete innerIter->second;
innerIter->second = nullptr;
innerIter = iter->second.erase(innerIter);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CModelInfoSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClient2DFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClient2DFXManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
{
if (std::holds_alternative<float>(propertyValue))
{
unsigned long colorValue = static_cast<unsigned long>(std::get<float>(propertyValue));
std::uint32_t colorValue = static_cast<std::uint32_t>(std::get<float>(propertyValue));
light.color = RwColor{static_cast<std::uint8_t>((colorValue >> 16) & mask(8)), static_cast<std::uint8_t>((colorValue >> 8) & mask(8)), static_cast<std::uint8_t>((colorValue >> 0) & mask(8)), static_cast<std::uint8_t>((colorValue >> 24) & mask(8))};

return true;
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CModelInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3f687cc

Please sign in to comment.