Skip to content

Commit 3f687cc

Browse files
committed
Cleanup 2/2
1 parent 0f8cbc1 commit 3f687cc

File tree

6 files changed

+33
-62
lines changed

6 files changed

+33
-62
lines changed

Client/game_sa/CModelInfoSA.cpp

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ void CModelInfoSA::StaticReset2DFXEffects()
12061206

12071207
// Delete copy of the default effect
12081208
delete innerIter->second;
1209+
innerIter->second = nullptr;
12091210
innerIter = iter->second.erase(innerIter);
12101211
}
12111212

@@ -2177,8 +2178,7 @@ bool CModelInfoSA::Reset2DFXEffects(bool removeCustomEffects)
21772178

21782179
// Clear maps
21792180
map.clear();
2180-
ms_DefaultEffectsMap.clear();
2181-
removedDefaultEffects.clear();
2181+
ms_DefaultEffectsMap.erase(m_dwModelID);
21822182

21832183
// Remove all custom effects
21842184
if (removeCustomEffects)
@@ -2190,18 +2190,8 @@ bool CModelInfoSA::Reset2DFXEffects(bool removeCustomEffects)
21902190
if (!effect)
21912191
continue;
21922192

2193-
// If this is not custom effect, continue
2194-
auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect);
2195-
if (it == d2fxEffects.end())
2196-
continue;
2197-
2198-
m_pInterface->ucNumOf2DEffects--;
2199-
MapGet(m_numCustom2dfxEffects, m_pInterface)--;
2200-
2201-
Remove2DFX(effect, true);
2193+
Remove2DFX(effect, false);
22022194
}
2203-
2204-
d2fxEffects.clear();
22052195
}
22062196

22072197
return true;
@@ -2228,10 +2218,30 @@ C2DEffectSAInterface* CModelInfoSA::Add2DFXEffect(const CVector& position, const
22282218
return effectInterface;
22292219
}
22302220

2231-
void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom, bool decrementCounters)
2221+
bool CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool includeDefault)
22322222
{
2223+
m_pInterface = ppModelInfo[m_dwModelID];
2224+
if (!m_pInterface)
2225+
return false;
2226+
22332227
if (!effect)
2234-
return;
2228+
return false;
2229+
2230+
auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect);
2231+
bool isCustomEffect = it != d2fxEffects.end();
2232+
2233+
if (!includeDefault && !isCustomEffect)
2234+
return false;
2235+
2236+
if (!isCustomEffect)
2237+
StoreDefault2DFXEffect(effect);
2238+
2239+
m_pInterface->ucNumOf2DEffects--;
2240+
if (isCustomEffect)
2241+
{
2242+
MapGet(m_numCustom2dfxEffects, m_pInterface)--;
2243+
d2fxEffects.erase(it);
2244+
}
22352245

22362246
switch (effect->type)
22372247
{
@@ -2296,18 +2306,8 @@ void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom, bool
22962306
}
22972307
}
22982308

2299-
if (decrementCounters)
2300-
{
2301-
m_pInterface->ucNumOf2DEffects--;
2302-
MapGet(m_numCustom2dfxEffects, m_pInterface)--;
2303-
2304-
auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect);
2305-
if (it != d2fxEffects.end())
2306-
d2fxEffects.erase(it);
2307-
}
2308-
23092309
// If it's custom effect then delete it. If it's default effect then store it as removed
2310-
if (isCustom)
2310+
if (isCustomEffect)
23112311
{
23122312
delete effect;
23132313
effect = nullptr;
@@ -2326,24 +2326,7 @@ bool CModelInfoSA::Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefa
23262326
if (!effect)
23272327
return false;
23282328

2329-
auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect);
2330-
bool isCustomEffect = it != d2fxEffects.end();
2331-
2332-
if (!includeDefault && !isCustomEffect)
2333-
return false;
2334-
2335-
if (!isCustomEffect)
2336-
StoreDefault2DFXEffect(effect);
2337-
2338-
m_pInterface->ucNumOf2DEffects--;
2339-
if (isCustomEffect)
2340-
{
2341-
MapGet(m_numCustom2dfxEffects, m_pInterface)--;
2342-
d2fxEffects.erase(it);
2343-
}
2344-
2345-
Remove2DFX(effect, isCustomEffect);
2346-
return true;
2329+
return Remove2DFX(effect, includeDefault);
23472330
}
23482331

23492332
bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault)
@@ -2359,23 +2342,10 @@ bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault)
23592342
if (!effect)
23602343
continue;
23612344

2362-
auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect);
2363-
bool isCustomEffect = it != d2fxEffects.end();
2364-
if (!includeDefault && !isCustomEffect)
2365-
continue;
2366-
2367-
if (!isCustomEffect)
2368-
StoreDefault2DFXEffect(effect);
2369-
2370-
m_pInterface->ucNumOf2DEffects--;
2371-
if (isCustomEffect)
2372-
MapGet(m_numCustom2dfxEffects, m_pInterface)--;
2373-
2374-
Remove2DFX(effect, isCustomEffect);
2345+
Remove2DFX(effect, includeDefault);
23752346
}
23762347

23772348
d2fxEffects.clear();
2378-
23792349
return true;
23802350
}
23812351

Client/game_sa/CModelInfoSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ class CModelInfoSA : public CModelInfo
472472

473473
// 2DFX functions
474474
C2DEffectSAInterface* Add2DFXEffect(const CVector& position, const e2dEffectType& type);
475-
void Remove2DFX(C2DEffectSAInterface* effect, bool isCustom = false, bool decrementCounters = false);
475+
bool Remove2DFX(C2DEffectSAInterface* effect, bool includeDefault);
476476
bool Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefault = false);
477477
bool RemoveAll2DFXEffects(bool includeDefault);
478478
C2DEffectSAInterface* Get2DFXFromIndex(std::uint32_t index);

Client/mods/deathmatch/logic/CClient2DFX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CClient2DFX::~CClient2DFX()
2929
if (!modelInfo)
3030
return;
3131

32-
modelInfo->Remove2DFX(m_effectInterface, true, true);
32+
modelInfo->Remove2DFX(m_effectInterface, false);
3333
}
3434

3535
bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, const effectDataMap& effectData)

Client/mods/deathmatch/logic/CClient2DFXManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ bool CClient2DFXManager::Set2DFXProperty(C2DEffectSAInterface* effect, const e2d
305305
{
306306
if (std::holds_alternative<float>(propertyValue))
307307
{
308-
unsigned long colorValue = static_cast<unsigned long>(std::get<float>(propertyValue));
308+
std::uint32_t colorValue = static_cast<std::uint32_t>(std::get<float>(propertyValue));
309309
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))};
310310

311311
return true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,7 @@ bool CLuaEngineDefs::EngineSetModel2DFXProperty(std::uint32_t modelID, std::uint
26912691
if (!effect)
26922692
return false;
26932693

2694+
modelInfo->StoreDefault2DFXEffect(effect);
26942695
return m_p2DFXManager->Set2DFXProperty(effect, property, propertyValue);
26952696
}
26962697

Client/sdk/game/CModelInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class CModelInfo
346346

347347
// 2dfx functions
348348
virtual C2DEffectSAInterface* Add2DFXEffect(const CVector& position, const e2dEffectType& type) = 0;
349-
virtual void Remove2DFX(C2DEffectSAInterface* effect, bool isCustom = false, bool decrementCounters = false) = 0;
349+
virtual bool Remove2DFX(C2DEffectSAInterface* effect, bool includeDefault) = 0;
350350
virtual bool Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefault = false) = 0;
351351
virtual bool RemoveAll2DFXEffects(bool includeDefault = false) = 0;
352352

0 commit comments

Comments
 (0)