ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Imago::Engine::InputState Class Reference

What systems query for input (ctx.input->began("jump")). This is only for querying. The InputHandler writes it. More...

#include <Imago/Engine/InputState.hpp>

Public Member Functions

 InputState ()=default
 Construct a new InputState object.
 InputState (const InputState &)=delete
InputState & operator= (const InputState &)=delete
 InputState (InputState &&)=delete
InputState & operator= (InputState &&)=delete
ActionId action_id (const std::string &name) const
 Returns an action id from its name. Returns INVALID_ACTION for unregisterd names. Used to cache ids.
bool held (ActionId action) const
 returns true while the action is being held down. Overloaded so it can be called with an action's name or id.
bool held (const std::string &action) const
bool began (ActionId action) const
 returns true when the action started being held. Overloaded so it can be called with an action's name or id.
bool began (const std::string &action) const
bool ended (ActionId action) const
 returns true when the action stopped being held. Overloaded so it can be called with an action's name or id.
bool ended (const std::string &action) const
float strength (ActionId action) const
 returns how much the action is engaged, from 0 to 1. Overloaded so it can be called with an action's name or id.
float strength (const std::string &action) const
float axis (ActionId negative, ActionId positive) const
 Returns result of a direction from one line of input, opposite inputs of the same strength cancel out. Overloaded so it can be called with an action's name or id.
float axis (const std::string &negative, const std::string &positive) const
glm::vec2 direction (ActionId left, ActionId right, ActionId up, ActionId down) const
 Returns result of a direction in 2D from four lines of input. Overloaded so it can be called with an action's name or id.
glm::vec2 direction (const std::string &left, const std::string &right, const std::string &up, const std::string &down) const

Friends

class InputHandler
class SystemScheduler
class InputStateTestAccess

Detailed Description

What systems query for input (ctx.input->began("jump")). This is only for querying. The InputHandler writes it.

Edges (began/ended) are phase aware. In a per-fram system they are true for the frame the input arrived or left in. In a fixed system they are true for the first fixed step after it arrived or left.

Member Function Documentation

◆ action_id()

ActionId Imago::Engine::InputState::action_id ( const std::string & name) const

Returns an action id from its name. Returns INVALID_ACTION for unregisterd names. Used to cache ids.

Parameters
nameName of the action you want the id for.

◆ axis()

float Imago::Engine::InputState::axis ( ActionId negative,
ActionId positive ) const

Returns result of a direction from one line of input, opposite inputs of the same strength cancel out. Overloaded so it can be called with an action's name or id.

strength(positive) - strength(negative)

◆ direction()

glm::vec2 Imago::Engine::InputState::direction ( ActionId left,
ActionId right,
ActionId up,
ActionId down ) const

Returns result of a direction in 2D from four lines of input. Overloaded so it can be called with an action's name or id.

two axes cobined into a direction with length at most 1, so a keyboard diagonal is not faster.

◆ strength()

float Imago::Engine::InputState::strength ( ActionId action) const

returns how much the action is engaged, from 0 to 1. Overloaded so it can be called with an action's name or id.

Keyboard and mouse only give 0 or 1. If there are multiple inputs the largest one wins.


The documentation for this class was generated from the following files:
  • engine/include/Imago/Engine/InputState.hpp
  • engine/src/Engine/InputState.cpp