Rosalie241 / RMG

Rosalie's Mupen GUI
GNU General Public License v3.0
573 stars 50 forks source link

RMG-Input: improve control stick functioning #142

Closed kev4cards closed 10 months ago

kev4cards commented 11 months ago

The current code uses maxAxis (85 position count) as the radius for the circular outer deadzone. Unfortunately, maxDiagonal (69 position count) reaches outside of that outer deadzone. The only reason maxDiagonal can be reached in the current code is because simulate_octagon will jump to maxDiagonal once the edge of the outer deadzone is reached. Input values between maxAxis sqrt(2) / 2 (unit circle at 45 degrees; 60 position count) and maxDiagonal, non-inclusive, simply jump to maxDiagonal. This PR addresses this issue by calculating a new circular outer deadzone called maxRadiusOuterDeadzone that actually encompasses the whole octagon and does not clip off the diagonals. maxOuterRadiusDeadzone is defined as a function of maxDiagonal, maxAxis, axisRange, and (inner) deadzone and is derived from solving for maxOuterRadiusDeadzone at point (maxOuterRadiusDeadzone sqrt(2) / 2, maxDiagonal) in the linear scaling equation.

Moreover, with this new approach, maxAxis is no longer at the edge of the outer deadzone. Therefore, values greater than maxAxis can occur. To prevent this, a clamp is added.

Finally, the diagonals were reaching just one shy of maxDiagonal. This was due to floating point error and lack of clamping to account for -32768. Therefore, a clamp was introduced to keep inputX and inputY from exceeding +/-1 before being passed to simulate_octagon, and an epsilon was added to counteract the floating point error just before the truncate-inducing cast to an 8-bit signed integer.

kev4cards commented 10 months ago

As already discussed on Discord, this PR has been transformed and is now replaced by PR #164, which addresses the above requested changes.