Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::shmup::ShipControls Class Reference

The controls of a player ship: arrows move it and Space fires, or a gamepad's D-pad or left stick and its South button (A, Cross) or right trigger. More...

#include <aegis2d/shmup/ship_controls.hpp>

Public Member Functions

 ShipControls ()
 Declares the ship's actions with their default keys, auto-fire off.
 
platform::ActionMap & actions () noexcept
 The ship's actions, to rebind them or show them (platform::control_lines()).
 
const platform::ActionMap & actions () const noexcept
 The ship's actions, to rebind them or show them (platform::control_lines()).
 
platform::ActionId id (ecs::Action action) const noexcept
 Identifier of one of the ship's actions in actions().
 
platform::LatchedAction & auto_fire () noexcept
 The auto-fire option of the fire action.
 
const platform::LatchedAction & auto_fire () const noexcept
 The auto-fire option of the fire action.
 
std::uint8_t update (const platform::Keyboard &keyboard)
 Reads the frame and tells which actions are held.
 
std::uint8_t update (const platform::Keyboard &keyboard, const platform::Gamepad &gamepad)
 Reads the frame on the keyboard and the gamepad, and tells which actions are held on either.
 
std::uint8_t held () const noexcept
 The result of the last update().
 
void load (const core::Config &settings, std::string_view input, std::string_view auto_fire, std::string_view gamepad={})
 Reads the player's key and button bindings and auto-fire option.
 
void save (core::Config &settings, std::string_view input, std::string_view auto_fire, std::string_view gamepad={}) const
 Writes the key and button bindings and the auto-fire option into the player's settings.
 

Detailed Description

The controls of a player ship: arrows move it and Space fires, or a gamepad's D-pad or left stick and its South button (A, Cross) or right trigger.

Declares the actions "up", "down", "left", "right" and "fire" with the subject's default keys and gamepad buttons; the player can rebind them (platform::ActionMap, platform::KeyCapture) and turn auto-fire on (platform::LatchedAction). Each frame, update() gives the held actions as the byte the client sends to the server, the keyboard and the gamepad together:

controls.load(settings, "input", "accessibility.auto_fire", "gamepad");
...
window.poll_events();
registry.get<ecs::PlayerInput>(ship).held =
controls.update(window.keyboard(), window.gamepad());
The controls of a player ship: arrows move it and Space fires, or a gamepad's D-pad or left stick and...
Definition ship_controls.hpp:40
void load(const core::Config &settings, std::string_view input, std::string_view auto_fire, std::string_view gamepad={})
Reads the player's key and button bindings and auto-fire option.
Definition ship_controls.hpp:104
std::uint8_t update(const platform::Keyboard &keyboard)
Reads the frame and tells which actions are held.
Definition ship_controls.hpp:72
std::uint8_t held() const noexcept
The result of the last update().
Definition ship_controls.hpp:95
Actions a player holds during the tick, as received from its client.
Definition components.hpp:184

Constructor & Destructor Documentation

◆ ShipControls()

aegis2d::shmup::ShipControls::ShipControls ( )
inline

Declares the ship's actions with their default keys, auto-fire off.

Member Function Documentation

◆ actions() [1/2]

const platform::ActionMap & aegis2d::shmup::ShipControls::actions ( ) const
inlinenoexcept

The ship's actions, to rebind them or show them (platform::control_lines()).

Returns
The action map.

◆ actions() [2/2]

platform::ActionMap & aegis2d::shmup::ShipControls::actions ( )
inlinenoexcept

The ship's actions, to rebind them or show them (platform::control_lines()).

Returns
The action map.

◆ auto_fire() [1/2]

const platform::LatchedAction & aegis2d::shmup::ShipControls::auto_fire ( ) const
inlinenoexcept

The auto-fire option of the fire action.

Returns
The latch that holds fire without its key when the option is on.

◆ auto_fire() [2/2]

platform::LatchedAction & aegis2d::shmup::ShipControls::auto_fire ( )
inlinenoexcept

The auto-fire option of the fire action.

Returns
The latch that holds fire without its key when the option is on.

◆ held()

std::uint8_t aegis2d::shmup::ShipControls::held ( ) const
inlinenoexcept

The result of the last update().

Returns
The held actions as ecs::Action bits; 0 before the first update.

◆ id()

platform::ActionId aegis2d::shmup::ShipControls::id ( ecs::Action  action) const
inlinenoexcept

Identifier of one of the ship's actions in actions().

Parameters
actionAction of the ship.
Returns
Its ActionId.

◆ load()

void aegis2d::shmup::ShipControls::load ( const core::Config &  settings,
std::string_view  input,
std::string_view  auto_fire,
std::string_view  gamepad = {} 
)
inline

Reads the player's key and button bindings and auto-fire option.

Parameters
settingsSettings read with platform::read_settings().
inputSection of the key bindings, such as "input" (see platform::ActionMap::load()).
auto_firePath of the auto-fire option, such as "accessibility.auto_fire".
gamepadSection of the gamepad bindings, such as "gamepad" (see platform::ActionMap::load_buttons()); empty to keep the default buttons.

◆ save()

void aegis2d::shmup::ShipControls::save ( core::Config &  settings,
std::string_view  input,
std::string_view  auto_fire,
std::string_view  gamepad = {} 
) const
inline

Writes the key and button bindings and the auto-fire option into the player's settings.

Parameters
settingsSettings to update, then saved with core::Config::save().
inputSection of the key bindings.
auto_firePath of the auto-fire option.
gamepadSection of the gamepad bindings; empty not to write them.

◆ update() [1/2]

std::uint8_t aegis2d::shmup::ShipControls::update ( const platform::Keyboard &  keyboard)
inline

Reads the frame and tells which actions are held.

Call it once per frame, after Window::poll_events().

Parameters
keyboardState of the keyboard, usually Window::keyboard().
Returns
The held actions, one ecs::Action bit each: the value of ecs::PlayerInput::held.

◆ update() [2/2]

std::uint8_t aegis2d::shmup::ShipControls::update ( const platform::Keyboard &  keyboard,
const platform::Gamepad &  gamepad 
)
inline

Reads the frame on the keyboard and the gamepad, and tells which actions are held on either.

Call it once per frame, after Window::poll_events().

Parameters
keyboardState of the keyboard, usually Window::keyboard().
gamepadState of the gamepads, usually Window::gamepad().
Returns
The held actions, one ecs::Action bit each.

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