ControllerEmu: Clean up the code that applies the modifier
This makes it more clear and pretty much the analog stick code bog standard.
This commit is contained in:
parent
c29d5ff989
commit
0d11081a3b
|
@ -124,8 +124,6 @@ public:
|
|||
template <typename C>
|
||||
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));
|
||||
|
||||
|
|
Loading…
Reference in New Issue