Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Sep 26, 2024
1 parent a6d3c2a commit 837354d
Show file tree
Hide file tree
Showing 12 changed files with 879 additions and 115 deletions.
1 change: 1 addition & 0 deletions Client/game_sa/C2DEffectSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct t2dEffectLight
// Flags 1
std::uint16_t checkObstacles : 1;
std::uint16_t fogType : 1;
std::uint16_t fogType2 : 1;
std::uint16_t withoutCorona : 1;
std::uint16_t onlyLongDistance : 1;
std::uint16_t atDay : 1;
Expand Down
60 changes: 56 additions & 4 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::unordered_map<DWORD, unsigned short> CModelInfo
std::unordered_map<DWORD, std::pair<float, float>> CModelInfoSA::ms_VehicleModelDefaultWheelSizes;
std::map<unsigned short, int> CModelInfoSA::ms_DefaultTxdIDMap;

std::unordered_map<DWORD, std::unordered_map<C2DEffectSAInterface*, C2DEffectSAInterface*>> CModelInfoSA::ms_DefaultEffectsMap;
std::unordered_map<DWORD, std::unordered_map<C2DEffectSAInterface*, C2DEffectSAInterface*>> CModelInfoSA::ms_DefaultEffectsMap;
static std::unordered_map<CBaseModelInfoSAInterface*, std::uint32_t> m_numCustom2dfxEffects;
static std::vector<C2DEffectSAInterface*> d2fxEffects;
static std::vector<C2DEffectSAInterface*> removedDefaultEffects;
Expand Down Expand Up @@ -1185,7 +1185,47 @@ void CModelInfoSA::ResetAlphaTransparency()

void CModelInfoSA::StaticReset2DFXEffects()
{
for (auto& iter = ms_DefaultEffectsMap.begin(); iter != ms_DefaultEffectsMap.end(); iter++)
{
CBaseModelInfoSAInterface* modelInfoInterface = ppModelInfo[iter->first];
if (!modelInfoInterface)
continue;

for (auto innerIter = iter->second.begin(); innerIter != iter->second.end();)
{
// Copy default effect
memcpy(innerIter->first, innerIter->second, sizeof(C2DEffectSAInterface));

// Increase the counter if this effect was removed
auto& removedEffect = std::find(removedDefaultEffects.begin(), removedDefaultEffects.end(), innerIter->first);
if (removedEffect != removedDefaultEffects.end())
{
removedDefaultEffects.erase(removedEffect);
modelInfoInterface->ucNumOf2DEffects++;
}

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

// Decrement the counter by the number of custom effects
auto customEffectsCount = MapGet(m_numCustom2dfxEffects, modelInfoInterface);
if (customEffectsCount && customEffectsCount > 0)
modelInfoInterface->ucNumOf2DEffects -= customEffectsCount;

MapSet(m_numCustom2dfxEffects, modelInfoInterface, 0);
}

// Remove all custom effects
for (auto& customEffect : d2fxEffects)
if (customEffect)
delete customEffect;

// Clear maps
removedDefaultEffects.clear();
ms_DefaultEffectsMap.clear();
d2fxEffects.clear();
}

short CModelInfoSA::GetAvailableVehicleMod(unsigned short usUpgrade)
Expand Down Expand Up @@ -2187,7 +2227,7 @@ C2DEffectSAInterface* CModelInfoSA::Add2DFXEffect(const CVector& position, const
return effectInterface;
}

void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom)
void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom, bool decrementCounters)
{
if (!effect)
return;
Expand Down Expand Up @@ -2255,6 +2295,16 @@ void CModelInfoSA::Remove2DFX(C2DEffectSAInterface* effect, bool isCustom)
}
}

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)
{
Expand All @@ -2281,7 +2331,8 @@ bool CModelInfoSA::Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefa
if (!includeDefault && !isCustomEffect)
return false;

StoreDefault2DFXEffect(effect);
if (!isCustomEffect)
StoreDefault2DFXEffect(effect);

m_pInterface->ucNumOf2DEffects--;
if (isCustomEffect)
Expand Down Expand Up @@ -2313,7 +2364,8 @@ bool CModelInfoSA::RemoveAll2DFXEffects(bool includeDefault)
if (!includeDefault && !isCustomEffect)
continue;

StoreDefault2DFXEffect(effect);
if (!isCustomEffect)
StoreDefault2DFXEffect(effect);

m_pInterface->ucNumOf2DEffects--;
if (isCustomEffect)
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);
void Remove2DFX(C2DEffectSAInterface* effect, bool isCustom = false, bool decrementCounters = false);
bool Remove2DFXEffectAtIndex(std::uint32_t index, bool includeDefault = false);
bool RemoveAll2DFXEffects(bool includeDefault);
C2DEffectSAInterface* Get2DFXFromIndex(std::uint32_t index);
Expand Down
10 changes: 9 additions & 1 deletion Client/mods/deathmatch/logic/CClient2DFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ CClient2DFX::CClient2DFX(class CClientManager* manager, ElementID ID)
CClient2DFX::~CClient2DFX()
{
m_2DFXManager->RemoveFromList(this);

// Destroy effect
CModelInfo* modelInfo = g_pGame->GetModelInfo(m_model);
if (!modelInfo)
return;

modelInfo->Remove2DFX(m_effectInterface, true, true);
}

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)
bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2dEffectType& type, const effectDataMap& effectData)
{
CModelInfo* modelInfo = g_pGame->GetModelInfo(static_cast<DWORD>(model));
if (!modelInfo)
Expand All @@ -38,6 +45,7 @@ bool CClient2DFX::Create(std::uint32_t model, const CVector& position, const e2d
// Set effect
m_effectInterface = effect;
m_effectType = effect->type;
m_model = static_cast<DWORD>(model);

if (!m_2DFXManager->Set2DFXProperties(effect, effectData))
return false;
Expand Down
5 changes: 4 additions & 1 deletion Client/mods/deathmatch/logic/CClient2DFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "CClientEntity.h"

using effectDataMap = std::unordered_map<std::string, std::variant<bool, float, std::string>>;

class CClient2DFX final : public CClientEntity
{
DECLARE_CLASS(CClient2DFX, CClientEntity)
Expand All @@ -25,7 +27,7 @@ class CClient2DFX final : public CClientEntity
void GetPosition(CVector& vecPosition) const {}
void SetPosition(const CVector& vecPosition){}

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

e2dEffectType Get2DFXType() const noexcept { return m_effectType; }
C2DEffectSAInterface* Get2DFX() const noexcept { return m_effectInterface; }
Expand All @@ -34,4 +36,5 @@ class CClient2DFX final : public CClientEntity
class CClient2DFXManager* m_2DFXManager;
C2DEffectSAInterface* m_effectInterface;
e2dEffectType m_effectType;
DWORD m_model;
};
Loading

0 comments on commit 837354d

Please sign in to comment.