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
8namespace input
9{
11{
12 std::map<key_code, key_state> map_;
13
14public:
15 void clear()
16 {
17 map_.clear();
18 }
19
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
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 {
59 p.second = key_state::down;
60 break;
61
63 p.second = key_state::up;
64 break;
65 default:
66 break;
67 }
68 }
69 }
70};
71} // namespace input
void set_state(key_code key, key_state state)
auto get_state(key_code key, const key_state default_state) const -> key_state
auto get_state(key_code key) const -> key_state
key_code
Definition key.hpp:6