Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
joystick_controller.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2016 est31, <MTest31@outlook.com>
4
5#pragma once
6
7#include <IEventReceiver.h>
8#include "irrlichttypes.h"
9
10#include "keys.h"
11#include <bitset>
12#include <vector>
13
24
27 // -1 if to invert, 1 if to keep it.
28 int invert;
29};
30
31
33
34 virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const=0;
35
37};
38
40
41 JoystickButtonCmb() = default;
42
49
50 virtual ~JoystickButtonCmb() = default;
51
52 virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const;
53
56};
57
59
60 JoystickAxisCmb() = default;
61
69
70 virtual ~JoystickAxisCmb() = default;
71
72 bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const override;
73
75
76 // if -1, thresh must be smaller than the axis value in order to trigger
77 // if 1, thresh must be bigger than the axis value in order to trigger
79 s16 thresh;
80};
81
83 std::vector<JoystickButtonCmb> button_keys;
84 std::vector<JoystickAxisCmb> axis_keys;
87};
88
90
91public:
93
94 void onJoystickConnect(const std::vector<irr::SJoystickInfo> &joystick_infos);
95
96 bool handleEvent(const irr::SEvent::SJoystickEvent &ev);
97 void clear();
98
100 {
102 m_keys_down.reset();
103 }
104
106 {
107 bool r = m_past_keys_pressed[b];
108 m_past_keys_pressed[b] = false;
109 return r;
110 }
111
113 {
114 return m_keys_released[b];
115 }
117 {
118 m_keys_released[b] = false;
119 }
120
122 {
123 return m_keys_pressed[b];
124 }
126 {
127 m_keys_pressed[b] = false;
128 }
129
131 {
132 return m_keys_down[b];
133 }
134
136 {
137 return m_axes_vals[axis];
138 }
139
141
142 float getMovementDirection();
143 float getMovementSpeed();
144
145 u8 getJoystickId() const
146 {
147 return m_joystick_id;
148 }
149
151
152private:
153 void setLayoutFromControllerName(const std::string &name);
154
156
158
160
161 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_down;
162 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_pressed;
163
165
167
168 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_past_keys_pressed;
169 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_released;
170};
Definition joystick_controller.h:89
bool isKeyDown(GameKeyType b)
Definition joystick_controller.h:130
s16 m_axes_vals[JA_COUNT]
Definition joystick_controller.h:157
void clearWasKeyReleased(GameKeyType b)
Definition joystick_controller.h:116
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_keys_down
Definition joystick_controller.h:161
void onJoystickConnect(const std::vector< irr::SJoystickInfo > &joystick_infos)
Definition joystick_controller.cpp:201
bool wasKeyReleased(GameKeyType b)
Definition joystick_controller.h:112
f32 doubling_dtime
Definition joystick_controller.h:150
void clear()
Definition joystick_controller.cpp:283
float getMovementDirection()
Definition joystick_controller.cpp:304
bool wasKeyDown(GameKeyType b)
Definition joystick_controller.h:105
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_keys_released
Definition joystick_controller.h:169
JoystickLayout m_layout
Definition joystick_controller.h:155
float getAxisWithoutDead(JoystickAxis axis)
Definition joystick_controller.cpp:292
void setLayoutFromControllerName(const std::string &name)
Definition joystick_controller.cpp:222
bool wasKeyPressed(GameKeyType b)
Definition joystick_controller.h:121
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_past_keys_pressed
Definition joystick_controller.h:168
void clearWasKeyPressed(GameKeyType b)
Definition joystick_controller.h:125
JoystickController()
Definition joystick_controller.cpp:191
bool handleEvent(const irr::SEvent::SJoystickEvent &ev)
Definition joystick_controller.cpp:233
f32 m_internal_time
Definition joystick_controller.h:164
void releaseAllKeys()
Definition joystick_controller.h:99
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_keys_pressed
Definition joystick_controller.h:162
u8 m_joystick_id
Definition joystick_controller.h:159
f32 m_past_pressed_time[KeyType::INTERNAL_ENUM_COUNT]
Definition joystick_controller.h:166
u8 getJoystickId() const
Definition joystick_controller.h:145
s16 getAxis(JoystickAxis axis)
Definition joystick_controller.h:135
float getMovementSpeed()
Definition joystick_controller.cpp:310
T
Definition keys.h:13
@ INTERNAL_ENUM_COUNT
Definition keys.h:100
JoystickAxis
Definition joystick_controller.h:14
@ JA_COUNT
Definition joystick_controller.h:22
@ JA_FRUSTUM_HORIZONTAL
Definition joystick_controller.h:18
@ JA_FRUSTUM_VERTICAL
Definition joystick_controller.h:19
@ JA_FORWARD_MOVE
Definition joystick_controller.h:16
@ JA_SIDEWARD_MOVE
Definition joystick_controller.h:15
Definition joystick_controller.h:58
s16 thresh
Definition joystick_controller.h:79
int direction
Definition joystick_controller.h:78
u16 axis_to_compare
Definition joystick_controller.h:74
virtual ~JoystickAxisCmb()=default
bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const override
Definition joystick_controller.cpp:22
JoystickAxisCmb(GameKeyType key, u16 axis_to_compare, int direction, s16 thresh)
Definition joystick_controller.h:62
JoystickAxisCmb()=default
Definition joystick_controller.h:25
int invert
Definition joystick_controller.h:28
u16 axis_id
Definition joystick_controller.h:26
Definition joystick_controller.h:39
JoystickButtonCmb(GameKeyType key, u32 filter_mask, u32 compare_mask)
Definition joystick_controller.h:43
u32 filter_mask
Definition joystick_controller.h:54
virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const
Definition joystick_controller.cpp:14
u32 compare_mask
Definition joystick_controller.h:55
virtual ~JoystickButtonCmb()=default
JoystickButtonCmb()=default
Definition joystick_controller.h:32
virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const =0
GameKeyType key
Definition joystick_controller.h:36
Definition joystick_controller.h:82
std::vector< JoystickButtonCmb > button_keys
Definition joystick_controller.h:83
JoystickAxisLayout axes[JA_COUNT]
Definition joystick_controller.h:85
s16 axes_deadzone
Definition joystick_controller.h:86
std::vector< JoystickAxisCmb > axis_keys
Definition joystick_controller.h:84