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

Ship's N64-compatible ControlDeck implementation. More...

#include <ControlDeck.h>

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

Public Member Functions

 ControlDeck (std::shared_ptr< Ship::Window > window=nullptr, std::shared_ptr< Ship::ConsoleVariable > consoleVariable=nullptr)
 Constructs a ControlDeck with the standard N64 button set and default mappings.
 
 ControlDeck (std::vector< CONTROLLERBUTTONS_T > additionalBitmasks, std::shared_ptr< Ship::Window > window=nullptr, std::shared_ptr< Ship::ConsoleVariable > consoleVariable=nullptr)
 Constructs a ControlDeck with the standard N64 buttons plus extra bitmasks.
 
 ControlDeck (std::vector< CONTROLLERBUTTONS_T > additionalBitmasks, std::shared_ptr< Ship::ControllerDefaultMappings > controllerDefaultMappings, std::unordered_map< CONTROLLERBUTTONS_T, std::string > buttonNames, std::shared_ptr< Ship::Window > window=nullptr, std::shared_ptr< Ship::ConsoleVariable > consoleVariable=nullptr)
 Full constructor: extra bitmasks, custom default mappings, and custom button names.
 
OSContPad * GetPads ()
 Returns a pointer to the OSContPad buffer (one pad per port).
 
void WriteToPad (void *pad) override
 Reads each connected controller and writes the result to the game's pad buffer.
 
- Public Member Functions inherited from 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.
 
 ~ControlDeck ()
 
void Init (uint8_t *controllerBits)
 Initialises the controller deck and loads saved mappings from Config.
 
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.
 

Additional Inherited Members

- Protected Member Functions inherited from Ship::ControlDeck
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 inherited from Ship::ControlDeck
std::vector< std::shared_ptr< ControlPort > > mPorts = {}
 One entry per controller port.
 

Detailed Description

Ship's N64-compatible ControlDeck implementation.

LUS::ControlDeck is the concrete ControlDeck subclass used by libultraship. It owns an OSContPad buffer (one entry per port) and implements WriteToPad() to copy the aggregated controller state from each Ship::Controller into that buffer for consumption by the emulated game.

The default constructor registers the standard N64 button set. The two-argument and three-argument constructors allow a game to extend the button set with custom bitmasks and to provide its own default mapping tables.

Obtain the instance from Context::GetControlDeck(), cast to LUS::ControlDeck if you need access to GetPads().

Constructor & Destructor Documentation

◆ ControlDeck() [1/3]

LUS::ControlDeck::ControlDeck ( std::shared_ptr< Ship::Window window = nullptr,
std::shared_ptr< Ship::ConsoleVariable consoleVariable = nullptr 
)

Constructs a ControlDeck with the standard N64 button set and default mappings.

◆ ControlDeck() [2/3]

LUS::ControlDeck::ControlDeck ( std::vector< CONTROLLERBUTTONS_T additionalBitmasks,
std::shared_ptr< Ship::Window window = nullptr,
std::shared_ptr< Ship::ConsoleVariable consoleVariable = nullptr 
)

Constructs a ControlDeck with the standard N64 buttons plus extra bitmasks.

Parameters
additionalBitmasksExtra button bitmasks beyond the standard N64 set.

◆ ControlDeck() [3/3]

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

Full constructor: extra bitmasks, custom default mappings, and custom button names.

Parameters
additionalBitmasksExtra button bitmasks.
controllerDefaultMappingsDefault mappings applied to new devices.
buttonNamesHuman-readable names for each button bitmask.

Member Function Documentation

◆ GetPads()

OSContPad * LUS::ControlDeck::GetPads ( )

Returns a pointer to the OSContPad buffer (one pad per port).

The buffer should be updated by WriteToPad() at the start of each game frame. The lifetime of the returned pointer is tied to this ControlDeck.

◆ WriteToPad()

void LUS::ControlDeck::WriteToPad ( void *  pad)
overridevirtual

Reads each connected controller and writes the result to the game's pad buffer.

pad must point to an array of OSContPad structures large enough to hold one entry per port (i.e. at least MAXCONTROLLERS * sizeof(OSContPad) bytes).

Parameters
padPointer to the game's OSContPad buffer.

Implements Ship::ControlDeck.


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