Skip to content

Commit 837354d

Browse files
committed
Update
1 parent a6d3c2a commit 837354d

12 files changed

+879
-115
lines changed

Client/game_sa/C2DEffectSAInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct t2dEffectLight
5151
// Flags 1
5252
std::uint16_t checkObstacles : 1;
5353
std::uint16_t fogType : 1;
54+
std::uint16_t fogType2 : 1;
5455
std::uint16_t withoutCorona : 1;
5556
std::uint16_t onlyLongDistance : 1;
5657
std::uint16_t atDay : 1;

Client/game_sa/CModelInfoSA.cpp

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ std::unordered_map<DWORD, unsigned short> CModelInfo
3737
std::unordered_map<DWORD, std::pair<float, float>> CModelInfoSA::ms_VehicleModelDefaultWheelSizes;
3838
std::map<unsigned short, int> CModelInfoSA::ms_DefaultTxdIDMap;
3939

40-
std::unordered_map<DWORD, std::unordered_map<C2DEffectSAInterface*, C2DEffectSAInterface*>> CModelInfoSA::ms_DefaultEffectsMap;
40+
std::unordered_map<DWORD, std::unordered_map<C2DEffectSAInterface*, C2DEffectSAInterface*>> CModelInfoSA::ms_DefaultEffectsMap;
4141
static std::unordered_map<CBaseModelInfoSAInterface*, std::uint32_t> m_numCustom2dfxEffects;
4242
static std::vector<C2DEffectSAInterface*> d2fxEffects;
4343
static std::vector<C2DEffectSAInterface*> removedDefaultEffects;
@@ -1185,7 +1185,47 @@ void CModelInfoSA::ResetAlphaTransparency()
11851185

11861186
void CModelInfoSA::StaticReset2DFXEffects()
11871187
{
1188+
for (auto& iter = ms_DefaultEffectsMap.begin(); iter != ms_DefaultEffectsMap.end(); iter++)
1189+
{
1190+
CBaseModelInfoSAInterface* modelInfoInterface = ppModelInfo[iter->first];
1191+
if (!modelInfoInterface)
1192+
continue;
1193+
1194+
for (auto innerIter = iter->second.begin(); innerIter != iter->second.end();)
1195+
{
1196+
// Copy default effect
1197+
memcpy(innerIter->first, innerIter->second, sizeof(C2DEffectSAInterface));
1198+
1199+
// Increase the counter if this effect was removed
1200+
auto& removedEffect = std::find(removedDefaultEffects.begin(), removedDefaultEffects.end(), innerIter->first);
1201+
if (removedEffect != removedDefaultEffects.end())
1202+
{
1203+
removedDefaultEffects.erase(removedEffect);
1204+
modelInfoInterface->ucNumOf2DEffects++;
1205+
}
11881206

1207+
// Delete copy of the default effect
1208+
delete innerIter->second;
1209+
innerIter = iter->second.erase(innerIter);
1210+
}
1211+
1212+
// Decrement the counter by the number of custom effects
1213+
auto customEffectsCount = MapGet(m_numCustom2dfxEffects, modelInfoInterface);
1214+
if (customEffectsCount && customEffectsCount > 0)
1215+
modelInfoInterface->ucNumOf2DEffects -= customEffectsCount;
1216+
1217+
MapSet(m_numCustom2dfxEffects, modelInfoInterface, 0);
1218+
}
1219+
1220+
// Remove all custom effects
1221+
for (auto& customEffect : d2fxEffects)
1222+
if (customEffect)
1223+
delete customEffect;
1224+
1225+
// Clear maps
1226+
removedDefaultEffects.clear();
1227+
ms_DefaultEffectsMap.clear();
1228+
d2fxEffects.clear();
11891229
}
11901230

11911231
short CModelInfoSA::GetAvailableVehicleMod(unsigned short usUpgrade)
@@ -2187,7 +2227,7 @@ C2DEffectSAInterface* CModelInfoSA::Add2DFXEffect(const CVector& position, const
21872227
return effectInterface;
21882228
}
21892229

2190-
void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom)
2230+
void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom, bool decrementCounters)
21912231
{
21922232
if (!effect)
21932233
return;
@@ -2255,6 +2295,16 @@ void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom)
22552295
}
22562296
}
22572297

2298+
if (decrementCounters)
2299+
{
2300+
m_pInterface->ucNumOf2DEffects--;
2301+
MapGet(m_numCustom2dfxEffects, m_pInterface)--;
2302+
2303+
auto& it = std::find(d2fxEffects.begin(), d2fxEffects.end(), effect);
2304+
if (it != d2fxEffects.end())
2305+
d2fxEffects.erase(it);
2306+
}
2307+
22582308
// If it's custom effect then delete it. If it's default effect then store it as removed
22592309
if (isCustom)
22602310
{
@@ -2281,7 +2331,8 @@ bool CModelInfoSA::Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefa
22812331
if (!includeDefault && !isCustomEffect)
22822332
return false;
22832333

2284-
StoreDefault2DFXEffect(effect);
2334+
if (!isCustomEffect)
2335+
StoreDefault2DFXEffect(effect);
22852336

22862337
m_pInterface->ucNumOf2DEffects--;
22872338
if (isCustomEffect)
@@ -2313,7 +2364,8 @@ bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault)
23132364
if (!includeDefault && !isCustomEffect)
23142365
continue;
23152366

2316-
StoreDefault2DFXEffect(effect);
2367+
if (!isCustomEffect)
2368+
StoreDefault2DFXEffect(effect);
23172369

23182370
m_pInterface->ucNumOf2DEffects--;
23192371
if (isCustomEffect)

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);
475+
void Remove2DFX(C2DEffectSAInterface* effect, bool isCustom = false, bool decrementCounters = false);
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ CClient2DFX::CClient2DFX(class CClientManager* manager, ElementID ID)
2323
CClient2DFX::~CClient2DFX()
2424
{
2525
m_2DFXManager->RemoveFromList(this);
26+
27+
// Destroy effect
28+
CModelInfo* modelInfo = g_pGame->GetModelInfo(m_model);
29+
if (!modelInfo)
30+
return;
31+
32+
modelInfo->Remove2DFX(m_effectInterface, true, true);
2633
}
2734

28-
bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, std::unordered_map<std::string, std::variant<bool, float, std::string>>& effectData)
35+
bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, const effectDataMap& effectData)
2936
{
3037
CModelInfo* modelInfo = g_pGame->GetModelInfo(static_cast<DWORD>(model));
3138
if (!modelInfo)
@@ -38,6 +45,7 @@ bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2d
3845
// Set effect
3946
m_effectInterface = effect;
4047
m_effectType = effect->type;
48+
m_model = static_cast<DWORD>(model);
4149

4250
if (!m_2DFXManager->Set2DFXProperties(effect, effectData))
4351
return false;

Client/mods/deathmatch/logic/CClient2DFX.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "CClientEntity.h"
1212

13+
using effectDataMap = std::unordered_map<std::string, std::variant<bool, float, std::string>>;
14+
1315
class CClient2DFX final : public CClientEntity
1416
{
1517
DECLARE_CLASS(CClient2DFX, CClientEntity)
@@ -25,7 +27,7 @@ class CClient2DFX final : public CClientEntity
2527
void GetPosition(CVector& vecPosition) const {}
2628
void SetPosition(const CVector& vecPosition){}
2729

28-
bool Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, std::unordered_map<std::string, std::variant<bool, float, std::string>>& effectData);
30+
bool Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, const effectDataMap& effectData);
2931

3032
e2dEffectType Get2DFXType() const noexcept { return m_effectType; }
3133
C2DEffectSAInterface* Get2DFX() const noexcept { return m_effectInterface; }
@@ -34,4 +36,5 @@ class CClient2DFX final : public CClientEntity
3436
class CClient2DFXManager* m_2DFXManager;
3537
C2DEffectSAInterface* m_effectInterface;
3638
e2dEffectType m_effectType;
39+
DWORD m_model;
3740
};

0 commit comments

Comments
 (0)