diff options
| author | Lioncash <mathew1800@gmail.com> | 2018-07-13 11:19:08 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2018-07-13 13:20:31 -0400 |
| commit | d05f490caaacf66008bd1409e61de37b1ac6c32b (patch) | |
| tree | b8affeb37e6310aff7eb0b2fb6789800f255d443 /Source/Core/InputCommon/ControllerEmu/ControlGroup | |
| parent | cc6526f5535e253f72589d1a63968a4696d47892 (diff) | |
ControlGroup/AnalogStick: Return state data by value
Makes it less error-prone to get state data from analog sticks (no need
to pass any 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/AnalogStick.cpp | 27 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h | 8 |
2 files changed, 20 insertions, 15 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index 3317da427c..c38e5f1d3a 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -36,20 +36,20 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50)); } -void AnalogStick::GetState(ControlState* const x, ControlState* const y) +AnalogStick::StateData AnalogStick::GetState() { - ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); - ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); + ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); + ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); - ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue(); - ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue(); - ControlState m = controls[4]->control_ref->State(); + const ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue(); + const ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue(); + const ControlState m = controls[4]->control_ref->State(); - ControlState ang = atan2(yy, xx); - ControlState ang_sin = sin(ang); - ControlState ang_cos = cos(ang); + const ControlState ang = atan2(y, x); + const ControlState ang_sin = sin(ang); + const ControlState ang_cos = cos(ang); - ControlState dist = sqrt(xx * xx + yy * yy); + ControlState dist = sqrt(x * x + y * y); // dead zone code dist = std::max(0.0, dist - deadzone); @@ -63,10 +63,9 @@ void AnalogStick::GetState(ControlState* const x, ControlState* const y) if (m) dist *= 0.5; - yy = std::max(-1.0, std::min(1.0, ang_sin * dist)); - xx = std::max(-1.0, std::min(1.0, ang_cos * dist)); + y = std::max(-1.0, std::min(1.0, ang_sin * dist)); + x = std::max(-1.0, std::min(1.0, ang_cos * dist)); - *y = yy; - *x = xx; + return {x, y}; } } // namespace ControllerEmu diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h index a598202ba7..d8d8e4ddea 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.h @@ -18,10 +18,16 @@ public: SETTING_DEADZONE, }; + struct StateData + { + ControlState x{}; + ControlState y{}; + }; + // The GameCube controller and Wiimote attachments have a different default radius AnalogStick(const char* name, ControlState default_radius); AnalogStick(const char* name, const char* ui_name, ControlState default_radius); - void GetState(ControlState* x, ControlState* y); + StateData GetState(); }; } // namespace ControllerEmu |
