libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <memory>
5#include <string>
6#include <cstdint>
7#include <queue>
8#include <vector>
9#include <map>
10#include <unordered_map>
11#include "ControllerButton.h"
12#include "ControllerStick.h"
13#include "ControllerGyro.h"
14#include "ControllerRumble.h"
15#include "ControllerLED.h"
18
19namespace Ship {
20class ConsoleVariable;
21class ControlDeck;
22class Window;
23
38class Controller : public ControlDevice {
39 public:
41 void SetControlDeck(std::shared_ptr<ControlDeck> controlDeck);
48 Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> bitmasks,
49 std::shared_ptr<ConsoleVariable> consoleVariable = nullptr,
50 std::shared_ptr<ControlDeck> controlDeck = nullptr, std::shared_ptr<Window> window = nullptr);
51
54
61
63 bool IsConnected() const;
64
66 void Connect();
67
69 void Disconnect();
70
73
79
84 void AddDefaultMappings(PhysicalDeviceType physicalDeviceType);
85
89 std::unordered_map<CONTROLLERBUTTONS_T, std::shared_ptr<ControllerButton>> GetAllButtons();
90
95 std::shared_ptr<ControllerButton> GetButtonByBitmask(CONTROLLERBUTTONS_T bitmask);
96
101 std::shared_ptr<ControllerButton> GetButton(CONTROLLERBUTTONS_T bitmask);
102
104 std::shared_ptr<ControllerStick> GetLeftStick();
105
107 std::shared_ptr<ControllerStick> GetRightStick();
108
110 std::shared_ptr<ControllerGyro> GetGyro();
111
113 std::shared_ptr<ControllerRumble> GetRumble();
114
116 std::shared_ptr<ControllerLED> GetLED();
117
125 virtual void ReadToPad(void* pad) = 0;
126
130 bool HasConfig();
131
133 uint8_t GetPortIndex();
134
138 std::vector<std::shared_ptr<ControllerMapping>> GetAllMappings();
139
146 bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
147
154 bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);
155
161
162 protected:
163 std::unordered_map<CONTROLLERBUTTONS_T, std::shared_ptr<ControllerButton>>
165 std::shared_ptr<ConsoleVariable> mConsoleVariable;
166 std::shared_ptr<ControlDeck> mControlDeck;
167 std::shared_ptr<Window> mWindow;
168
169 private:
170 void LoadButtonMappingFromConfig(std::string id);
171 void SaveButtonMappingIdsToConfig();
172
173 std::shared_ptr<ControllerStick> mLeftStick, mRightStick;
174 std::shared_ptr<ControllerGyro> mGyro;
175 std::shared_ptr<ControllerRumble> mRumble;
176 std::shared_ptr<ControllerLED> mLED;
177};
178} // namespace Ship
#define CONTROLLERBUTTONS_T
Definition ControllerButtonMapping.h:13
Abstract base class for all input devices that can be connected to a ControlPort.
Definition ControlDevice.h:15
Represents a single logical controller connected to a ControlPort.
Definition Controller.h:38
std::shared_ptr< ControllerStick > GetLeftStick()
Returns the left analog stick input aggregator.
std::shared_ptr< ControllerButton > GetButtonByBitmask(CONTROLLERBUTTONS_T bitmask)
Returns the ControllerButton for the given bitmask, or nullptr if not found.
void AddDefaultMappings(PhysicalDeviceType physicalDeviceType)
Applies the default mappings for the given physical device type.
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType)
Returns true if any mapping for this controller targets the given physical device type.
std::vector< std::shared_ptr< ControllerMapping > > GetAllMappings()
Returns a flat list of all ControllerMapping instances across all subsystems.
bool HasConfig()
Returns true if any Config key exists for this controller's mappings.
void Disconnect()
Marks the controller as "disconnected" and clears transient state.
void SetControlDeck(std::shared_ptr< ControlDeck > controlDeck)
Injects the owning ControlDeck into this controller and all of its subsystems.
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode)
Forwards a keyboard event to all button and stick mappings.
void Connect()
Marks the controller as "connected" (used by the mapping layer).
bool IsConnected() const
Returns true if at least one physical device mapping is active for any button.
std::shared_ptr< ControlDeck > mControlDeck
Definition Controller.h:166
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button)
Forwards a mouse-button event to all button and stick mappings.
std::unordered_map< CONTROLLERBUTTONS_T, std::shared_ptr< ControllerButton > > mButtons
Button subsystems keyed by bitmask.
Definition Controller.h:164
std::shared_ptr< Window > mWindow
Definition Controller.h:167
void ClearAllMappings()
Removes all mappings for all buttons, sticks, rumble, LED, and gyro.
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.
void ReloadAllMappingsFromConfig()
Discards all in-memory mappings and reloads them from Config.
std::shared_ptr< ControllerGyro > GetGyro()
Returns the gyroscope input aggregator.
std::shared_ptr< ControllerLED > GetLED()
Returns the LED output aggregator.
std::shared_ptr< ConsoleVariable > mConsoleVariable
Cached ConsoleVariable component.
Definition Controller.h:165
~Controller()
Destroys the Controller and releases all mapping resources.
std::shared_ptr< ControllerStick > GetRightStick()
Returns the right analog stick input aggregator.
uint8_t GetPortIndex()
Returns the zero-based port index this controller is bound to.
std::unordered_map< CONTROLLERBUTTONS_T, std::shared_ptr< ControllerButton > > GetAllButtons()
Returns the full bitmask→ControllerButton map.
virtual void ReadToPad(void *pad)=0
Reads aggregated input state and writes it to the game-specific pad structure.
std::shared_ptr< ControllerButton > GetButton(CONTROLLERBUTTONS_T bitmask)
Alias of GetButtonByBitmask().
void ClearAllMappingsForDeviceType(PhysicalDeviceType physicalDeviceType)
Removes all mappings that target the given physical device type.
std::shared_ptr< ControllerRumble > GetRumble()
Returns the rumble output aggregator.
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
PhysicalDeviceType
Identifies the category of a physical input device.
Definition PhysicalDeviceType.h:11
KbScancode
Platform-independent keyboard scan codes used by the input mapping system.
Definition KeyboardScancodes.h:26
KbEventType
Identifies the type of a keyboard event delivered to the input mapping system.
Definition KeyboardScancodes.h:12
MouseBtn
Identifies a mouse button delivered to the input mapping system.
Definition KeyboardScancodes.h:136