Vulkan Schnee
0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
InputManager.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <glm/glm.hpp>
4
5
#include <cstdint>
6
#include <functional>
7
#include <string>
8
#include <unordered_map>
9
#include <vector>
10
11
namespace
Input
12
{
13
namespace
Actions
14
{
15
inline
constexpr
const
char
*
XrLeftTrigger
=
"XR.LeftTrigger"
;
16
inline
constexpr
const
char
*
XrRightTrigger
=
"XR.RightTrigger"
;
17
inline
constexpr
const
char
*
XrLeftGrip
=
"XR.LeftGrip"
;
18
inline
constexpr
const
char
*
XrRightGrip
=
"XR.RightGrip"
;
19
inline
constexpr
const
char
*
XrLeftThumbstick
=
"XR.LeftThumbstick"
;
20
inline
constexpr
const
char
*
XrRightThumbstick
=
"XR.RightThumbstick"
;
21
}
// namespace Actions
22
23
class
InputManager
24
{
25
public
:
26
enum class
DispatchRule
27
{
28
EveryFrame
,
29
Changed
,
30
Pressed
,
31
Released
,
32
};
33
34
struct
CallbackHandle
35
{
36
uint64_t
id
= 0;
37
38
[[nodiscard]]
explicit
operator
bool()
const
39
{
40
return
id
!= 0;
41
}
42
};
43
44
using
BoolProvider
= std::function<bool()>;
45
using
FloatProvider
= std::function<float()>;
46
using
Vec2Provider
= std::function<glm::vec2()>;
47
48
using
BoolCallback
= std::function<void(
bool
value )>;
49
using
FloatCallback
= std::function<void(
float
value )>;
50
using
Vec2Callback
= std::function<void( glm::vec2 value )>;
51
52
void
bindBoolAction
( std::string name,
BoolProvider
provider );
53
void
bindFloatAction
( std::string name,
FloatProvider
provider );
54
void
bindVec2Action
( std::string name,
Vec2Provider
provider );
55
56
CallbackHandle
onBoolAction
(
const
std::string & name,
DispatchRule
rule,
BoolCallback
callback );
57
CallbackHandle
onBoolPressed
(
const
std::string & name, std::function<
void
()> callback );
58
CallbackHandle
onBoolReleased
(
const
std::string & name, std::function<
void
()> callback );
59
CallbackHandle
onFloatAction
(
const
std::string & name,
DispatchRule
rule,
FloatCallback
callback );
60
CallbackHandle
onVec2Action
(
const
std::string & name,
DispatchRule
rule,
Vec2Callback
callback );
61
62
void
removeCallback
(
CallbackHandle
handle );
63
64
void
beginFrame
();
65
void
dispatchCallbacks
();
66
67
[[nodiscard]]
bool
getBoolAction
(
const
std::string & name )
const
;
68
[[nodiscard]]
float
getFloatAction
(
const
std::string & name )
const
;
69
[[nodiscard]] glm::vec2
getVec2Action
(
const
std::string & name )
const
;
70
71
private
:
72
struct
BoolCallbackEntry
73
{
74
CallbackHandle
handle
;
75
DispatchRule
rule
=
DispatchRule::EveryFrame
;
76
BoolCallback
callback
;
77
};
78
79
struct
Vec2CallbackEntry
80
{
81
CallbackHandle
handle
;
82
DispatchRule
rule
=
DispatchRule::EveryFrame
;
83
Vec2Callback
callback
;
84
};
85
86
struct
FloatCallbackEntry
87
{
88
CallbackHandle
handle
;
89
DispatchRule
rule
=
DispatchRule::EveryFrame
;
90
FloatCallback
callback
;
91
};
92
93
struct
BoolAction
94
{
95
BoolProvider
provider
;
96
bool
current
=
false
;
97
bool
previous
=
false
;
98
std::vector<BoolCallbackEntry>
callbacks
;
99
};
100
101
struct
Vec2Action
102
{
103
Vec2Provider
provider
;
104
glm::vec2
current
{ 0.0f };
105
glm::vec2
previous
{ 0.0f };
106
std::vector<Vec2CallbackEntry>
callbacks
;
107
};
108
109
struct
FloatAction
110
{
111
FloatProvider
provider
;
112
float
current
= 0.0f;
113
float
previous
= 0.0f;
114
std::vector<FloatCallbackEntry>
callbacks
;
115
};
116
117
[[nodiscard]]
CallbackHandle
makeHandle
();
118
119
std::unordered_map<std::string, BoolAction>
boolActions_
;
120
std::unordered_map<std::string, FloatAction>
floatActions_
;
121
std::unordered_map<std::string, Vec2Action>
vec2Actions_
;
122
uint64_t
nextCallbackId_
= 1;
123
bool
callbacksDispatched_
=
true
;
124
};
125
}
// namespace Input
Input::InputManager
Definition
InputManager.h:24
Input::InputManager::getBoolAction
bool getBoolAction(const std::string &name) const
Input::InputManager::onBoolAction
CallbackHandle onBoolAction(const std::string &name, DispatchRule rule, BoolCallback callback)
Input::InputManager::BoolProvider
std::function< bool()> BoolProvider
Definition
InputManager.h:44
Input::InputManager::FloatCallback
std::function< void(float value)> FloatCallback
Definition
InputManager.h:49
Input::InputManager::nextCallbackId_
uint64_t nextCallbackId_
Definition
InputManager.h:122
Input::InputManager::onVec2Action
CallbackHandle onVec2Action(const std::string &name, DispatchRule rule, Vec2Callback callback)
Input::InputManager::bindBoolAction
void bindBoolAction(std::string name, BoolProvider provider)
Input::InputManager::onFloatAction
CallbackHandle onFloatAction(const std::string &name, DispatchRule rule, FloatCallback callback)
Input::InputManager::makeHandle
CallbackHandle makeHandle()
Input::InputManager::getFloatAction
float getFloatAction(const std::string &name) const
Input::InputManager::vec2Actions_
std::unordered_map< std::string, Vec2Action > vec2Actions_
Definition
InputManager.h:121
Input::InputManager::boolActions_
std::unordered_map< std::string, BoolAction > boolActions_
Definition
InputManager.h:119
Input::InputManager::callbacksDispatched_
bool callbacksDispatched_
Definition
InputManager.h:123
Input::InputManager::floatActions_
std::unordered_map< std::string, FloatAction > floatActions_
Definition
InputManager.h:120
Input::InputManager::onBoolPressed
CallbackHandle onBoolPressed(const std::string &name, std::function< void()> callback)
Input::InputManager::bindFloatAction
void bindFloatAction(std::string name, FloatProvider provider)
Input::InputManager::getVec2Action
glm::vec2 getVec2Action(const std::string &name) const
Input::InputManager::bindVec2Action
void bindVec2Action(std::string name, Vec2Provider provider)
Input::InputManager::BoolCallback
std::function< void(bool value)> BoolCallback
Definition
InputManager.h:48
Input::InputManager::onBoolReleased
CallbackHandle onBoolReleased(const std::string &name, std::function< void()> callback)
Input::InputManager::FloatProvider
std::function< float()> FloatProvider
Definition
InputManager.h:45
Input::InputManager::beginFrame
void beginFrame()
Input::InputManager::removeCallback
void removeCallback(CallbackHandle handle)
Input::InputManager::DispatchRule
DispatchRule
Definition
InputManager.h:27
Input::InputManager::DispatchRule::Changed
@ Changed
Definition
InputManager.h:29
Input::InputManager::DispatchRule::EveryFrame
@ EveryFrame
Definition
InputManager.h:28
Input::InputManager::DispatchRule::Pressed
@ Pressed
Definition
InputManager.h:30
Input::InputManager::DispatchRule::Released
@ Released
Definition
InputManager.h:31
Input::InputManager::Vec2Callback
std::function< void(glm::vec2 value)> Vec2Callback
Definition
InputManager.h:50
Input::InputManager::Vec2Provider
std::function< glm::vec2()> Vec2Provider
Definition
InputManager.h:46
Input::InputManager::dispatchCallbacks
void dispatchCallbacks()
Input::Actions
Definition
InputManager.h:14
Input::Actions::XrRightTrigger
constexpr const char * XrRightTrigger
Definition
InputManager.h:16
Input::Actions::XrLeftTrigger
constexpr const char * XrLeftTrigger
Definition
InputManager.h:15
Input::Actions::XrLeftThumbstick
constexpr const char * XrLeftThumbstick
Definition
InputManager.h:19
Input::Actions::XrRightThumbstick
constexpr const char * XrRightThumbstick
Definition
InputManager.h:20
Input::Actions::XrLeftGrip
constexpr const char * XrLeftGrip
Definition
InputManager.h:17
Input::Actions::XrRightGrip
constexpr const char * XrRightGrip
Definition
InputManager.h:18
Input
Definition
VrGliderComponent.h:15
Input::InputManager::BoolAction
Definition
InputManager.h:94
Input::InputManager::BoolAction::provider
BoolProvider provider
Definition
InputManager.h:95
Input::InputManager::BoolAction::previous
bool previous
Definition
InputManager.h:97
Input::InputManager::BoolAction::current
bool current
Definition
InputManager.h:96
Input::InputManager::BoolAction::callbacks
std::vector< BoolCallbackEntry > callbacks
Definition
InputManager.h:98
Input::InputManager::BoolCallbackEntry
Definition
InputManager.h:73
Input::InputManager::BoolCallbackEntry::callback
BoolCallback callback
Definition
InputManager.h:76
Input::InputManager::BoolCallbackEntry::rule
DispatchRule rule
Definition
InputManager.h:75
Input::InputManager::BoolCallbackEntry::handle
CallbackHandle handle
Definition
InputManager.h:74
Input::InputManager::CallbackHandle
Definition
InputManager.h:35
Input::InputManager::FloatAction
Definition
InputManager.h:110
Input::InputManager::FloatAction::callbacks
std::vector< FloatCallbackEntry > callbacks
Definition
InputManager.h:114
Input::InputManager::FloatAction::previous
float previous
Definition
InputManager.h:113
Input::InputManager::FloatAction::current
float current
Definition
InputManager.h:112
Input::InputManager::FloatAction::provider
FloatProvider provider
Definition
InputManager.h:111
Input::InputManager::FloatCallbackEntry
Definition
InputManager.h:87
Input::InputManager::FloatCallbackEntry::handle
CallbackHandle handle
Definition
InputManager.h:88
Input::InputManager::FloatCallbackEntry::rule
DispatchRule rule
Definition
InputManager.h:89
Input::InputManager::FloatCallbackEntry::callback
FloatCallback callback
Definition
InputManager.h:90
Input::InputManager::Vec2Action
Definition
InputManager.h:102
Input::InputManager::Vec2Action::callbacks
std::vector< Vec2CallbackEntry > callbacks
Definition
InputManager.h:106
Input::InputManager::Vec2Action::provider
Vec2Provider provider
Definition
InputManager.h:103
Input::InputManager::Vec2Action::previous
glm::vec2 previous
Definition
InputManager.h:105
Input::InputManager::Vec2Action::current
glm::vec2 current
Definition
InputManager.h:104
Input::InputManager::Vec2CallbackEntry
Definition
InputManager.h:80
Input::InputManager::Vec2CallbackEntry::callback
Vec2Callback callback
Definition
InputManager.h:83
Input::InputManager::Vec2CallbackEntry::handle
CallbackHandle handle
Definition
InputManager.h:81
Input::InputManager::Vec2CallbackEntry::rule
DispatchRule rule
Definition
InputManager.h:82
Engine
include
Engine
Input
InputManager.h
Generated by
1.14.0