From 0d11081a3bb00d749cc73fa4a611f87513077a36 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 11 Jul 2014 08:11:33 -0400 Subject: [PATCH] ControllerEmu: Clean up the code that applies the modifier This makes it more clear and pretty much the analog stick code bog standard. --- Source/Core/InputCommon/ControllerEmu.h | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Source/Core/InputCommon/ControllerEmu.h b/Source/Core/InputCommon/ControllerEmu.h index 4881832243..4f883c9cb8 100644 --- a/Source/Core/InputCommon/ControllerEmu.h +++ b/Source/Core/InputCommon/ControllerEmu.h @@ -124,8 +124,6 @@ public: template void GetState(C* const x, C* const y, const unsigned int base, const unsigned int range) { - // this is all a mess - ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State(); ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State(); @@ -133,13 +131,6 @@ public: ControlState deadzone = settings[SETTING_DEADZONE]->value; ControlState m = controls[4]->control_ref->State(); - // modifier code - if (m) - { - yy = (fabsf(yy)>deadzone) * sign(yy) * (m + deadzone/2); - xx = (fabsf(xx)>deadzone) * sign(xx) * (m + deadzone/2); - } - ControlState ang = atan2(yy, xx); ControlState ang_sin = sin(ang); ControlState ang_cos = cos(ang); @@ -153,6 +144,11 @@ public: // radius dist *= radius; + // The modifier halves the distance by 50%, which is useful + // for keyboard controls. + if (m) + dist *= 0.5; + yy = std::max(-1.0f, std::min(1.0f, ang_sin * dist)); xx = std::max(-1.0f, std::min(1.0f, ang_cos * dist)); @@ -281,13 +277,6 @@ public: auto const angle = settings[2]->value / 1.8f; ControlState m = controls[4]->control_ref->State(); - // modifier code - if (m) - { - yy = (fabsf(yy)>deadzone) * sign(yy) * (m + deadzone/2); - xx = (fabsf(xx)>deadzone) * sign(xx) * (m + deadzone/2); - } - // deadzone / circle stick code // this section might be all wrong, but its working good enough, I think @@ -312,6 +301,9 @@ public: ControlState amt = dist / stick_full; dist += (square_full - 1) * amt * circle; + if (m) + dist *= 0.5; + yy = std::max(-1.0f, std::min(1.0f, ang_sin * dist)); xx = std::max(-1.0f, std::min(1.0f, ang_cos * dist));