|
libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
|
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< ControllerAxisDirectionMapping > | GetAxisDirectionMappingById (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). | |
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.
| 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.
| portIndex | Zero-based port index. |
| stickIndex | Stick identifier (e.g. LEFT_STICK or RIGHT_STICK). |
Constructs a ControllerStick for a specific port and stick index.
| portIndex | Zero-based port index. |
| stickIndex | LEFT_STICK or RIGHT_STICK. |
| consoleVariable | Optional ConsoleVariable dependency; falls back to Context lookup if nullptr. |
| Ship::ControllerStick::~ControllerStick | ( | ) |
| void Ship::ControllerStick::AddAxisDirectionMapping | ( | Direction | direction, |
| std::shared_ptr< ControllerAxisDirectionMapping > | mapping | ||
| ) |
Adds a mapping for the given direction.
| direction | Axis direction. |
| mapping | Mapping to add. |
| void Ship::ControllerStick::AddDefaultMappings | ( | PhysicalDeviceType | physicalDeviceType | ) |
Applies the default axis-direction mappings for the given device type.
| physicalDeviceType | Device type to apply defaults for. |
| bool Ship::ControllerStick::AddOrEditAxisDirectionMappingFromRawPress | ( | Direction | direction, |
| std::string | id | ||
| ) |
Listens for the next raw physical input and adds or replaces a directional mapping.
| direction | Axis direction the captured input should drive. |
| id | Optional UUID of an existing mapping to replace; empty = create new. |
| void Ship::ControllerStick::ClearAllMappings | ( | ) |
Removes all axis-direction mappings for all directions.
| void Ship::ControllerStick::ClearAllMappingsForDeviceType | ( | PhysicalDeviceType | physicalDeviceType | ) |
Removes all axis-direction mappings that target the given device type.
| physicalDeviceType | Device type whose mappings should be cleared. |
| void Ship::ControllerStick::ClearAxisDirectionMapping | ( | Direction | direction, |
| std::shared_ptr< ControllerAxisDirectionMapping > | mapping | ||
| ) |
Removes the given mapping instance from both in-memory and Config.
| direction | Axis direction. |
| mapping | Mapping to remove. |
| void Ship::ControllerStick::ClearAxisDirectionMapping | ( | Direction | direction, |
| std::string | id | ||
| ) |
Removes the mapping by ID from both in-memory and Config.
| direction | Axis direction. |
| id | Mapping UUID. |
| void Ship::ControllerStick::ClearAxisDirectionMappingId | ( | Direction | direction, |
| std::string | id | ||
| ) |
Removes the mapping ID from Config without destroying the in-memory object.
| direction | Axis direction. |
| id | Mapping UUID. |
| bool Ship::ControllerStick::DeadzoneIsDefault | ( | ) |
Returns true if dead-zone is at the default value.
| std::unordered_map< std::string, std::shared_ptr< ControllerAxisDirectionMapping > > Ship::ControllerStick::GetAllAxisDirectionMappingByDirection | ( | Direction | direction | ) |
Returns the id → mapping map for a single direction.
| direction | Axis direction to query. |
| 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.
| 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.
| direction | Axis direction (Up/Down/Left/Right). |
| id | Mapping UUID. |
| uint8_t Ship::ControllerStick::GetDeadzonePercentage | ( | ) |
Returns the current dead-zone percentage.
| uint8_t Ship::ControllerStick::GetNotchSnapAngle | ( | ) |
Returns the current notch snap angle in degrees.
| uint8_t Ship::ControllerStick::GetSensitivityPercentage | ( | ) |
Returns the current sensitivity percentage.
| StickIndex Ship::ControllerStick::GetStickIndex | ( | ) |
Returns the stick index (left or right).
| bool Ship::ControllerStick::HasMappingsForPhysicalDeviceType | ( | PhysicalDeviceType | physicalDeviceType | ) |
Returns true if any directional mapping targets the given device type.
| physicalDeviceType | Device type to query. |
| bool Ship::ControllerStick::NotchSnapAngleIsDefault | ( | ) |
Returns true if the notch snap angle is at the default value.
| 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.
| bool Ship::ControllerStick::ProcessKeyboardEvent | ( | KbEventType | eventType, |
| KbScancode | scancode | ||
| ) |
Forwards a keyboard event to all directional mappings that handle keyboard input.
| eventType | Key-down or key-up. |
| scancode | Platform-independent scan code. |
| bool Ship::ControllerStick::ProcessMouseButtonEvent | ( | bool | isPressed, |
| Ship::MouseBtn | button | ||
| ) |
Forwards a mouse-button event to all directional mappings that handle mouse input.
| isPressed | true for button-down, false for button-up. |
| button | Mouse button identifier. |
| void Ship::ControllerStick::ReloadAllMappingsFromConfig | ( | ) |
Clears all in-memory mappings and reloads them from Config.
| void Ship::ControllerStick::ResetDeadzoneToDefault | ( | ) |
Resets dead-zone to DEFAULT_STICK_DEADZONE_PERCENTAGE and saves to Config.
| void Ship::ControllerStick::ResetNotchSnapAngleToDefault | ( | ) |
Resets notch snap angle to DEFAULT_NOTCH_SNAP_ANGLE and saves to Config.
| void Ship::ControllerStick::ResetSensitivityToDefault | ( | ) |
Resets sensitivity to DEFAULT_STICK_SENSITIVITY_PERCENTAGE and saves to Config.
| void Ship::ControllerStick::SaveAxisDirectionMappingIdsToConfig | ( | ) |
Writes the current set of mapping IDs for all directions to Config.
| bool Ship::ControllerStick::SensitivityIsDefault | ( | ) |
Returns true if sensitivity is at the default value.
|
inline |
Injects the owning ControlDeck.
| void Ship::ControllerStick::SetDeadzone | ( | uint8_t | deadzonePercentage | ) |
Sets the dead-zone and saves to Config.
| deadzonePercentage | Dead-zone radius as a percentage of full scale. |
| void Ship::ControllerStick::SetNotchSnapAngle | ( | uint8_t | notchSnapAngle | ) |
Sets the notch snap angle and saves to Config.
| notchSnapAngle | Snap threshold in degrees (0 = disabled). |
| void Ship::ControllerStick::SetSensitivity | ( | uint8_t | sensitivityPercentage | ) |
Sets the stick sensitivity and saves to Config.
| sensitivityPercentage | Sensitivity as a percentage (100 = full scale). |
| 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.
| x | Output X axis value in the range [-128, 127]. |
| y | Output Y axis value in the range [-128, 127]. |