Skip to content

Commit

Permalink
ChaosMod: Implement EffectCategory & major cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Jan 21, 2025
1 parent 37ba7f5 commit 81092df
Show file tree
Hide file tree
Showing 317 changed files with 1,324 additions and 773 deletions.
17 changes: 7 additions & 10 deletions ChaosMod/Components/DebugMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "DebugMenu.h"

#include "Components/EffectDispatcher.h"

#include "Effects/EnabledEffects.h"
#include "Util/OptionsManager.h"

#define MAX_VIS_ITEMS 15
Expand All @@ -16,13 +16,10 @@ DebugMenu::DebugMenu() : Component()

for (const auto &pair : g_EnabledEffects)
{
const auto &[effectIdentifier, effectData] = pair;
const auto &[effectId, effectData] = pair;

if (!effectData.IsHidden())
{
m_Effects.emplace_back(effectIdentifier,
effectData.HasCustomName() ? effectData.CustomName : effectData.Name);
}
m_Effects.emplace_back(effectId, effectData.HasCustomName() ? effectData.CustomName : effectData.Name);
}

if (m_Effects.empty())
Expand All @@ -41,8 +38,8 @@ DebugMenu::DebugMenu() : Component()
return false;
else if (idx >= b.EffectName.size())
return true;
auto ai = std::toupper(a.EffectName[idx]);

auto ai = std::toupper(a.EffectName[idx]);
auto bi = std::toupper(b.EffectName[idx]);
if (ai != bi)
return ai < bi;
Expand Down Expand Up @@ -83,7 +80,7 @@ void DebugMenu::OnRun()
m_DispatchEffect = false;

if (ComponentExists<EffectDispatcher>())
GetComponent<EffectDispatcher>()->DispatchEffect(m_Effects[m_SelectedIdx].Identifier);
GetComponent<EffectDispatcher>()->DispatchEffect(m_Effects[m_SelectedIdx].Id);
}

float y = .1f;
Expand Down Expand Up @@ -211,7 +208,7 @@ void DebugMenu::OnKeyInput(DWORD key, bool repeated, bool isUpNow, bool isCtrlPr
break;
}
case VK_RETURN:
if (!m_Effects[m_SelectedIdx].Identifier.GetEffectId().empty())
if (!m_Effects[m_SelectedIdx].Id.Id().empty())
m_DispatchEffect = true;

break;
Expand Down
6 changes: 3 additions & 3 deletions ChaosMod/Components/DebugMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class DebugMenu : public Component
{
struct DebugEffect
{
EffectIdentifier Identifier;
EffectIdentifier Id;
std::string EffectName;

DebugEffect(const EffectIdentifier &effectIdentifier, const std::string &effectName)
: Identifier(effectIdentifier), EffectName(effectName)
DebugEffect(const EffectIdentifier &effectId, const std::string &effectName)
: Id(effectId), EffectName(effectName)
{
}
};
Expand Down
27 changes: 12 additions & 15 deletions ChaosMod/Components/DebugSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include "DebugSocket.h"

#include "Components/EffectDispatcher.h"
#include "Effects/EnabledEffectsMap.h"
#include "Util/OptionsFile.h"
#include "Effects/EnabledEffects.h"

#include <json.hpp>

Expand Down Expand Up @@ -35,7 +34,7 @@ static void OnFetchEffects(DebugSocket *debugSocket, std::shared_ptr<ix::Connect
continue;

json effectInfoJson;
effectInfoJson["id"] = effectId.GetEffectId();
effectInfoJson["id"] = effectId;
effectInfoJson["name"] = effectData.Name;

effectsJson["effects"].push_back(effectInfoJson);
Expand Down Expand Up @@ -192,29 +191,29 @@ static void OnMessage(DebugSocket *debugSocket, std::shared_ptr<ix::ConnectionSt
#undef HANDLER
}

static bool EventOnPreDispatchEffect(DebugSocket *debugSocket, const EffectIdentifier &identifier)
static bool EventOnPreDispatchEffect(DebugSocket *debugSocket, const EffectIdentifier &ide)
{
debugSocket->m_EffectTraceStats.erase(identifier.GetEffectId());
debugSocket->m_EffectTraceStats.erase(ide);
return true;
}

static void EventOnPreRunEffect(DebugSocket *debugSocket, const EffectIdentifier &identifier)
static void EventOnPreRunEffect(DebugSocket *debugSocket, const EffectIdentifier &id)
{
if (debugSocket->m_IsProfiling)
{
LARGE_INTEGER ticks;
QueryPerformanceCounter(&ticks);

debugSocket->m_EffectTraceStats[identifier.GetEffectId()].EntryTimestamp = ticks.QuadPart;
debugSocket->m_EffectTraceStats[id].EntryTimestamp = ticks.QuadPart;
}
}

static void EventOnPostRunEffect(DebugSocket *debugSocket, const EffectIdentifier &identifier)
static void EventOnPostRunEffect(DebugSocket *debugSocket, const EffectIdentifier &id)
{
if (!debugSocket->m_IsProfiling)
return;

const auto &effectId = identifier.GetEffectId();
const auto &effectId = id;
if (!debugSocket->m_EffectTraceStats.contains(effectId))
return;

Expand Down Expand Up @@ -259,16 +258,14 @@ DebugSocket::DebugSocket()
if (ComponentExists<EffectDispatcher>())
{
m_OnPreDispatchEffectListener.Register(GetComponent<EffectDispatcher>()->OnPreDispatchEffect,
[&](const EffectIdentifier &identifier)
{ return EventOnPreDispatchEffect(this, identifier); });
[&](const EffectIdentifier &id)
{ return EventOnPreDispatchEffect(this, id); });

m_OnPreRunEffectListener.Register(GetComponent<EffectDispatcher>()->OnPreRunEffect,
[&](const EffectIdentifier &identifier)
{ EventOnPreRunEffect(this, identifier); });
[&](const EffectIdentifier &id) { EventOnPreRunEffect(this, id); });

m_OnPostRunEffectListener.Register(GetComponent<EffectDispatcher>()->OnPostRunEffect,
[&](const EffectIdentifier &identifier)
{ EventOnPostRunEffect(this, identifier); });
[&](const EffectIdentifier &id) { EventOnPostRunEffect(this, id); });
}
}

Expand Down
Loading

0 comments on commit 81092df

Please sign in to comment.