Skip to content

Commit

Permalink
ChaosMod: Exclude meta effects from ClearActiveEffects & ClearMostRec…
Browse files Browse the repository at this point in the history
…entEffect
  • Loading branch information
pongo1231 committed Oct 15, 2023
1 parent 1ffac55 commit 00cbe11
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
42 changes: 19 additions & 23 deletions ChaosMod/Components/EffectDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,6 @@ void EffectDispatcher::UpdateEffects(int deltaTime)

bool isEffectPaused = EffectThreads::IsThreadPaused(effect.ThreadId);

bool isMeta = false;
// Temporary non-timed effects will have their entries removed already since their OnStop is called immediately
if (g_EnabledEffects.contains(effect.Identifier))
{
const auto &effectData = g_EnabledEffects.at(effect.Identifier);
isMeta = effectData.IsMeta();
}

if (!EffectThreads::DoesThreadExist(effect.ThreadId))
{
if (effect.MaxTime > 0.f
Expand All @@ -475,7 +467,7 @@ void EffectDispatcher::UpdateEffects(int deltaTime)
EffectThreads::RunThread(effect.ThreadId);
OnPostRunEffect.Fire(effect.Identifier);

if (!isMeta)
if (!effect.IsMeta)
{
activeEffects++;
}
Expand All @@ -488,7 +480,7 @@ void EffectDispatcher::UpdateEffects(int deltaTime)

if (effect.MaxTime > 0.f)
{
if (isMeta)
if (isEffectPaused)
{
effect.Timer -= adjustedDeltaTime;
}
Expand All @@ -507,7 +499,7 @@ void EffectDispatcher::UpdateEffects(int deltaTime)
* (1.f + (t / 5 - 1) * std::max(0.f, SharedState.ActiveEffects.size() - n) / (m - n));
}

if ((effect.MaxTime > 0.f && effect.Timer <= 0.f) || (!isMeta && activeEffects > maxEffects))
if ((effect.MaxTime > 0.f && effect.Timer <= 0.f) || (!effect.IsMeta && activeEffects > maxEffects))
{
if (effect.Timer < -60.f)
{
Expand Down Expand Up @@ -772,33 +764,37 @@ void EffectDispatcher::ClearEffects(ClearEffectsFlags clearEffectFlags)
: ClearEffectsState::AllRestartPermanent;
}

void EffectDispatcher::ClearActiveEffects(const EffectIdentifier &exclude)
void EffectDispatcher::ClearActiveEffects()
{
for (auto it = SharedState.ActiveEffects.begin(); it != SharedState.ActiveEffects.end();)
for (auto it = SharedState.ActiveEffects.begin(); it != SharedState.ActiveEffects.end(); it++)
{
ActiveEffect &effect = *it;
auto &effect = *it;

if (effect.Identifier != exclude)
if (effect.IsMeta || effect.Timer <= 0.f)
{
EffectThreads::StopThread(effect.ThreadId);
effect.IsStopping = true;
continue;
}

it++;
EffectThreads::StopThread(effect.ThreadId);
effect.IsStopping = true;
}
}

void EffectDispatcher::ClearMostRecentEffect()
{
if (!SharedState.ActiveEffects.empty())
for (auto it = SharedState.ActiveEffects.rbegin(); it != SharedState.ActiveEffects.rend(); it++)
{
auto &mostRecentEffect = SharedState.ActiveEffects[SharedState.ActiveEffects.size() - 1];
auto &effect = *it;

if (mostRecentEffect.Timer > 0.f)
if (effect.IsMeta || effect.Timer <= 0.f)
{
EffectThreads::StopThread(mostRecentEffect.ThreadId);
mostRecentEffect.IsStopping = true;
continue;
}

EffectThreads::StopThread(effect.ThreadId);
effect.IsStopping = true;

break;
}
}

Expand Down
5 changes: 4 additions & 1 deletion ChaosMod/Components/EffectDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class EffectDispatcher : public Component
float Timer = 0.f;
float MaxTime = 0.f;

bool IsMeta = false;

bool HideEffectName = false;
bool IsStopping = false;

Expand All @@ -60,6 +62,7 @@ class EffectDispatcher : public Component
Timer = effectDuration;
MaxTime = effectDuration;
HideEffectName = effectData.ShouldHideRealNameOnStart();
IsMeta = effectData.IsMeta();

auto timedType = g_EnabledEffects.at(effectIdentifier).TimedType;
ThreadId = EffectThreads::CreateThread(registeredEffect, timedType != EffectTimedType::NotTimed);
Expand Down Expand Up @@ -180,7 +183,7 @@ class EffectDispatcher : public Component
ClearEffectsFlag_NoRestartPermanentEffects = (1 << 0),
};
void ClearEffects(ClearEffectsFlags clearEffectFlags = ClearEffectsFlag_None);
void ClearActiveEffects(const EffectIdentifier &exclude = EffectIdentifier());
void ClearActiveEffects();
void ClearMostRecentEffect();

std::vector<RegisteredEffect *> GetRecentEffects(int distance, std::string_view ignoreEffect = {}) const;
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/db/Meta/MetaNoChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static void OnStart()

if (ComponentExists<EffectDispatcher>())
{
GetComponent<EffectDispatcher>()->ClearActiveEffects({ "meta_nochaos" });
GetComponent<EffectDispatcher>()->ClearActiveEffects();
}
}

Expand Down

0 comments on commit 00cbe11

Please sign in to comment.