TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Game::InputAction Class Reference

#include <tb_input_action.hpp>

Public Member Functions

 InputAction (void)
 
 InputAction (const tbApplication::Key &keyBinding)
 
 InputAction (const InputAction &other)
 
 ~InputAction (void)
 
bool IsDown (void) const
 
bool IsPressed (void) const
 
bool IsReleased (void) const
 
float GetAnalogValue (void) const
 
bool IsAnalog (void) const
 
bool IsDigital (void) const
 
void ClearBindings (void)
 
void AddBinding (const tbApplication::Key &keyBinding)
 
void AddBinding (const tbSystem::Unstable::DeviceHandle &deviceHandle, const tbSystem::Unstable::ButtonIdentifier &button)
 
void AddAnalogBinding (const tbSystem::Unstable::DeviceHandle &deviceHandle, const tbSystem::Unstable::AxisIdentifier &axis, bool inverted=false)
 
void RemoveBinding (const tbApplication::Key &keyBinding)
 
void RemoveBinding (const tbSystem::Unstable::DeviceHandle &deviceHandle, const tbSystem::Unstable::ButtonIdentifier &button)
 
void RemoveAnalogBinding (const tbSystem::Unstable::DeviceHandle &deviceHandle, const tbSystem::Unstable::AxisIdentifier &axis)
 
void SetInputSignalConverter (InputSignalConverterInterface *signalConverter)
 
InputActionoperator= (const InputAction &other)
 

Detailed Description

An object to manage watching one-many keys to perform game actions and hide details about the bound keys from code using the action. Internally the InputAction separates Simulate step polling from Update step polling, this is to make IsPressed() or IsReleased() work for a single Simulate step vs all Simulate steps during a frame.

Note
There is a slight caveat/issue with IsPressed() or IsReleased() input potentially getting skipped from within an Simulate step, due to some frames containing 0 simulate steps.

Constructor & Destructor Documentation

TurtleBrains::Game::InputAction::InputAction ( void  )

Constructs an InputAction that contains no bindings and registers the action in a tracked list.

TurtleBrains::Game::InputAction::InputAction ( const tbApplication::Key keyBinding)
explicit

Constructs an InputAction that binds to the Key given, and registers the action in a tracked list.

Parameters
keyBindingThe Key to bind to the InputAction object during construction.
TurtleBrains::Game::InputAction::InputAction ( const InputAction other)

Copies the contents of one InputAction into this one.

Parameters
otherThe action to copy.
TurtleBrains::Game::InputAction::~InputAction ( void  )

Destroys the InputAction object and any data it contained while unregistering it from the tracked actions list.

Member Function Documentation

void TurtleBrains::Game::InputAction::AddAnalogBinding ( const tbSystem::Unstable::DeviceHandle &  deviceHandle,
const tbSystem::Unstable::AxisIdentifier &  axis,
bool  inverted = false 
)

Adds an analog axis from a controller device to the InputAction so that it will get tracked for Down, Pressed or Released events.

Parameters
deviceHandleis the handle to the controller of the axis that should be used for the action.
axisis the axis id on the controller.
invertedshould be true if the analog signal should be converted/inverted by/with the attached InputSignalConverterInterface::InvertAnalogValue().
void TurtleBrains::Game::InputAction::AddBinding ( const tbApplication::Key keyBinding)

Adds a Key binding to the InputAction so that it will get tracked for Down, Pressed or Released events.

Parameters
keyBindingThe Key to bind to the InputAction.
void TurtleBrains::Game::InputAction::AddBinding ( const tbSystem::Unstable::DeviceHandle &  deviceHandle,
const tbSystem::Unstable::ButtonIdentifier &  button 
)

Adds a button from a controller device to the InputAction so that it will get tracked for Down, Pressed or Released events.

Parameters
deviceHandleis the handle to the controller of the button that should be used for the action.
buttonis the button id on the controller.
void TurtleBrains::Game::InputAction::ClearBindings ( void  )

Removes ALL bindings from the input action so there are no keys, not controller devices or button/axis or any inputs that will trigger any of the Down, Pressed or Released events.

float TurtleBrains::Game::InputAction::GetAnalogValue ( void  ) const

Returns an analog value from 0 to 1, or some other range if custom converters change it. This value is created from digital inputs by running through DigitalToAnalogConverted() in the attached InputSignalConverterInterface().

bool TurtleBrains::Game::InputAction::IsAnalog ( void  ) const

Checks the last/most recently used binding to see if it was an axis/analog type.

bool TurtleBrains::Game::InputAction::IsDigital ( void  ) const

Checks the last/most recently used binding to see if it was a Key/Butoon digital type control.

bool TurtleBrains::Game::InputAction::IsDown ( void  ) const

This will check each of the Keys or Buttons bound to the InputAction to see if ANY are currently down, returning true if any are, or false if none are. Analog/Axis controls are also checked after running through a AnalogToDigital converter, if that was the last used binding.

bool TurtleBrains::Game::InputAction::IsPressed ( void  ) const

This will check if the previous state of the action was up from the previous polling (Simulate and Update polling are separated) and if IsDown() now returns true then IsPressed() will return true.

bool TurtleBrains::Game::InputAction::IsReleased ( void  ) const

This will check if the previous state of the action was already down from previous polling and is currently that IsDown() now returns false. If that is met, this will return true.

InputAction& TurtleBrains::Game::InputAction::operator= ( const InputAction other)

Copies the contents of one InputAction into this one.

Parameters
otherThe action to copy.
void TurtleBrains::Game::InputAction::RemoveAnalogBinding ( const tbSystem::Unstable::DeviceHandle &  deviceHandle,
const tbSystem::Unstable::AxisIdentifier &  axis 
)

Removes a specific controller button from the InputAction while keeping any other bindings as they were.

Parameters
deviceHandleis the handle to the controller of the button that should be used for the action.
axisis the axis id on the controller that should get removed from the InputAction.
void TurtleBrains::Game::InputAction::RemoveBinding ( const tbApplication::Key keyBinding)

Removes a specific Key from the InputAction while keeping any other bindings as they were.

Parameters
keyBindingThe Key binding to remove from the InputAction.
void TurtleBrains::Game::InputAction::RemoveBinding ( const tbSystem::Unstable::DeviceHandle &  deviceHandle,
const tbSystem::Unstable::ButtonIdentifier &  button 
)

Removes a specific controller button from the InputAction while keeping any other bindings as they were.

Parameters
deviceHandleis the handle to the controller of the button that should be used for the action.
buttonis the button id on the controller that should get removed from the InputAction.
void TurtleBrains::Game::InputAction::SetInputSignalConverter ( InputSignalConverterInterface signalConverter)

Allows for customized InputSignalConverter's to be used to convert from digital to analog, analog to digital or analog to analog conversions (including custom inversion). Typically one would use a custom signal converter to add deadzones or thresholds to analog controls, or create specific digital to analog routines.

Parameters
signalConverteris a pointer to the InputSignalConverterInterface object that should be used and it MUST remain in project scope until it is removed from the InputAction or it must outlive the InputAction.
Note
To remove or use the default converted, call SetInputSignalConverter(nullptr).