4 #include <SDL3/SDL_scancode.h>
5 #include <SDL3/SDL_mouse.h>
6 #include <SDL3/SDL_events.h>
7 #include <SDL3/SDL_gamepad.h>
9#include "IInputListener.hpp"
10#include "SpinLock.hpp"
12#include "DataStructures.hpp"
13#include <RavEngine/mathtypes.hpp>
27 MOUSEMOVE_XVEL = -502,
28 MOUSEMOVE_YVEL = -503,
31 CONTROLLER_AXIS_OFFSET = -8000,
32 CONTROLLER_BUTTON_OFFSET = -10000
39 SDL_CONTROLLER_BUTTON_INVALID = -1,
40 SDL_CONTROLLER_BUTTON_A = Special::CONTROLLER_BUTTON_OFFSET,
41 SDL_CONTROLLER_BUTTON_B,
42 SDL_CONTROLLER_BUTTON_X,
43 SDL_CONTROLLER_BUTTON_Y,
44 SDL_CONTROLLER_BUTTON_BACK,
45 SDL_CONTROLLER_BUTTON_GUIDE,
46 SDL_CONTROLLER_BUTTON_START,
47 SDL_CONTROLLER_BUTTON_LEFTSTICK,
48 SDL_CONTROLLER_BUTTON_RIGHTSTICK,
49 SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
50 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
51 SDL_CONTROLLER_BUTTON_DPAD_UP,
52 SDL_CONTROLLER_BUTTON_DPAD_DOWN,
53 SDL_CONTROLLER_BUTTON_DPAD_LEFT,
54 SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
55 SDL_CONTROLLER_BUTTON_MAX
62 SDL_CONTROLLER_AXIS_INVALID = -1,
63 SDL_CONTROLLER_AXIS_LEFTX = Special::CONTROLLER_AXIS_OFFSET,
64 SDL_CONTROLLER_AXIS_LEFTY,
65 SDL_CONTROLLER_AXIS_RIGHTX,
66 SDL_CONTROLLER_AXIS_RIGHTY,
67 SDL_CONTROLLER_AXIS_TRIGGERLEFT,
68 SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
69 SDL_CONTROLLER_AXIS_MAX
102 constexpr inline CID operator | (CID lhs, CID rhs)
104 using T = std::underlying_type_t<CID>;
105 return static_cast<CID
>(
static_cast<T
>(lhs) |
static_cast<T
>(rhs));
108 constexpr inline CID& operator |= (CID& lhs, CID rhs)
113 constexpr inline CID operator & (CID lhs, CID rhs)
115 using T = std::underlying_type_t<CID>;
116 return static_cast<CID
>(
static_cast<T
>(lhs) &
static_cast<T
>(rhs));
119 constexpr inline CID& operator &= (CID& lhs, CID rhs)
129 constexpr inline static CID Make_CID(
int x){
130 return static_cast<CID
>(1 << x);
133 typedef Function<void(
float)> axisCallback;
134 typedef Function<void()> actionCallback;
141 void* func_addr =
nullptr;
177 return controller == other.controller && state == other.state &&
id == other.id && func_addr == other.func_addr;
184 void* func_addr =
nullptr;
207 if ((controller &
c_in) != CID::NONE && IsValid()){
208 func(std::abs(value) >= deadzone ? value : 0);
211 inline bool IsValid()
const{
216 constexpr inline bool operator==(
const AxisBinding& other)
const{
217 return deadzone == other.deadzone && controller == other.controller &&
id == other.id && func_addr == other.func_addr;
223 locked_hashmap<int, locked_hashset<std::string,SpinLock>,SpinLock> CodeToAction;
225 locked_hashmap<std::string, LinkedList<ActionBinding>,SpinLock> ActionBindings;
228 std::string identifier;
233 inline std::size_t operator()(
const AxisID& other)
const{
234 std::hash<std::string> hasher;
235 return hasher(other.identifier);
240 inline bool operator()(
const AxisID& A,
const AxisID& B)
const{
241 return A.identifier == B.identifier && A.scale == B.scale;
249 CID source_controller;
299 CodeToAction[Id].insert(name);
308 inline void AddAxisMap(
const std::string& name,
int Id,
float scale = 1){
309 CodeToAxis[Id].insert({name,scale});
318 CodeToAction[Id].erase(name);
326 inline void RemoveAxisMap(
const std::string& name,
int Id,
float scale = 1){
327 CodeToAxis[Id].erase({name, scale});
337 template<
class U,
typename T>
339 auto binding = [=]()
mutable{
344 ActionBindings[name].push_back(ab);
354 template<
typename U,
typename T>
356 auto func = [=](
float amt)
mutable{
361 AxisBindings[name].bindings.push_back(ab);
371 template<
typename U,
typename T>
373 auto binding = [=](){
378 ActionBindings[name].remove(ab);
387 template<
typename U,
typename T>
389 auto func = [=](
float amt){
394 AxisBindings[name].bindings.remove(ab);
401 AnyEventBindings.push_back(
listener);
Definition SpinLock.hpp:9
Definition concurrentqueue.h:747
Definition Animation.hpp:6
Definition InputManager.hpp:60
Definition InputManager.hpp:74
Definition InputManager.hpp:23
Definition qualifier.hpp:35