summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-01-20 23:19:56 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2025-03-15 14:30:43 -0500
commitddb82a5e8ca84df1b95942c8b3a1fa6c9071010b (patch)
tree996de0475d813c192e64a0f3d6004181cdf54b8e /Source/Core/InputCommon/ControllerEmu/ControlGroup
parent225039f742d14eacd704490bb1a66dc119a91320 (diff)
InputCommon/ControllerEmu: Break out functionality of EmulatedController
to eliminate redundant unused members in Wii Remote extension objects.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp61
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h22
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp60
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h9
4 files changed, 87 insertions, 65 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
index b4bb1699c0..45ce337d6c 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
@@ -5,11 +5,16 @@
namespace ControllerEmu
{
+
+void AttachedController::LoadDefaults()
+{
+}
+
Attachments::Attachments(const std::string& name_) : ControlGroup(name_, GroupType::Attachments)
{
}
-void Attachments::AddAttachment(std::unique_ptr<EmulatedController> att)
+void Attachments::AddAttachment(std::unique_ptr<AttachedController> att)
{
m_attachments.emplace_back(std::move(att));
}
@@ -40,9 +45,61 @@ SubscribableSettingValue<int>& Attachments::GetAttachmentSetting()
return m_selection_value;
}
-const std::vector<std::unique_ptr<EmulatedController>>& Attachments::GetAttachmentList() const
+const std::vector<std::unique_ptr<AttachedController>>& Attachments::GetAttachmentList() const
{
return m_attachments;
}
+void Attachments::LoadConfig(Common::IniFile::Section* sec, const std::string& base)
+{
+ ControlGroup::LoadConfig(sec, base);
+
+ SetSelectedAttachment(0);
+
+ std::string attachment_text;
+ sec->Get(base + name, &attachment_text, "");
+
+ // First assume attachment string is a valid expression.
+ // If it instead matches one of the names of our attachments it is overridden below.
+ GetSelectionSetting().GetInputReference().SetExpression(attachment_text);
+
+ u32 n = 0;
+ for (auto& ai : GetAttachmentList())
+ {
+ ai->LoadGroupsConfig(sec, base + ai->GetName() + "/");
+
+ if (ai->GetName() == attachment_text)
+ SetSelectedAttachment(n);
+
+ ++n;
+ }
+}
+
+void Attachments::SaveConfig(Common::IniFile::Section* sec, const std::string& base)
+{
+ if (GetSelectionSetting().IsSimpleValue())
+ {
+ sec->Set(base + name, GetAttachmentList()[GetSelectedAttachment()]->GetName(), "None");
+ }
+ else
+ {
+ std::string expression = GetSelectionSetting().GetInputReference().GetExpression();
+ ReplaceBreaksWithSpaces(expression);
+ sec->Set(base + name, expression, "None");
+ }
+
+ for (auto& ai : GetAttachmentList())
+ ai->SaveGroupsConfig(sec, base + ai->GetName() + "/");
+}
+
+void Attachments::UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env)
+{
+ ControlGroup::UpdateReferences(env);
+
+ GetSelectionSetting().GetInputReference().UpdateReference(env);
+
+ for (auto& attachment : GetAttachmentList())
+ attachment->UpdateGroupsReferences(env);
+}
+
} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h
index 887231196b..1573b01bca 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h
@@ -3,19 +3,23 @@
#pragma once
-#include <atomic>
#include <memory>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
-#include "Core/HW/WiimoteEmu/ExtensionPort.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
namespace ControllerEmu
{
+class AttachedController : public ControlGroupContainer
+{
+public:
+ virtual void LoadDefaults();
+};
+
// A container of the selected and available attachments
// for configuration saving/loading purposes
class Attachments : public ControlGroup
@@ -23,7 +27,7 @@ class Attachments : public ControlGroup
public:
explicit Attachments(const std::string& name);
- void AddAttachment(std::unique_ptr<EmulatedController> att);
+ void AddAttachment(std::unique_ptr<AttachedController> att);
u32 GetSelectedAttachment() const;
void SetSelectedAttachment(u32 val);
@@ -31,16 +35,20 @@ public:
NumericSetting<int>& GetSelectionSetting();
SubscribableSettingValue<int>& GetAttachmentSetting();
- const std::vector<std::unique_ptr<EmulatedController>>& GetAttachmentList() const;
+ const std::vector<std::unique_ptr<AttachedController>>& GetAttachmentList() const;
+
+ void LoadConfig(Common::IniFile::Section* sec, const std::string& base) override;
+ void SaveConfig(Common::IniFile::Section* sec, const std::string& base) override;
+
+ void UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env) override;
private:
SubscribableSettingValue<int> m_selection_value;
// This is here and not added to the list of numeric_settings because it's serialized differently,
// by string (to be independent from the enum), and visualized differently in the UI.
// For the rest, it's treated similarly to other numeric_settings in the group.
- NumericSetting<int> m_selection_setting = {
- &m_selection_value, {""}, 0, 0, WiimoteEmu::ExtensionNumber::MAX - 1};
+ NumericSetting<int> m_selection_setting = {&m_selection_value, {""}, 0, 0, 0};
- std::vector<std::unique_ptr<EmulatedController>> m_attachments;
+ std::vector<std::unique_ptr<AttachedController>> m_attachments;
};
} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
index 2896acd070..93367649f9 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
@@ -3,13 +3,11 @@
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
-#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h"
-#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
@@ -50,8 +48,7 @@ void ControlGroup::AddDeadzoneSetting(SettingValue<double>* value, double maximu
ControlGroup::~ControlGroup() = default;
-void ControlGroup::LoadConfig(Common::IniFile::Section* sec, const std::string& defdev,
- const std::string& base)
+void ControlGroup::LoadConfig(Common::IniFile::Section* sec, const std::string& base)
{
const std::string group(base + name + "/");
@@ -75,36 +72,9 @@ void ControlGroup::LoadConfig(Common::IniFile::Section* sec, const std::string&
sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0);
c->control_ref->range /= 100;
}
-
- // extensions
- if (type == GroupType::Attachments)
- {
- auto* const ext = static_cast<Attachments*>(this);
-
- ext->SetSelectedAttachment(0);
- u32 n = 0;
- std::string attachment_text;
- sec->Get(base + name, &attachment_text, "");
-
- // First assume attachment string is a valid expression.
- // If it instead matches one of the names of our attachments it is overridden below.
- ext->GetSelectionSetting().GetInputReference().SetExpression(attachment_text);
-
- for (auto& ai : ext->GetAttachmentList())
- {
- ai->SetDefaultDevice(defdev);
- ai->LoadConfig(sec, base + ai->GetName() + "/");
-
- if (ai->GetName() == attachment_text)
- ext->SetSelectedAttachment(n);
-
- n++;
- }
- }
}
-void ControlGroup::SaveConfig(Common::IniFile::Section* sec, const std::string& defdev,
- const std::string& base)
+void ControlGroup::SaveConfig(Common::IniFile::Section* sec, const std::string& base)
{
const std::string group(base + name + "/");
@@ -125,27 +95,15 @@ void ControlGroup::SaveConfig(Common::IniFile::Section* sec, const std::string&
// range
sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0);
}
+}
- // extensions
- if (type == GroupType::Attachments)
- {
- auto* const ext = static_cast<Attachments*>(this);
-
- if (ext->GetSelectionSetting().IsSimpleValue())
- {
- sec->Set(base + name, ext->GetAttachmentList()[ext->GetSelectedAttachment()]->GetName(),
- "None");
- }
- else
- {
- std::string expression = ext->GetSelectionSetting().GetInputReference().GetExpression();
- ReplaceBreaksWithSpaces(expression);
- sec->Set(base + name, expression, "None");
- }
+void ControlGroup::UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env)
+{
+ for (auto& control : controls)
+ control->control_ref->UpdateReference(env);
- for (auto& ai : ext->GetAttachmentList())
- ai->SaveConfig(sec, base + ai->GetName() + "/");
- }
+ for (auto& setting : numeric_settings)
+ setting->GetInputReference().UpdateReference(env);
}
void ControlGroup::SetControlExpression(int index, const std::string& expression)
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
index bb426e9297..7928fb61a9 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
@@ -13,7 +13,6 @@
#include <type_traits>
#include <vector>
-#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerInterface/CoreDevice.h"
@@ -69,10 +68,10 @@ public:
DefaultValue default_value = DefaultValue::AlwaysEnabled);
virtual ~ControlGroup();
- virtual void LoadConfig(Common::IniFile::Section* sec, const std::string& defdev = "",
- const std::string& base = "");
- virtual void SaveConfig(Common::IniFile::Section* sec, const std::string& defdev = "",
- const std::string& base = "");
+ virtual void LoadConfig(Common::IniFile::Section* sec, const std::string& base);
+ virtual void SaveConfig(Common::IniFile::Section* sec, const std::string& base);
+
+ virtual void UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env);
void SetControlExpression(int index, const std::string& expression);