coastline 0.0.4
Loading...
Searching...
No Matches
coastline::InputBindings Class Reference

Open every gamepad in the order it connects, and drive the first two ports with the devices the Player1 and Player2 keys of the Controls section choose. More...

#include <input.h>

Public Member Functions

 InputBindings ()
 Open connected gamepads and register default controls for the active input context.
 InputBindings (const GameConfig &config)
 Open connected gamepads and register configured controls for the active input context.
 ~InputBindings ()
 Close gamepads and unregister this input context.
 InputBindings (const InputBindings &)=delete
 Copying is disabled because SDL events address one active input context.
InputBindings & operator= (const InputBindings &)=delete
 Assignment is disabled because the active input context has a stable address.
ControlBindings & Controls ()
const ControlBindings & Controls () const
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.
void SetScriptedKeys (std::vector< int > scancodes)
 Add simulated key presses alongside physical keyboard input, for tests.
bool IsKeyDown (SDL_Scancode scancode)
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, such as Enter of Alt and Enter.
void SetSecondControllerState (const ControllerState &state)
 Set the state of the second controller the race reads for its second player, until the next call.
ControllerState SecondControllerState () const
int TakeMouseWheel ()
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.
std::array< ControllerState, CONTROLLER_PORTS > Poll (std::size_t players, bool race) const

Static Public Member Functions

static InputBindings * Active ()

Detailed Description

Open every gamepad in the order it connects, and drive the first two ports with the devices the Player1 and Player2 keys of the Controls section choose.

One instance exists at a time.

Constructor & Destructor Documentation

◆ InputBindings() [1/3]

coastline::InputBindings::InputBindings ( )

Open connected gamepads and register default controls for the active input context.

◆ InputBindings() [2/3]

coastline::InputBindings::InputBindings ( const GameConfig & config)
explicit

Open connected gamepads and register configured controls for the active input context.

Parameters
configThe initial keyboard, gamepad, and player-assignment settings.

◆ ~InputBindings()

coastline::InputBindings::~InputBindings ( )

Close gamepads and unregister this input context.

◆ InputBindings() [3/3]

coastline::InputBindings::InputBindings ( const InputBindings & )
delete

Copying is disabled because SDL events address one active input context.

Member Function Documentation

◆ operator=()

InputBindings & coastline::InputBindings::operator= ( const InputBindings & )
delete

Assignment is disabled because the active input context has a stable address.

◆ Active()

InputBindings * coastline::InputBindings::Active ( )
static
Returns
The active input owner registered with SDL, or null outside its lifetime.

◆ Controls() [1/2]

ControlBindings & coastline::InputBindings::Controls ( )
inline
Returns
The input owner's configured bindings.

◆ Controls() [2/2]

const ControlBindings & coastline::InputBindings::Controls ( ) const
inline
Returns
The input owner's configured bindings.

◆ AssignedDevices()

PlayerDevices coastline::InputBindings::AssignedDevices ( std::size_t player,
std::size_t players ) const

Resolve the Player1 and Player2 keys of the Controls section against the open gamepads.

A key that is auto takes the gamepads no other key chooses, one each in the order of the players and the rest by the first player that is auto, and the keyboard goes to the first player that is auto with no gamepad, else to the first player that is auto.

Parameters
playerThe player, 0 for the first.
playersThe number of players, 1 or 2. One player takes the devices of both.
Returns
The devices of the player.

◆ SetScriptedKeys()

void coastline::InputBindings::SetScriptedKeys ( std::vector< int > scancodes)

Add simulated key presses alongside physical keyboard input, for tests.

Parameters
scancodesThe SDL scancodes to report as down, replacing the previous list.

◆ IsKeyDown()

bool coastline::InputBindings::IsKeyDown ( SDL_Scancode scancode)

Parameters
scancodeThe key.
Returns
Whether the key is down on the keyboard or reported by SetScriptedKeys(), and not ignored by IgnoreKeyUntilReleased(). Without active bindings, only physical input is read.

◆ IgnoreKeyUntilReleased()

void coastline::InputBindings::IgnoreKeyUntilReleased ( SDL_Scancode scancode)

Report a key as up to IsKeyDown() until it is released, for a key a shortcut of the window consumed, such as Enter of Alt and Enter.

Parameters
scancodeThe key.

◆ SetSecondControllerState()

void coastline::InputBindings::SetSecondControllerState ( const ControllerState & state)

Set the state of the second controller the race reads for its second player, until the next call.

Parameters
stateThe state of the second port.

◆ SecondControllerState()

ControllerState coastline::InputBindings::SecondControllerState ( ) const
Returns
The latest sample of the second controller.

◆ TakeMouseWheel()

int coastline::InputBindings::TakeMouseWheel ( )

Returns
The wheel of the mouse scrolled since the last call, in the units of the third axis of a DirectInput mouse (120 a notch, positive away from the user). A fraction of a unit is retained for the next call.

◆ ClearMouseWheel()

void coastline::InputBindings::ClearMouseWheel ( )

Discard accumulated mouse-wheel movement.

◆ HandleEvent()

void coastline::InputBindings::HandleEvent ( const SDL_Event & event)

Open or close a gamepad for a connection event, and log the devices of the players.

A wheel event of the mouse adds to the wheel TakeMouseWheel() reads. Other events are ignored.

Parameters
eventThe SDL event.

◆ Poll()

std::array< ControllerState, CONTROLLER_PORTS > coastline::InputBindings::Poll ( std::size_t players,
bool race ) const
Parameters
playersThe number of players the screen reads, 1 or 2. In single-player mode, devices assigned to either player drive the first port.
raceWhether a race reads the second port, through the race actions of the Controls section for a gamepad and the keyboard bindings of the PC release for the keyboard.
Returns
The state of every port, read now. The second port is connected whenever a device would drive the second of two players.

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