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

Represents a single logical controller connected to a ControlPort. More...

#include <Controller.h>

Inheritance diagram for Ship::Controller:
[legend]
Collaboration diagram for Ship::Controller:
[legend]

Public Member Functions

void SetControlDeck (std::shared_ptr< ControlDeck > controlDeck)
 Injects the owning ControlDeck into this controller and all of its subsystems.
 
 Controller (uint8_t portIndex, std::vector< CONTROLLERBUTTONS_T > bitmasks, std::shared_ptr< ConsoleVariable > consoleVariable=nullptr, std::shared_ptr< ControlDeck > controlDeck=nullptr, std::shared_ptr< Window > window=nullptr)
 Constructs a Controller for the given port with a set of button bitmasks.
 
 ~Controller ()
 Destroys the Controller and releases all mapping resources.
 
void ReloadAllMappingsFromConfig ()
 Discards all in-memory mappings and reloads them from Config.
 
bool IsConnected () const
 Returns true if at least one physical device mapping is active for any button.
 
void Connect ()
 Marks the controller as "connected" (used by the mapping layer).
 
void Disconnect ()
 Marks the controller as "disconnected" and clears transient state.
 
void ClearAllMappings ()
 Removes all mappings for all buttons, sticks, rumble, LED, and gyro.
 
void ClearAllMappingsForDeviceType (PhysicalDeviceType physicalDeviceType)
 Removes all mappings that target the given physical device type.
 
void AddDefaultMappings (PhysicalDeviceType physicalDeviceType)
 Applies the default mappings for the given physical device type.
 
std::unordered_map< CONTROLLERBUTTONS_T, std::shared_ptr< ControllerButton > > GetAllButtons ()
 Returns the full bitmask→ControllerButton map.
 
std::shared_ptr< ControllerButtonGetButtonByBitmask (CONTROLLERBUTTONS_T bitmask)
 Returns the ControllerButton for the given bitmask, or nullptr if not found.
 
std::shared_ptr< ControllerButtonGetButton (CONTROLLERBUTTONS_T bitmask)
 Alias of GetButtonByBitmask().
 
std::shared_ptr< ControllerStickGetLeftStick ()
 Returns the left analog stick input aggregator.
 
std::shared_ptr< ControllerStickGetRightStick ()
 Returns the right analog stick input aggregator.
 
std::shared_ptr< ControllerGyroGetGyro ()
 Returns the gyroscope input aggregator.
 
std::shared_ptr< ControllerRumbleGetRumble ()
 Returns the rumble output aggregator.
 
std::shared_ptr< ControllerLEDGetLED ()
 Returns the LED output aggregator.
 
virtual void ReadToPad (void *pad)=0
 Reads aggregated input state and writes it to the game-specific pad structure.
 
bool HasConfig ()
 Returns true if any Config key exists for this controller's mappings.
 
uint8_t GetPortIndex ()
 Returns the zero-based port index this controller is bound to.
 
std::vector< std::shared_ptr< ControllerMapping > > GetAllMappings ()
 Returns a flat list of all ControllerMapping instances across all subsystems.
 
bool ProcessKeyboardEvent (KbEventType eventType, KbScancode scancode)
 Forwards a keyboard event to all button and stick mappings.
 
bool ProcessMouseButtonEvent (bool isPressed, MouseBtn button)
 Forwards a mouse-button event to all button and stick mappings.
 
bool HasMappingsForPhysicalDeviceType (PhysicalDeviceType physicalDeviceType)
 Returns true if any mapping for this controller targets the given physical device type.
 
- Public Member Functions inherited from Ship::ControlDevice
 ControlDevice (uint8_t portIndex)
 Constructs a ControlDevice bound to the given port.
 
virtual ~ControlDevice ()
 

Protected Attributes

std::unordered_map< CONTROLLERBUTTONS_T, std::shared_ptr< ControllerButton > > mButtons
 Button subsystems keyed by bitmask.
 
std::shared_ptr< ConsoleVariablemConsoleVariable
 Cached ConsoleVariable component.
 
std::shared_ptr< ControlDeckmControlDeck
 
std::shared_ptr< WindowmWindow
 
- Protected Attributes inherited from Ship::ControlDevice
uint8_t mPortIndex
 Zero-based port index this device is connected to.
 

Detailed Description

Represents a single logical controller connected to a ControlPort.

Controller aggregates a set of ControllerButton, two ControllerStick, a ControllerGyro, a ControllerRumble, and a ControllerLED — each of which holds a collection of ControllerMapping instances that translate physical device events into logical input.

Subclass Controller and implement ReadToPad() to convert the aggregated input state into whatever structure the game expects (e.g. an N64 OSContPad).

Mappings are persisted in Config under a key derived from the port index and are (re-)loaded via ReloadAllMappingsFromConfig().

Constructor & Destructor Documentation

◆ Controller()

Ship::Controller::Controller ( uint8_t  portIndex,
std::vector< CONTROLLERBUTTONS_T bitmasks,
std::shared_ptr< ConsoleVariable consoleVariable = nullptr,
std::shared_ptr< ControlDeck controlDeck = nullptr,
std::shared_ptr< Window window = nullptr 
)

Constructs a Controller for the given port with a set of button bitmasks.

Parameters
portIndexZero-based port index.
bitmasksAll button bitmasks this controller should track (one ControllerButton per entry).
consoleVariableOptional ConsoleVariable dependency; falls back to Context lookup if nullptr.

◆ ~Controller()

Ship::Controller::~Controller ( )

Destroys the Controller and releases all mapping resources.

Member Function Documentation

◆ AddDefaultMappings()

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

Applies the default mappings for the given physical device type.

Parameters
physicalDeviceTypeDevice type to apply defaults for.

◆ ClearAllMappings()

void Ship::Controller::ClearAllMappings ( )

Removes all mappings for all buttons, sticks, rumble, LED, and gyro.

◆ ClearAllMappingsForDeviceType()

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

Removes all mappings that target the given physical device type.

Parameters
physicalDeviceTypeType of device whose mappings should be cleared (e.g. keyboard, SDL gamepad).

◆ Connect()

void Ship::Controller::Connect ( )

Marks the controller as "connected" (used by the mapping layer).

◆ Disconnect()

void Ship::Controller::Disconnect ( )

Marks the controller as "disconnected" and clears transient state.

◆ GetAllButtons()

std::unordered_map< CONTROLLERBUTTONS_T, std::shared_ptr< ControllerButton > > Ship::Controller::GetAllButtons ( )

Returns the full bitmask→ControllerButton map.

◆ GetAllMappings()

std::vector< std::shared_ptr< ControllerMapping > > Ship::Controller::GetAllMappings ( )

Returns a flat list of all ControllerMapping instances across all subsystems.

◆ GetButton()

std::shared_ptr< ControllerButton > Ship::Controller::GetButton ( CONTROLLERBUTTONS_T  bitmask)

Alias of GetButtonByBitmask().

Parameters
bitmaskSingle-bit button bitmask.

◆ GetButtonByBitmask()

std::shared_ptr< ControllerButton > Ship::Controller::GetButtonByBitmask ( CONTROLLERBUTTONS_T  bitmask)

Returns the ControllerButton for the given bitmask, or nullptr if not found.

Parameters
bitmaskSingle-bit button bitmask.

◆ GetGyro()

std::shared_ptr< ControllerGyro > Ship::Controller::GetGyro ( )

Returns the gyroscope input aggregator.

◆ GetLED()

std::shared_ptr< ControllerLED > Ship::Controller::GetLED ( )

Returns the LED output aggregator.

◆ GetLeftStick()

std::shared_ptr< ControllerStick > Ship::Controller::GetLeftStick ( )

Returns the left analog stick input aggregator.

◆ GetPortIndex()

uint8_t Ship::Controller::GetPortIndex ( )

Returns the zero-based port index this controller is bound to.

◆ GetRightStick()

std::shared_ptr< ControllerStick > Ship::Controller::GetRightStick ( )

Returns the right analog stick input aggregator.

◆ GetRumble()

std::shared_ptr< ControllerRumble > Ship::Controller::GetRumble ( )

Returns the rumble output aggregator.

◆ HasConfig()

bool Ship::Controller::HasConfig ( )

Returns true if any Config key exists for this controller's mappings.

◆ HasMappingsForPhysicalDeviceType()

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

Returns true if any mapping for this controller targets the given physical device type.

Parameters
physicalDeviceTypeDevice type to query.

◆ IsConnected()

bool Ship::Controller::IsConnected ( ) const

Returns true if at least one physical device mapping is active for any button.

◆ ProcessKeyboardEvent()

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

Forwards a keyboard event to all button and stick mappings.

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

◆ ProcessMouseButtonEvent()

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

Forwards a mouse-button event to all button and stick mappings.

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

◆ ReadToPad()

virtual void Ship::Controller::ReadToPad ( void *  pad)
pure virtual

Reads aggregated input state and writes it to the game-specific pad structure.

Must be implemented by a game-specific subclass.

Parameters
padPointer to the game's pad buffer for this controller's port.

Implemented in LUS::Controller.

◆ ReloadAllMappingsFromConfig()

void Ship::Controller::ReloadAllMappingsFromConfig ( )

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

Called on startup and whenever the user saves mapping changes.

◆ SetControlDeck()

void Ship::Controller::SetControlDeck ( std::shared_ptr< ControlDeck controlDeck)

Injects the owning ControlDeck into this controller and all of its subsystems.

Member Data Documentation

◆ mButtons

std::unordered_map<CONTROLLERBUTTONS_T, std::shared_ptr<ControllerButton> > Ship::Controller::mButtons
protected

Button subsystems keyed by bitmask.

◆ mConsoleVariable

std::shared_ptr<ConsoleVariable> Ship::Controller::mConsoleVariable
protected

Cached ConsoleVariable component.

◆ mControlDeck

std::shared_ptr<ControlDeck> Ship::Controller::mControlDeck
protected

◆ mWindow

std::shared_ptr<Window> Ship::Controller::mWindow
protected

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