summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-07-13 11:38:26 -0400
committerLioncash <mathew1800@gmail.com>2018-07-13 13:20:35 -0400
commitef1240b0c73a158c1d80fce5ab9724d0a793a491 (patch)
treebb8c64da1cf993daea91f6db04017791b40b0987 /Source/Core/InputCommon/ControllerEmu/ControlGroup
parentd05f490caaacf66008bd1409e61de37b1ac6c32b (diff)
ControlGroup/Cursor: Return state data by value
Makes it less error-prone to get state data from cursors (no need to pass any pointers to locals), and also allows direct assignment, letting the retrieved data be const.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp38
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h13
2 files changed, 29 insertions, 22 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
index 154b0ca862..b0633ec6a5 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.cpp
@@ -39,18 +39,18 @@ Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GroupType::Cursor
boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Auto-Hide"), false));
}
-void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState* const z,
- const bool adjusted)
+Cursor::StateData Cursor::GetState(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);
+ if (zz > m_state.z)
+ m_state.z = std::min(m_state.z + 0.1, zz);
+ else if (zz < m_state.z)
+ m_state.z = std::max(m_state.z - 0.1, zz);
- *z = m_z;
+ StateData result;
+ result.z = m_state.z;
if (m_autohide_timer > -1)
{
@@ -69,11 +69,11 @@ void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState
}
// hide
- bool autohide = boolean_settings[1]->GetValue() && m_autohide_timer < 0;
+ const bool autohide = boolean_settings[1]->GetValue() && m_autohide_timer < 0;
if (controls[6]->control_ref->State() > 0.5 || autohide)
{
- *x = 10000;
- *y = 0;
+ result.x = 10000;
+ result.y = 0;
}
else
{
@@ -90,28 +90,30 @@ void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState
{
// 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);
+ m_state.x = MathUtil::Clamp(m_state.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);
+ m_state.y = MathUtil::Clamp(m_state.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;
+ m_state.x = 0.0;
+ m_state.y = 0.0;
}
}
else
{
- m_x = xx;
- m_y = yy;
+ m_state.x = xx;
+ m_state.y = yy;
}
- *x = m_x;
- *y = m_y;
+ result.x = m_state.x;
+ result.y = m_state.y;
}
m_prev_xx = xx;
m_prev_yy = yy;
+
+ return result;
}
} // namespace ControllerEmu
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h
index 5e740334cf..b24cfdcba3 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Cursor.h
@@ -13,9 +13,16 @@ namespace ControllerEmu
class Cursor : public ControlGroup
{
public:
+ struct StateData
+ {
+ ControlState x{};
+ ControlState y{};
+ ControlState z{};
+ };
+
explicit Cursor(const std::string& name);
- void GetState(ControlState* x, ControlState* y, ControlState* z, bool adjusted = false);
+ StateData GetState(bool adjusted = false);
private:
// This is used to reduce the cursor speed for relative input
@@ -25,9 +32,7 @@ private:
// Sets the length for the auto-hide timer
static constexpr int TIMER_VALUE = 500;
- ControlState m_x = 0.0;
- ControlState m_y = 0.0;
- ControlState m_z = 0.0;
+ StateData m_state;
int m_autohide_timer = TIMER_VALUE;
ControlState m_prev_xx;