summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2019-01-01 08:32:39 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2019-02-02 19:40:31 -0600
commit0d1fbe7bbca8e42449ee37600519509cb47516b9 (patch)
tree28c80ff2fa153a50e9e7ed9bee91ed85a9692289 /Source/Core/InputCommon/ControllerEmu
parentb1f350ab1c225996bf5eee169acd1f53d8936234 (diff)
WiimoteEmu: Major renaming and cleanup.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp33
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h37
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp21
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h2
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp16
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h31
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h3
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp14
8 files changed, 89 insertions, 68 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
new file mode 100644
index 0000000000..e104918fe2
--- /dev/null
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.cpp
@@ -0,0 +1,33 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
+
+namespace ControllerEmu
+{
+Attachments::Attachments(const std::string& name_) : ControlGroup(name_, GroupType::Attachments)
+{
+}
+
+void Attachments::AddAttachment(std::unique_ptr<EmulatedController> att)
+{
+ m_attachments.emplace_back(std::move(att));
+}
+
+u32 Attachments::GetSelectedAttachment() const
+{
+ return m_selected_attachment;
+}
+
+void Attachments::SetSelectedAttachment(u32 val)
+{
+ m_selected_attachment = val;
+}
+
+const std::vector<std::unique_ptr<EmulatedController>>& Attachments::GetAttachmentList() const
+{
+ return m_attachments;
+}
+
+} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h
new file mode 100644
index 0000000000..746bc523ab
--- /dev/null
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Attachments.h
@@ -0,0 +1,37 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <atomic>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "Common/CommonTypes.h"
+#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
+#include "InputCommon/ControllerEmu/ControllerEmu.h"
+
+namespace ControllerEmu
+{
+// A container of the selected and available attachments
+// for configuration saving/loading purposes
+class Attachments : public ControlGroup
+{
+public:
+ explicit Attachments(const std::string& name);
+
+ void AddAttachment(std::unique_ptr<EmulatedController> att);
+
+ u32 GetSelectedAttachment() const;
+ void SetSelectedAttachment(u32 val);
+
+ const std::vector<std::unique_ptr<EmulatedController>>& GetAttachmentList() const;
+
+private:
+ std::vector<std::unique_ptr<EmulatedController>> m_attachments;
+
+ std::atomic<u32> m_selected_attachment;
+};
+} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
index 1cc2ac1865..6e8e5cfb70 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.cpp
@@ -9,7 +9,7 @@
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
-#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
+#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/BooleanSetting.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
@@ -67,22 +67,22 @@ void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
}
// extensions
- if (type == GroupType::Extension)
+ if (type == GroupType::Attachments)
{
- Extension* const ext = (Extension*)this;
+ auto* const ext = static_cast<Attachments*>(this);
- ext->switch_extension = 0;
+ ext->SetSelectedAttachment(0);
u32 n = 0;
std::string extname;
sec->Get(base + name, &extname, "");
- for (auto& ai : ext->attachments)
+ for (auto& ai : ext->GetAttachmentList())
{
ai->SetDefaultDevice(defdev);
ai->LoadConfig(sec, base + ai->GetName() + "/");
if (ai->GetName() == extname)
- ext->switch_extension = n;
+ ext->SetSelectedAttachment(n);
n++;
}
@@ -120,12 +120,13 @@ void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
}
// extensions
- if (type == GroupType::Extension)
+ if (type == GroupType::Attachments)
{
- Extension* const ext = (Extension*)this;
- sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None");
+ auto* const ext = static_cast<Attachments*>(this);
+ sec->Set(base + name, ext->GetAttachmentList()[ext->GetSelectedAttachment()]->GetName(),
+ "None");
- for (auto& ai : ext->attachments)
+ for (auto& ai : ext->GetAttachmentList())
ai->SaveConfig(sec, base + ai->GetName() + "/");
}
}
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
index b771adcdb9..8e9fa3f24a 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/ControlGroup.h
@@ -24,7 +24,7 @@ enum class GroupType
MixedTriggers,
Buttons,
Force,
- Extension,
+ Attachments,
Tilt,
Cursor,
Triggers,
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp
deleted file mode 100644
index eb9dbc8a99..0000000000
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2017 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
-
-#include <string>
-
-#include "InputCommon/ControllerEmu/ControllerEmu.h"
-
-namespace ControllerEmu
-{
-Extension::Extension(const std::string& name_) : ControlGroup(name_, GroupType::Extension)
-{
-}
-} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h
deleted file mode 100644
index 366e94f248..0000000000
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Extension.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "Common/CommonTypes.h"
-#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
-
-namespace ControllerEmu
-{
-class EmulatedController;
-
-class Extension : public ControlGroup
-{
-public:
- explicit Extension(const std::string& name);
-
- void GetState(u8* data);
- bool IsButtonPressed() const;
-
- std::vector<std::unique_ptr<EmulatedController>> attachments;
-
- int switch_extension = 0;
- int active_extension = 0;
-};
-} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h
index 03dc07ecbd..7b55d3535f 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.h
@@ -19,8 +19,5 @@ public:
explicit Force(const std::string& name);
StateData GetState();
-
-private:
- StateData m_swing{};
};
} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp
index 98b9e5828b..e6623ea754 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControllerEmu.cpp
@@ -12,8 +12,8 @@
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
+#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
-#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace ControllerEmu
@@ -41,10 +41,10 @@ void EmulatedController::UpdateReferences(const ControllerInterface& devi)
for (auto& control : ctrlGroup->controls)
control->control_ref.get()->UpdateReference(devi, GetDefaultDevice());
- // extension
- if (ctrlGroup->type == GroupType::Extension)
+ // Attachments:
+ if (ctrlGroup->type == GroupType::Attachments)
{
- for (auto& attachment : ((Extension*)ctrlGroup.get())->attachments)
+ for (auto& attachment : static_cast<Attachments*>(ctrlGroup.get())->GetAttachmentList())
attachment->UpdateReferences(devi);
}
}
@@ -73,10 +73,10 @@ void EmulatedController::SetDefaultDevice(ciface::Core::DeviceQualifier devq)
for (auto& ctrlGroup : groups)
{
- // extension
- if (ctrlGroup->type == GroupType::Extension)
+ // Attachments:
+ if (ctrlGroup->type == GroupType::Attachments)
{
- for (auto& ai : ((Extension*)ctrlGroup.get())->attachments)
+ for (auto& ai : static_cast<Attachments*>(ctrlGroup.get())->GetAttachmentList())
{
ai->SetDefaultDevice(m_default_device);
}