Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
InputRegistry Class Reference

#include <input.hpp>

Public Member Functions

int actionAddEvent (const std::string &name, std::unique_ptr< InputEvent > event)
 
void actionRemoveEvent (const std::string &action, int index)
 
void actionRemoveEvents (const std::string &action)
 
float actionGetDeadzone (const std::string &action) const
 
std::vector< InputEventactionGetEvents (std::string action)
 
void actionSetDeadzone (const std::string &action, float deadzone)
 
void addAction (const std::string &action, float deadzone=0.1f)
 
void removeAction (const std::string &action)
 
bool eventIsAction (const InputEvent *event, const std::string &name, bool identityCheck=false)
 
std::vector< std::string > getActions ()
 
bool hasAction (const std::string &action) const
 
std::unordered_map< std::string, InputRegistryAction > * getActionsArray ()
 

Detailed Description

InputRegistry

The InputRegistry allows you to define actions which are binded to specific events (like, for example InputEventKey). Once you add an action, you can bind an event to it using actionAddEvent().

// Add an action called "left" which is binded to a InputEventControllerMotion event. This action has a deadzone of 0.2f
InputRegistry.addAction("left", 0.2f);
auto leftEvent = std::make_unique<InputEventControllerMotion>();
leftEvent->device = 0;
leftEvent->axis = ControllerAxis::LEFT_X;
leftEvent->motion = -1.0f;
inputRegistry.actionAddEvent("left", std::move(leftEvent));
Definition input.hpp:227
void addAction(const std::string &action, float deadzone=0.1f)
Definition input.cpp:337

Once you do that, you can check on a scripts input function if the event is a specific action:

void input(InputEvent &event)
{
if(event.isActionPressed("left")) { // Since the action has
// code here
}
}
Definition input.hpp:62
bool isActionPressed(const std::string &action) const
Definition input.cpp:517

Make sure to also check out the input example!

Member Function Documentation

◆ actionAddEvent()

int InputRegistry::actionAddEvent ( const std::string &  name,
std::unique_ptr< InputEvent event 
)

◆ actionGetDeadzone()

float InputRegistry::actionGetDeadzone ( const std::string &  action) const

◆ actionGetEvents()

std::vector< InputEvent > InputRegistry::actionGetEvents ( std::string  action)

◆ actionRemoveEvent()

void InputRegistry::actionRemoveEvent ( const std::string &  action,
int  index 
)

◆ actionRemoveEvents()

void InputRegistry::actionRemoveEvents ( const std::string &  action)

◆ actionSetDeadzone()

void InputRegistry::actionSetDeadzone ( const std::string &  action,
float  deadzone 
)

◆ addAction()

void InputRegistry::addAction ( const std::string &  action,
float  deadzone = 0.1f 
)

◆ eventIsAction()

bool InputRegistry::eventIsAction ( const InputEvent event,
const std::string &  name,
bool  identityCheck = false 
)

◆ getActions()

std::vector< std::string > InputRegistry::getActions ( )

◆ getActionsArray()

std::unordered_map< std::string, InputRegistryAction > * InputRegistry::getActionsArray ( )

◆ hasAction()

bool InputRegistry::hasAction ( const std::string &  action) const

◆ removeAction()

void InputRegistry::removeAction ( const std::string &  action)

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