libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::ControllerStick Class Reference

Aggregates axis-direction mappings and applies sensitivity, dead-zone, and notch-snap to a stick. More...

#include <ControllerStick.h>

Public Member Functions

void SetControlDeck (std::shared_ptr< ControlDeck > controlDeck)
 Injects the owning ControlDeck.
 
 ControllerStick (uint8_t portIndex, StickIndex stickIndex, std::shared_ptr< ConsoleVariable > consoleVariable=nullptr, std::shared_ptr< ControlDeck > controlDeck=nullptr, std::shared_ptr< Window > window=nullptr)
 Constructs a ControllerStick for a given port and stick index.
 
 ~ControllerStick ()
 
void ReloadAllMappingsFromConfig ()
 Clears all in-memory mappings and reloads them from Config.
 
void AddDefaultMappings (PhysicalDeviceType physicalDeviceType)
 Applies the default axis-direction mappings for the given device type.
 
void ClearAllMappings ()
 Removes all axis-direction mappings for all directions.
 
void ClearAllMappingsForDeviceType (PhysicalDeviceType physicalDeviceType)
 Removes all axis-direction mappings that target the given device type.
 
void UpdatePad (int8_t &x, int8_t &y)
 Evaluates all axis mappings and writes the processed stick values to x and y.
 
std::shared_ptr< ControllerAxisDirectionMappingGetAxisDirectionMappingById (Direction direction, std::string id)
 Returns the mapping for the given direction and ID, or nullptr if not found.
 
std::unordered_map< Direction, std::unordered_map< std::string, std::shared_ptr< ControllerAxisDirectionMapping > > > GetAllAxisDirectionMappings ()
 Returns a copy of the full direction → (id → mapping) map.
 
std::unordered_map< std::string, std::shared_ptr< ControllerAxisDirectionMapping > > GetAllAxisDirectionMappingByDirection (Direction direction)
 Returns the id → mapping map for a single direction.
 
void AddAxisDirectionMapping (Direction direction, std::shared_ptr< ControllerAxisDirectionMapping > mapping)
 Adds a mapping for the given direction.
 
void ClearAxisDirectionMappingId (Direction direction, std::string id)
 Removes the mapping ID from Config without destroying the in-memory object.
 
void ClearAxisDirectionMapping (Direction direction, std::string id)
 Removes the mapping by ID from both in-memory and Config.
 
void ClearAxisDirectionMapping (Direction direction, std::shared_ptr< ControllerAxisDirectionMapping > mapping)
 Removes the given mapping instance from both in-memory and Config.
 
void SaveAxisDirectionMappingIdsToConfig ()
 Writes the current set of mapping IDs for all directions to Config.
 
bool AddOrEditAxisDirectionMappingFromRawPress (Direction direction, std::string id)
 Listens for the next raw physical input and adds or replaces a directional mapping.
 
void Process (int8_t &x, int8_t &y)
 Reads raw axis values, applies processing, and writes to x and y.
 
void ResetSensitivityToDefault ()
 Resets sensitivity to DEFAULT_STICK_SENSITIVITY_PERCENTAGE and saves to Config.
 
void SetSensitivity (uint8_t sensitivityPercentage)
 Sets the stick sensitivity and saves to Config.
 
uint8_t GetSensitivityPercentage ()
 Returns the current sensitivity percentage.
 
bool SensitivityIsDefault ()
 Returns true if sensitivity is at the default value.
 
void ResetDeadzoneToDefault ()
 Resets dead-zone to DEFAULT_STICK_DEADZONE_PERCENTAGE and saves to Config.
 
void SetDeadzone (uint8_t deadzonePercentage)
 Sets the dead-zone and saves to Config.
 
uint8_t GetDeadzonePercentage ()
 Returns the current dead-zone percentage.
 
bool DeadzoneIsDefault ()
 Returns true if dead-zone is at the default value.
 
void ResetNotchSnapAngleToDefault ()
 Resets notch snap angle to DEFAULT_NOTCH_SNAP_ANGLE and saves to Config.
 
void SetNotchSnapAngle (uint8_t notchSnapAngle)
 Sets the notch snap angle and saves to Config.
 
uint8_t GetNotchSnapAngle ()
 Returns the current notch snap angle in degrees.
 
bool NotchSnapAngleIsDefault ()
 Returns true if the notch snap angle is at the default value.
 
bool ProcessKeyboardEvent (KbEventType eventType, KbScancode scancode)
 Forwards a keyboard event to all directional mappings that handle keyboard input.
 
bool ProcessMouseButtonEvent (bool isPressed, Ship::MouseBtn button)
 Forwards a mouse-button event to all directional mappings that handle mouse input.
 
bool HasMappingsForPhysicalDeviceType (PhysicalDeviceType physicalDeviceType)
 Returns true if any directional mapping targets the given device type.
 
StickIndex GetStickIndex ()
 Returns the stick index (left or right).
 

Detailed Description

Aggregates axis-direction mappings and applies sensitivity, dead-zone, and notch-snap to a stick.

ControllerStick tracks four directional axes (Up, Down, Left, Right) and can hold multiple ControllerAxisDirectionMapping instances per direction. Every frame, UpdatePad() reads raw axis values from the mappings, applies the configured dead-zone and sensitivity, optionally snaps to 8-way notch angles, and writes the result as signed 8-bit values.

Settings (sensitivity, dead-zone, notch snap angle) are persisted in Config.

Constructor & Destructor Documentation

◆ ControllerStick()

Ship::ControllerStick::ControllerStick ( uint8_t  portIndex,
StickIndex  stickIndex,
std::shared_ptr< ConsoleVariable consoleVariable = nullptr,
std::shared_ptr< ControlDeck controlDeck = nullptr,
std::shared_ptr< Window window = nullptr 
)

Constructs a ControllerStick for a given port and stick index.

Parameters
portIndexZero-based port index.
stickIndexStick identifier (e.g. LEFT_STICK or RIGHT_STICK).

Constructs a ControllerStick for a specific port and stick index.

Parameters
portIndexZero-based port index.
stickIndexLEFT_STICK or RIGHT_STICK.
consoleVariableOptional ConsoleVariable dependency; falls back to Context lookup if nullptr.

◆ ~ControllerStick()

Ship::ControllerStick::~ControllerStick ( )

Member Function Documentation

◆ AddAxisDirectionMapping()

void Ship::ControllerStick::AddAxisDirectionMapping ( Direction  direction,
std::shared_ptr< ControllerAxisDirectionMapping mapping 
)

Adds a mapping for the given direction.

Parameters
directionAxis direction.
mappingMapping to add.

◆ AddDefaultMappings()

void Ship::ControllerStick::AddDefaultMappings ( PhysicalDeviceType  physicalDeviceType)

Applies the default axis-direction mappings for the given device type.

Parameters
physicalDeviceTypeDevice type to apply defaults for.

◆ AddOrEditAxisDirectionMappingFromRawPress()

bool Ship::ControllerStick::AddOrEditAxisDirectionMappingFromRawPress ( Direction  direction,
std::string  id 
)

Listens for the next raw physical input and adds or replaces a directional mapping.

Parameters
directionAxis direction the captured input should drive.
idOptional UUID of an existing mapping to replace; empty = create new.
Returns
true if a mapping was captured and added.

◆ ClearAllMappings()

void Ship::ControllerStick::ClearAllMappings ( )

Removes all axis-direction mappings for all directions.

◆ ClearAllMappingsForDeviceType()

void Ship::ControllerStick::ClearAllMappingsForDeviceType ( PhysicalDeviceType  physicalDeviceType)

Removes all axis-direction mappings that target the given device type.

Parameters
physicalDeviceTypeDevice type whose mappings should be cleared.

◆ ClearAxisDirectionMapping() [1/2]

void Ship::ControllerStick::ClearAxisDirectionMapping ( Direction  direction,
std::shared_ptr< ControllerAxisDirectionMapping mapping 
)

Removes the given mapping instance from both in-memory and Config.

Parameters
directionAxis direction.
mappingMapping to remove.

◆ ClearAxisDirectionMapping() [2/2]

void Ship::ControllerStick::ClearAxisDirectionMapping ( Direction  direction,
std::string  id 
)

Removes the mapping by ID from both in-memory and Config.

Parameters
directionAxis direction.
idMapping UUID.

◆ ClearAxisDirectionMappingId()

void Ship::ControllerStick::ClearAxisDirectionMappingId ( Direction  direction,
std::string  id 
)

Removes the mapping ID from Config without destroying the in-memory object.

Parameters
directionAxis direction.
idMapping UUID.

◆ DeadzoneIsDefault()

bool Ship::ControllerStick::DeadzoneIsDefault ( )

Returns true if dead-zone is at the default value.

◆ GetAllAxisDirectionMappingByDirection()

std::unordered_map< std::string, std::shared_ptr< ControllerAxisDirectionMapping > > Ship::ControllerStick::GetAllAxisDirectionMappingByDirection ( Direction  direction)

Returns the id → mapping map for a single direction.

Parameters
directionAxis direction to query.

◆ GetAllAxisDirectionMappings()

std::unordered_map< Direction, std::unordered_map< std::string, std::shared_ptr< ControllerAxisDirectionMapping > > > Ship::ControllerStick::GetAllAxisDirectionMappings ( )

Returns a copy of the full direction → (id → mapping) map.

◆ GetAxisDirectionMappingById()

std::shared_ptr< ControllerAxisDirectionMapping > Ship::ControllerStick::GetAxisDirectionMappingById ( Direction  direction,
std::string  id 
)

Returns the mapping for the given direction and ID, or nullptr if not found.

Parameters
directionAxis direction (Up/Down/Left/Right).
idMapping UUID.

◆ GetDeadzonePercentage()

uint8_t Ship::ControllerStick::GetDeadzonePercentage ( )

Returns the current dead-zone percentage.

◆ GetNotchSnapAngle()

uint8_t Ship::ControllerStick::GetNotchSnapAngle ( )

Returns the current notch snap angle in degrees.

◆ GetSensitivityPercentage()

uint8_t Ship::ControllerStick::GetSensitivityPercentage ( )

Returns the current sensitivity percentage.

◆ GetStickIndex()

StickIndex Ship::ControllerStick::GetStickIndex ( )

Returns the stick index (left or right).

◆ HasMappingsForPhysicalDeviceType()

bool Ship::ControllerStick::HasMappingsForPhysicalDeviceType ( PhysicalDeviceType  physicalDeviceType)

Returns true if any directional mapping targets the given device type.

Parameters
physicalDeviceTypeDevice type to query.

◆ NotchSnapAngleIsDefault()

bool Ship::ControllerStick::NotchSnapAngleIsDefault ( )

Returns true if the notch snap angle is at the default value.

◆ Process()

void Ship::ControllerStick::Process ( int8_t &  x,
int8_t &  y 
)

Reads raw axis values, applies processing, and writes to x and y.

Alias of UpdatePad() used during the game's input-read phase.

◆ ProcessKeyboardEvent()

bool Ship::ControllerStick::ProcessKeyboardEvent ( KbEventType  eventType,
KbScancode  scancode 
)

Forwards a keyboard event to all directional mappings that handle keyboard input.

Parameters
eventTypeKey-down or key-up.
scancodePlatform-independent scan code.
Returns
true if any mapping consumed the event.

◆ ProcessMouseButtonEvent()

bool Ship::ControllerStick::ProcessMouseButtonEvent ( bool  isPressed,
Ship::MouseBtn  button 
)

Forwards a mouse-button event to all directional mappings that handle mouse input.

Parameters
isPressedtrue for button-down, false for button-up.
buttonMouse button identifier.
Returns
true if any mapping consumed the event.

◆ ReloadAllMappingsFromConfig()

void Ship::ControllerStick::ReloadAllMappingsFromConfig ( )

Clears all in-memory mappings and reloads them from Config.

◆ ResetDeadzoneToDefault()

void Ship::ControllerStick::ResetDeadzoneToDefault ( )

Resets dead-zone to DEFAULT_STICK_DEADZONE_PERCENTAGE and saves to Config.

◆ ResetNotchSnapAngleToDefault()

void Ship::ControllerStick::ResetNotchSnapAngleToDefault ( )

Resets notch snap angle to DEFAULT_NOTCH_SNAP_ANGLE and saves to Config.

◆ ResetSensitivityToDefault()

void Ship::ControllerStick::ResetSensitivityToDefault ( )

Resets sensitivity to DEFAULT_STICK_SENSITIVITY_PERCENTAGE and saves to Config.

◆ SaveAxisDirectionMappingIdsToConfig()

void Ship::ControllerStick::SaveAxisDirectionMappingIdsToConfig ( )

Writes the current set of mapping IDs for all directions to Config.

◆ SensitivityIsDefault()

bool Ship::ControllerStick::SensitivityIsDefault ( )

Returns true if sensitivity is at the default value.

◆ SetControlDeck()

void Ship::ControllerStick::SetControlDeck ( std::shared_ptr< ControlDeck controlDeck)
inline

Injects the owning ControlDeck.

◆ SetDeadzone()

void Ship::ControllerStick::SetDeadzone ( uint8_t  deadzonePercentage)

Sets the dead-zone and saves to Config.

Parameters
deadzonePercentageDead-zone radius as a percentage of full scale.

◆ SetNotchSnapAngle()

void Ship::ControllerStick::SetNotchSnapAngle ( uint8_t  notchSnapAngle)

Sets the notch snap angle and saves to Config.

Parameters
notchSnapAngleSnap threshold in degrees (0 = disabled).

◆ SetSensitivity()

void Ship::ControllerStick::SetSensitivity ( uint8_t  sensitivityPercentage)

Sets the stick sensitivity and saves to Config.

Parameters
sensitivityPercentageSensitivity as a percentage (100 = full scale).

◆ UpdatePad()

void Ship::ControllerStick::UpdatePad ( int8_t &  x,
int8_t &  y 
)

Evaluates all axis mappings and writes the processed stick values to x and y.

Dead-zone, sensitivity, and notch-snap are applied before writing the output.

Parameters
xOutput X axis value in the range [-128, 127].
yOutput Y axis value in the range [-128, 127].

The documentation for this class was generated from the following file: