coastline 0.0.4
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <vector>
6
7#include <SDL3/SDL.h>
8
9#include "controller.h"
10#include "controls.h"
11#include "raceinput.h"
12
13namespace coastline {
14
21
27public:
35 explicit InputBindings(const GameConfig &config);
39 InputBindings(const InputBindings &) = delete;
42
45
48 return m_controls;
49 }
50
51 const ControlBindings &Controls() const {
52 return m_controls;
53 }
54
60 bool IsKeyDown(SDL_Scancode scancode);
62 void IgnoreKeyUntilReleased(SDL_Scancode scancode);
71
78 void HandleEvent(const SDL_Event &event);
79
89
90private:
91 bool OpenGamepad(SDL_JoystickID id);
92 ControlBindings m_controls;
93 std::vector<int> m_scriptedKeys;
94 std::vector<int> m_ignoredKeys;
95 ControllerState m_secondController;
97 float m_mouseWheel = 0.0f;
98 RaceInputContext m_raceInput;
99};
100
112
121
130
137
143bool IsKeyDown(SDL_Scancode scancode);
144
151void IgnoreKeyUntilReleased(SDL_Scancode scancode);
152
160
167
170
171} // namespace coastline
Configured action sources, player devices, and stick dead zone for an input owner.
Definition controls.h:248
The settings of BossRally.ini.
Definition config.h:18
InputBindings(const InputBindings &)=delete
Copying is disabled because SDL events address one active input context.
bool IsKeyDown(SDL_Scancode scancode)
PlayerDevices AssignedDevices(std::size_t player, std::size_t players) const
Resolve the Player1 and Player2 keys of the Controls section against the open gamepads.
static InputBindings * Active()
ControllerState SecondControllerState() const
void SetScriptedKeys(std::vector< int > scancodes)
Add simulated key presses alongside physical keyboard input, for tests.
void ClearMouseWheel()
Discard accumulated mouse-wheel movement.
void HandleEvent(const SDL_Event &event)
Open or close a gamepad for a connection event, and log the devices of the players.
InputBindings()
Open connected gamepads and register default controls for the active input context.
InputBindings & operator=(const InputBindings &)=delete
Assignment is disabled because the active input context has a stable address.
const ControlBindings & Controls() const
Definition input.h:51
~InputBindings()
Close gamepads and unregister this input context.
void IgnoreKeyUntilReleased(SDL_Scancode scancode)
Report a key as up to IsKeyDown() until it is released, for a key a shortcut of the window consumed,...
InputBindings(const GameConfig &config)
Open connected gamepads and register configured controls for the active input context.
std::array< ControllerState, CONTROLLER_PORTS > Poll(std::size_t players, bool race) const
ControlBindings & Controls()
Definition input.h:47
void SetSecondControllerState(const ControllerState &state)
Set the state of the second controller the race reads for its second player, until the next call.
Input history and haptic resources for one active input configuration.
Definition raceinput.h:10
Definition assetimport.h:11
void IgnoreKeyUntilReleased(SDL_Scancode scancode)
Report a key as up to IsKeyDown() until it is released, for a key a shortcut of the window consumed,...
int TakeMouseWheel()
void SetSecondControllerState(const ControllerState &state)
Set the state of the second controller the race reads for its second player, until the next call.
void SetScriptedKeys(std::vector< int > scancodes)
Add simulated key presses alongside physical keyboard input, for tests.
PlayerDevices AssignedDevices(std::size_t player, std::size_t players)
Resolve the Player1 and Player2 keys of the Controls section against the open gamepads.
void ClearMouseWheel()
Discard the wheel of the mouse scrolled since TakeMouseWheel() last read it.
std::int8_t ScaleStickAxis(std::int16_t axis)
Scale an SDL axis of -32768 to 32767 to the range of the controller stick.
ControllerState ReadRacePad(const PlayerDevices &devices)
Read the second player of a race as the console reads a pad: the race actions of the Controls section...
bool IsKeyDown(SDL_Scancode scancode)
The state of one controller port, as libultra reports a pad.
Definition controller.h:27
The devices that drive one player.
Definition input.h:16
std::vector< SDL_Gamepad * > gamepads
Borrowed gamepads, valid until disconnection or InputBindings destruction.
Definition input.h:19
bool keyboard
Definition input.h:17