Overview
ControllerMode is an abstract base class that extends InputMode to provide controller-specific functionality. It handles the conversion of physical button inputs into analog stick positions and digital button outputs for game controllers.
Class Definition
Inheritance
Inherits from
InputMode, which provides configuration management, SOCD handling, and button remapping functionality.Constructor
ControllerMode()
- Calls the parent
InputModeconstructor - Calls
ResetDirections()to initialize stick direction state
Public Methods
UpdateOutputs
Reference to the current input state containing all physical button presses
Reference to the output state to be modified with controller outputs
- Creates a copy of inputs for remapping
- Applies button remapping via
HandleRemap() - Applies SOCD (Simultaneous Opposite Cardinal Direction) resolution via
HandleSocd() - Calls
UpdateDigitalOutputs()to set button states - Calls
UpdateAnalogOutputs()to set analog stick positions
ResetDirections
directions struct to neutral state.
Behavior:
- Sets all directional flags to
false - Sets all coordinate values (
x,y,cx,cy) to0
UpdateDirections
Left stick left direction active
Left stick right direction active
Left stick down direction active
Left stick up direction active
Right stick (C-stick) left direction active
Right stick (C-stick) right direction active
Right stick (C-stick) down direction active
Right stick (C-stick) up direction active
Minimum analog value (typically 48 for GameCube)
Neutral/center analog value (typically 128)
Maximum analog value (typically 208 for GameCube)
Output state to update with calculated stick positions
- Resets directions to neutral state
- Sets stick outputs to neutral position
- Calculates coordinate flags (
horizontal,vertical,diagonal) - Sets coordinate values (
x,y,cx,cy) to -1, 0, or 1 - Updates
outputs.leftStickX,outputs.leftStickY,outputs.rightStickX,outputs.rightStickY
This method is virtual and can be overridden by derived classes to implement custom directional behavior.
Protected Members
directions
True if left stick has horizontal input
True if left stick has vertical input
True if left stick has both horizontal and vertical input
Left stick horizontal direction: -1 (left), 0 (neutral), 1 (right)
Left stick vertical direction: -1 (down), 0 (neutral), 1 (up)
Right stick horizontal direction: -1 (left), 0 (neutral), 1 (right)
Right stick vertical direction: -1 (down), 0 (neutral), 1 (up)
Pure Virtual Methods
These methods must be implemented by any concrete class derived fromControllerMode.
UpdateDigitalOutputs
Remapped and SOCD-resolved input state
Output state to update with button presses
UpdateAnalogOutputs
Remapped and SOCD-resolved input state
Output state to update with analog values
Usage Example
Here’s how theMelee20Button mode implements ControllerMode:
Digital Output Implementation
Analog Output Implementation
Best Practices
The
directions struct provides a convenient way to check for diagonal inputs and apply different coordinate values based on the direction quadrant.Related Types
- InputState: Defined in
include/core/state.hpp- contains all button states - OutputState: Defined in
include/core/state.hpp- contains controller output structure - InputMode: Parent class providing config, SOCD, and remapping functionality
See Also
- KeyboardMode - For implementing keyboard input modes
- InputSource - For reading physical inputs
- CommunicationBackend - For sending outputs to the host device
