Unravel Engine C++ Reference
Loading...
Searching...
No Matches
key_state_map.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
key.hpp
"
4
#include "
key_state.hpp
"
5
#include <iostream>
6
#include <map>
7
8
namespace
input
9
{
10
class
key_state_map
11
{
12
std::map<key_code, key_state> map_;
13
14
public
:
15
void
clear
()
16
{
17
map_.clear();
18
}
19
20
auto
get_state
(
key_code
key
)
const
->
key_state
21
{
22
return
map_.at(
key
);
23
}
24
25
auto
get_state
(
key_code
key
,
const
key_state
default_state)
const
->
key_state
26
{
27
const
auto
&
find
= map_.find(
key
);
28
if
(
find
== map_.end())
29
{
30
return
default_state;
31
}
32
33
return
find
->second;
34
}
35
36
void
set_state
(
key_code
key
,
key_state
state)
37
{
38
const
key_state
last_state =
get_state
(
key
,
key_state::up
);
39
40
if
(state ==
key_state::pressed
)
41
{
42
if
(last_state ==
key_state::down
|| last_state ==
key_state::pressed
)
43
{
44
state =
key_state::down
;
45
}
46
}
47
48
map_[
key
] = state;
49
}
50
51
void
update
()
52
{
53
// Update Pressed and Released states to Down and Up
54
for
(
auto
&
p
: map_)
55
{
56
switch
(
p
.second)
57
{
58
case
key_state::pressed
:
59
p
.second =
key_state::down
;
60
break
;
61
62
case
key_state::released
:
63
p
.second =
key_state::up
;
64
break
;
65
default
:
66
break
;
67
}
68
}
69
}
70
};
71
}
// namespace input
input::key_state_map
Definition
key_state_map.hpp:11
input::key_state_map::set_state
void set_state(key_code key, key_state state)
Definition
key_state_map.hpp:36
input::key_state_map::get_state
auto get_state(key_code key, const key_state default_state) const -> key_state
Definition
key_state_map.hpp:25
input::key_state_map::update
void update()
Definition
key_state_map.hpp:51
input::key_state_map::get_state
auto get_state(key_code key) const -> key_state
Definition
key_state_map.hpp:20
input::key_state_map::clear
void clear()
Definition
key_state_map.hpp:15
key.hpp
key_state.hpp
input
Definition
action_id.hpp:5
input::key_state
key_state
Definition
key_state.hpp:6
input::key_state::released
@ released
input::key_state::up
@ up
input::key_state::pressed
@ pressed
input::key_state::down
@ down
input::input_type::key
@ key
input::key_code
key_code
Definition
key.hpp:6
input::key_code::p
@ p
input::key_code::find
@ find
UnravelEngine
UnravelEngine
engine
engine
input
action_map
key_state_map.hpp
Generated by
1.12.0