JonnyHaystack / HayBox

Modular cross-platform firmware for digital or mixed analog/digital game controllers
GNU General Public License v3.0
178 stars 208 forks source link

Replace output assignments with normalized coordinate functions #15

Closed ribbanya closed 2 years ago

ribbanya commented 2 years ago

The primary goal of this PR is to employ normalized coordinates from 0 to 10,000 per quadrant, equivalent to the 0 to 1 coordinate system familiar to the Melee community. I also cleaned up the comments, removing any reference to 0..255 coordinates and updating the angles to be uniformly accurate to 5 decimal places.

In doing so, I chose to refactor the &input and &output parameters of ControllerMode to protected pointers, which are updated to point to the CommunicationBackend's structs, once per update loop.

I also refactored ANALOG_STICK_MIN and ANALOG_STICK_MAX to instead use a single analog_stick_length property of ControllerMode, which is set in the constructor. This was necessary to implement the normalized coordinate systems across different game modes.

ANALOG_STICK_NEUTRAL is still a #define but was moved to state.hpp and is used in place of 128 throughout the codebase, where appropriate.

These changes were made as part of a refactoring pass that I'm doing for my own forks. I'm just submitting this as a PR in case it's preferred here as well.


I have moved these normalized coordinate functions to a PlatformFighter base class, which all platform fighter modes (Melee, PM, Ultimate, and Rivals) now inherit from.

ribbanya commented 2 years ago

Came up with (I think) a better way of doing this. Will resubmit as a new PR.