summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2017-02-08 22:15:43 -0500
committerLioncash <mathew1800@gmail.com>2017-02-09 18:18:52 -0500
commit6a75ea5653ec596b1a08e985e98fca0b05ccd6f7 (patch)
treed76f549ca6c7591fa2b11a86f63e0351b418f4c8 /Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
parent1385a012d94bbec76bc8b2922467c715b63f0158 (diff)
ControllerEmu: Separate ControlGroup from ControllerEmu
ControllerEmu, the class, is essentially acting like a namespace for ControlGroup. This makes it impossible to forward declare any of the internals. It also globs a bunch of classes together which is kind of a pain to manage. This splits ControlGroup and the classes it contains into their own source files and situates them all within a namespace, which gets them out of global scope. Since this allows forward declarations for the once-internal classes, it now requires significantly less files to be rebuilt if anything is changed in the ControllerEmu portion of code. It does not split out the settings classes yet, however, as it would be preferable to make a settings base class that all settings derive from, but this would be a functional change -- this commit only intends to move around existing code. Extracting the settings class will be done in another commit.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
new file mode 100644
index 0000000000..1d0c55a8d5
--- /dev/null
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
@@ -0,0 +1,98 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h"
+
+#include <algorithm>
+#include <cmath>
+#include <memory>
+#include <string>
+
+#include "Common/Common.h"
+#include "Common/MathUtil.h"
+
+#include "InputCommon/ControlReference/ControlReference.h"
+#include "InputCommon/ControllerEmu/Control/Control.h"
+#include "InputCommon/ControllerEmu/Control/Input.h"
+#include "InputCommon/ControllerEmu/ControllerEmu.h"
+
+namespace ControllerEmu
+{
+Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_CURSOR)
+{
+ for (auto& named_direction : named_directions)
+ controls.emplace_back(std::make_unique<Input>(named_direction));
+
+ controls.emplace_back(std::make_unique<Input>("Forward"));
+ controls.emplace_back(std::make_unique<Input>("Backward"));
+ controls.emplace_back(std::make_unique<Input>(_trans("Hide")));
+ controls.emplace_back(std::make_unique<Input>("Recenter"));
+
+ numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5));
+ numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5));
+ numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Height"), 0.5));
+ numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 20));
+ boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Relative Input"), false));
+}
+
+void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState* const z,
+ const bool adjusted)
+{
+ const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
+
+ // silly being here
+ if (zz > m_z)
+ m_z = std::min(m_z + 0.1, zz);
+ else if (zz < m_z)
+ m_z = std::max(m_z - 0.1, zz);
+
+ *z = m_z;
+
+ // hide
+ if (controls[6]->control_ref->State() > 0.5)
+ {
+ *x = 10000;
+ *y = 0;
+ }
+ else
+ {
+ ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
+ ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
+
+ // adjust cursor according to settings
+ if (adjusted)
+ {
+ xx *= (numeric_settings[1]->GetValue() * 2);
+ yy *= (numeric_settings[2]->GetValue() * 2);
+ yy += (numeric_settings[0]->GetValue() - 0.5);
+ }
+
+ // relative input
+ if (boolean_settings[0]->GetValue())
+ {
+ const ControlState deadzone = numeric_settings[3]->GetValue();
+ // deadzone to avoid the cursor slowly drifting
+ if (std::abs(xx) > deadzone)
+ m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
+ if (std::abs(yy) > deadzone)
+ m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
+
+ // recenter
+ if (controls[7]->control_ref->State() > 0.5)
+ {
+ m_x = 0.0;
+ m_y = 0.0;
+ }
+ }
+ else
+ {
+ m_x = xx;
+ m_y = yy;
+ }
+
+ *x = m_x;
+ *y = m_y;
+ }
+}
+} // namespace ControllerEmu