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

Manages all controller ports and routes input/blocking requests. More...

#include <ControlDeck.h>

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

Public Member Functions

 ControlDeck (std::vector< CONTROLLERBUTTONS_T > additionalBitmasks, std::shared_ptr< ControllerDefaultMappings > controllerDefaultMappings, std::unordered_map< CONTROLLERBUTTONS_T, std::string > buttonNames, std::shared_ptr< Window > window=nullptr, std::shared_ptr< ConsoleVariable > consoleVariable=nullptr)
 Constructs the ControlDeck and sets up the port list.
 
 ~ControlDeck ()
 
void Init (uint8_t *controllerBits)
 Initialises the controller deck and loads saved mappings from Config.
 
virtual void WriteToPad (void *pads)=0
 Reads controller state and writes it to the game-specific pad structure(s).
 
uint8_t * GetControllerBits ()
 Returns the pointer passed to Init() that tracks which ports have controllers.
 
std::shared_ptr< ControllerGetControllerByPort (uint8_t port)
 Returns the Controller connected to the given port, or nullptr.
 
void BlockGameInput (int32_t blockId)
 Blocks all game input for the caller identified by blockId.
 
void UnblockGameInput (int32_t blockId)
 Removes the block associated with blockId.
 
bool GamepadGameInputBlocked ()
 Returns true if any blocker has blocked gamepad game input.
 
bool KeyboardGameInputBlocked ()
 Returns true if any blocker has blocked keyboard game input.
 
bool MouseGameInputBlocked ()
 Returns true if any blocker has blocked mouse game input.
 
bool ProcessKeyboardEvent (KbEventType eventType, KbScancode scancode)
 Forwards a keyboard event to all controllers that have keyboard bindings.
 
bool ProcessMouseButtonEvent (bool isPressed, MouseBtn button)
 Forwards a mouse-button event to all controllers that have mouse bindings.
 
std::shared_ptr< ConnectedPhysicalDeviceManagerGetConnectedPhysicalDeviceManager ()
 Returns the manager that tracks currently connected SDL/HID devices.
 
std::shared_ptr< GlobalSDLDeviceSettingsGetGlobalSDLDeviceSettings ()
 Returns the global SDL device settings (dead-zone, axis scale, etc.).
 
std::shared_ptr< ControllerDefaultMappingsGetControllerDefaultMappings ()
 Returns the default mapping configuration applied to new controllers.
 
std::shared_ptr< WheelHandlerGetWheelHandler () const
 Returns the cached wheel handler.
 
const std::unordered_map< CONTROLLERBUTTONS_T, std::string > & GetAllButtonNames () const
 Returns the full bitmask→name map for all registered buttons.
 
std::string GetButtonNameForBitmask (CONTROLLERBUTTONS_T bitmask)
 Returns the human-readable name for the given button bitmask.
 
- Public Member Functions inherited from Ship::Component
 Component (const std::string &name, std::shared_ptr< Context > context=nullptr)
 Constructs a Component with the given name.
 
virtual ~Component ()
 
void Init (const nlohmann::json &initArgs=nlohmann::json::object())
 Performs one-time initialization of this component.
 
bool IsInitialized () const
 Returns true once Init() (or MarkInitialized()) has completed successfully.
 
const std::string & GetName () const
 Returns the name of this Component.
 
std::string ToString () const
 Returns a human-readable string representation (e.g. "Name (id)").
 
std::string ToTreeString (int depth=0) const
 Returns a human-readable tree representation of this component and its children.
 
 operator std::string () const
 Conversion operator to std::string; equivalent to ToString().
 
ParentComponentListGetParents ()
 Returns a mutable reference to the parent list.
 
const ParentComponentListGetParents () const
 Returns a const reference to the parent list.
 
ComponentListGetChildren ()
 Returns a mutable reference to the child list.
 
const ComponentListGetChildren () const
 Returns a const reference to the child list.
 
virtual std::shared_ptr< ComponentTryGetSharedComponent () noexcept
 Returns a shared_ptr to this Component when available, otherwise nullptr.
 
virtual std::shared_ptr< ComponentGetSharedComponent ()
 Returns a shared_ptr to this Component via the correct enable_shared_from_this base.
 
template<typename T >
bool HasInChildren () const
 Checks whether any descendant Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInChildren () const
 Returns the first descendant that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInChildren () const
 Returns all descendants that match type T via BFS.
 
template<typename T >
bool HasInParents () const
 Checks whether any ancestor Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInParents () const
 Returns the first ancestor that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInParents () const
 Returns all ancestors that match type T via BFS.
 
- Public Member Functions inherited from Ship::Part
 Part ()
 Constructs a Part and assigns it a unique ID.
 
 Part (std::shared_ptr< Context > context)
 Constructs a Part with an explicit Context reference and unique ID.
 
virtual ~Part ()=default
 
uint64_t GetId () const
 Returns the unique identifier for this Part.
 
bool operator== (const Part &other) const
 Compares two Parts for equality by their unique IDs.
 
std::shared_ptr< ContextGetContext () const
 Returns the Context this Part belongs to, or nullptr if unset.
 
void SetContext (std::shared_ptr< Context > ctx)
 Sets the Context this Part belongs to.
 

Protected Member Functions

bool AllGameInputBlocked ()
 Returns true if all registered blockers have blocked game input.
 
- Protected Member Functions inherited from Ship::Component
virtual void OnInit (const nlohmann::json &initArgs=nlohmann::json::object())
 Override this to implement component-specific initialization logic.
 
void MarkInitialized ()
 Marks this component as initialized without going through Init().
 
template<typename T >
std::shared_ptr< T > RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const
 Returns a cached dependency after validating it exists and is initialized.
 
- Protected Member Functions inherited from Ship::Part
virtual void OnAdded (bool forced)
 Called after this Part has been added to a PartList.
 
virtual void OnRemoved (bool forced)
 Called after this Part has been removed from a PartList.
 

Protected Attributes

std::vector< std::shared_ptr< ControlPort > > mPorts = {}
 One entry per controller port.
 

Detailed Description

Manages all controller ports and routes input/blocking requests.

ControlDeck is the top-level controller subsystem. It owns a fixed set of ControlPort instances, one per supported controller port, and exposes the game-facing API for:

  • Writing pad state from connected controllers (via the pure-virtual WriteToPad()).
  • Blocking / unblocking game input globally (e.g. while the ImGui overlay is focused).
  • Forwarding keyboard and mouse events to the mapping layer.
  • Providing access to physical device management and default-mapping configuration.

Subclass ControlDeck to implement WriteToPad() for a specific game's pad layout.

Required dependencies (constructor-injected): Window, ConsoleVariable

  • ConsoleVariable — injected at construction and used by controller mapping layers to load/save per-mapping settings (e.g. button assignments, rumble toggle).
  • Window — injected at construction and consulted by controller mappings for keyboard/mouse capture state.

Obtain the instance from Context::GetChildren().GetFirst<ControlDeck>().

Constructor & Destructor Documentation

◆ ControlDeck()

Ship::ControlDeck::ControlDeck ( std::vector< CONTROLLERBUTTONS_T additionalBitmasks,
std::shared_ptr< ControllerDefaultMappings controllerDefaultMappings,
std::unordered_map< CONTROLLERBUTTONS_T, std::string >  buttonNames,
std::shared_ptr< Window window = nullptr,
std::shared_ptr< ConsoleVariable consoleVariable = nullptr 
)

Constructs the ControlDeck and sets up the port list.

Parameters
additionalBitmasksExtra button bitmasks beyond the standard set.
controllerDefaultMappingsDefault mappings applied when a new device is connected.
buttonNamesHuman-readable names for each button bitmask, keyed by bitmask.
windowOptional Window dependency.
consoleVariableOptional ConsoleVariable dependency.

◆ ~ControlDeck()

Ship::ControlDeck::~ControlDeck ( )

Member Function Documentation

◆ AllGameInputBlocked()

bool Ship::ControlDeck::AllGameInputBlocked ( )
protected

Returns true if all registered blockers have blocked game input.

Used internally by WriteToPad() implementations to decide whether to pass zeroed or real pad data to the game.

◆ BlockGameInput()

void Ship::ControlDeck::BlockGameInput ( int32_t  blockId)

Blocks all game input for the caller identified by blockId.

Multiple callers may independently block input; input is only unblocked when all callers have called UnblockGameInput() with their respective IDs.

Parameters
blockIdArbitrary identifier that distinguishes this blocker from others.

◆ GamepadGameInputBlocked()

bool Ship::ControlDeck::GamepadGameInputBlocked ( )

Returns true if any blocker has blocked gamepad game input.

◆ GetAllButtonNames()

const std::unordered_map< CONTROLLERBUTTONS_T, std::string > & Ship::ControlDeck::GetAllButtonNames ( ) const

Returns the full bitmask→name map for all registered buttons.

◆ GetButtonNameForBitmask()

std::string Ship::ControlDeck::GetButtonNameForBitmask ( CONTROLLERBUTTONS_T  bitmask)

Returns the human-readable name for the given button bitmask.

Parameters
bitmaskSingle-bit button bitmask.
Returns
Human-readable name, or an empty string if the bitmask is not registered.

◆ GetConnectedPhysicalDeviceManager()

std::shared_ptr< ConnectedPhysicalDeviceManager > Ship::ControlDeck::GetConnectedPhysicalDeviceManager ( )

Returns the manager that tracks currently connected SDL/HID devices.

◆ GetControllerBits()

uint8_t * Ship::ControlDeck::GetControllerBits ( )

Returns the pointer passed to Init() that tracks which ports have controllers.

◆ GetControllerByPort()

std::shared_ptr< Controller > Ship::ControlDeck::GetControllerByPort ( uint8_t  port)

Returns the Controller connected to the given port, or nullptr.

Parameters
portZero-based port index.

◆ GetControllerDefaultMappings()

std::shared_ptr< ControllerDefaultMappings > Ship::ControlDeck::GetControllerDefaultMappings ( )

Returns the default mapping configuration applied to new controllers.

◆ GetGlobalSDLDeviceSettings()

std::shared_ptr< GlobalSDLDeviceSettings > Ship::ControlDeck::GetGlobalSDLDeviceSettings ( )

Returns the global SDL device settings (dead-zone, axis scale, etc.).

◆ GetWheelHandler()

std::shared_ptr< WheelHandler > Ship::ControlDeck::GetWheelHandler ( ) const

Returns the cached wheel handler.

◆ Init()

void Ship::ControlDeck::Init ( uint8_t *  controllerBits)

Initialises the controller deck and loads saved mappings from Config.

Parameters
controllerBitsPointer to the byte the game uses as a bitmask of connected ports.

◆ KeyboardGameInputBlocked()

bool Ship::ControlDeck::KeyboardGameInputBlocked ( )

Returns true if any blocker has blocked keyboard game input.

◆ MouseGameInputBlocked()

bool Ship::ControlDeck::MouseGameInputBlocked ( )

Returns true if any blocker has blocked mouse game input.

◆ ProcessKeyboardEvent()

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

Forwards a keyboard event to all controllers that have keyboard bindings.

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

◆ ProcessMouseButtonEvent()

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

Forwards a mouse-button event to all controllers that have mouse bindings.

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

◆ UnblockGameInput()

void Ship::ControlDeck::UnblockGameInput ( int32_t  blockId)

Removes the block associated with blockId.

Parameters
blockIdThe same ID passed to BlockGameInput().

◆ WriteToPad()

virtual void Ship::ControlDeck::WriteToPad ( void *  pads)
pure virtual

Reads controller state and writes it to the game-specific pad structure(s).

Must be implemented by a game-specific subclass to translate Controller state into whatever pad format the game expects (e.g. OSContPad on Nintendo 64).

Parameters
padsPointer to the game's pad buffer.

Implemented in LUS::ControlDeck.

Member Data Documentation

◆ mPorts

std::vector<std::shared_ptr<ControlPort> > Ship::ControlDeck::mPorts = {}
protected

One entry per controller port.


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