Luanti 5.10.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
8#include "keys.h"
9#include <bitset>
10#include <vector>
11
22
25 // -1 if to invert, 1 if to keep it.
26 int invert;
27};
28
29
31
32 virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const=0;
33
35};
36
38
39 JoystickButtonCmb() = default;
40
47
48 virtual ~JoystickButtonCmb() = default;
49
50 virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const;
51
54};
55
57
58 JoystickAxisCmb() = default;
59
67
68 virtual ~JoystickAxisCmb() = default;
69
70 bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const override;
71
73
74 // if -1, thresh must be smaller than the axis value in order to trigger
75 // if 1, thresh must be bigger than the axis value in order to trigger
77 s16 thresh;
78};
79
81 std::vector<JoystickButtonCmb> button_keys;
82 std::vector<JoystickAxisCmb> axis_keys;
85};
86
88
89public:
91
92 void onJoystickConnect(const std::vector<irr::SJoystickInfo> &joystick_infos);
93
94 bool handleEvent(const irr::SEvent::SJoystickEvent &ev);
95 void clear();
96
98 {
100 m_keys_down.reset();
101 }
102
104 {
105 bool r = m_past_keys_pressed[b];
106 m_past_keys_pressed[b] = false;
107 return r;
108 }
109
111 {
112 return m_keys_released[b];
113 }
115 {
116 m_keys_released[b] = false;
117 }
118
120 {
121 return m_keys_pressed[b];
122 }
124 {
125 m_keys_pressed[b] = false;
126 }
127
129 {
130 return m_keys_down[b];
131 }
132
134 {
135 return m_axes_vals[axis];
136 }
137
139
140 float getMovementDirection();
141 float getMovementSpeed();
142
143 u8 getJoystickId() const
144 {
145 return m_joystick_id;
146 }
147
149
150private:
151 void setLayoutFromControllerName(const std::string &name);
152
154
156
158
159 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_down;
160 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_pressed;
161
163
165
166 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_past_keys_pressed;
167 std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_released;
168};
Definition joystick_controller.h:87
bool isKeyDown(GameKeyType b)
Definition joystick_controller.h:128
s16 m_axes_vals[JA_COUNT]
Definition joystick_controller.h:155
void clearWasKeyReleased(GameKeyType b)
Definition joystick_controller.h:114
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_keys_down
Definition joystick_controller.h:159
void onJoystickConnect(const std::vector< irr::SJoystickInfo > &joystick_infos)
Definition joystick_controller.cpp:201
bool wasKeyReleased(GameKeyType b)
Definition joystick_controller.h:110
f32 doubling_dtime
Definition joystick_controller.h:148
void clear()
Definition joystick_controller.cpp:283
float getMovementDirection()
Definition joystick_controller.cpp:304
bool wasKeyDown(GameKeyType b)
Definition joystick_controller.h:103
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_keys_released
Definition joystick_controller.h:167
JoystickLayout m_layout
Definition joystick_controller.h:153
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:119
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_past_keys_pressed
Definition joystick_controller.h:166
void clearWasKeyPressed(GameKeyType b)
Definition joystick_controller.h:123
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:162
void releaseAllKeys()
Definition joystick_controller.h:97
std::bitset< KeyType::INTERNAL_ENUM_COUNT > m_keys_pressed
Definition joystick_controller.h:160
u8 m_joystick_id
Definition joystick_controller.h:157
f32 m_past_pressed_time[KeyType::INTERNAL_ENUM_COUNT]
Definition joystick_controller.h:164
u8 getJoystickId() const
Definition joystick_controller.h:143
s16 getAxis(JoystickAxis axis)
Definition joystick_controller.h:133
float getMovementSpeed()
Definition joystick_controller.cpp:310
T
Definition keys.h:13
@ INTERNAL_ENUM_COUNT
Definition keys.h:100
JoystickAxis
Definition joystick_controller.h:12
@ JA_COUNT
Definition joystick_controller.h:20
@ JA_FRUSTUM_HORIZONTAL
Definition joystick_controller.h:16
@ JA_FRUSTUM_VERTICAL
Definition joystick_controller.h:17
@ JA_FORWARD_MOVE
Definition joystick_controller.h:14
@ JA_SIDEWARD_MOVE
Definition joystick_controller.h:13
Definition joystick_controller.h:56
s16 thresh
Definition joystick_controller.h:77
int direction
Definition joystick_controller.h:76
u16 axis_to_compare
Definition joystick_controller.h:72
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:60
JoystickAxisCmb()=default
Definition joystick_controller.h:23
int invert
Definition joystick_controller.h:26
u16 axis_id
Definition joystick_controller.h:24
Definition joystick_controller.h:37
JoystickButtonCmb(GameKeyType key, u32 filter_mask, u32 compare_mask)
Definition joystick_controller.h:41
u32 filter_mask
Definition joystick_controller.h:52
virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const
Definition joystick_controller.cpp:14
u32 compare_mask
Definition joystick_controller.h:53
virtual ~JoystickButtonCmb()=default
JoystickButtonCmb()=default
Definition joystick_controller.h:30
virtual bool isTriggered(const irr::SEvent::SJoystickEvent &ev) const =0
GameKeyType key
Definition joystick_controller.h:34
Definition joystick_controller.h:80
std::vector< JoystickButtonCmb > button_keys
Definition joystick_controller.h:81
JoystickAxisLayout axes[JA_COUNT]
Definition joystick_controller.h:83
s16 axes_deadzone
Definition joystick_controller.h:84
std::vector< JoystickAxisCmb > axis_keys
Definition joystick_controller.h:82