forked from Mirrorlandia_minetest/minetest
Fix some more joystick issues (#10624)
This commit is contained in:
parent
5066fe7583
commit
af22dd86e3
@ -152,6 +152,9 @@ joystick_type (Joystick type) enum auto auto,generic,xbox
|
|||||||
# when holding down a joystick button combination.
|
# when holding down a joystick button combination.
|
||||||
repeat_joystick_button_time (Joystick button repetition interval) float 0.17 0.001
|
repeat_joystick_button_time (Joystick button repetition interval) float 0.17 0.001
|
||||||
|
|
||||||
|
# The deadzone of the joystick
|
||||||
|
joystick_deadzone (Joystick deadzone) int 2048
|
||||||
|
|
||||||
# The sensitivity of the joystick axes for moving the
|
# The sensitivity of the joystick axes for moving the
|
||||||
# ingame view frustum around.
|
# ingame view frustum around.
|
||||||
joystick_frustum_sensitivity (Joystick frustum sensitivity) float 170
|
joystick_frustum_sensitivity (Joystick frustum sensitivity) float 170
|
||||||
|
@ -129,6 +129,9 @@
|
|||||||
# type: float min: 0.001
|
# type: float min: 0.001
|
||||||
# repeat_joystick_button_time = 0.17
|
# repeat_joystick_button_time = 0.17
|
||||||
|
|
||||||
|
# The deadzone of the joystick
|
||||||
|
# joystick_deadzone = 2048
|
||||||
|
|
||||||
# The sensitivity of the joystick axes for moving the
|
# The sensitivity of the joystick axes for moving the
|
||||||
# ingame view frustum around.
|
# ingame view frustum around.
|
||||||
# type: float
|
# type: float
|
||||||
|
@ -3139,8 +3139,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
|
|||||||
wasKeyDown(KeyType::DIG);
|
wasKeyDown(KeyType::DIG);
|
||||||
wasKeyDown(KeyType::PLACE);
|
wasKeyDown(KeyType::PLACE);
|
||||||
|
|
||||||
input->joystick.clearWasKeyDown(KeyType::DIG);
|
input->joystick.clearWasKeyPressed(KeyType::DIG);
|
||||||
input->joystick.clearWasKeyDown(KeyType::PLACE);
|
input->joystick.clearWasKeyPressed(KeyType::PLACE);
|
||||||
|
|
||||||
input->joystick.clearWasKeyReleased(KeyType::DIG);
|
input->joystick.clearWasKeyReleased(KeyType::DIG);
|
||||||
input->joystick.clearWasKeyReleased(KeyType::PLACE);
|
input->joystick.clearWasKeyReleased(KeyType::PLACE);
|
||||||
|
@ -279,7 +279,7 @@ public:
|
|||||||
}
|
}
|
||||||
virtual bool wasKeyPressed(GameKeyType k)
|
virtual bool wasKeyPressed(GameKeyType k)
|
||||||
{
|
{
|
||||||
return m_receiver->WasKeyPressed(keycache.key[k]) || joystick.wasKeyReleased(k);
|
return m_receiver->WasKeyPressed(keycache.key[k]) || joystick.wasKeyPressed(k);
|
||||||
}
|
}
|
||||||
virtual bool wasKeyReleased(GameKeyType k)
|
virtual bool wasKeyReleased(GameKeyType k)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ bool JoystickAxisCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const
|
|||||||
{
|
{
|
||||||
s16 ax_val = ev.Axis[axis_to_compare];
|
s16 ax_val = ev.Axis[axis_to_compare];
|
||||||
|
|
||||||
return (ax_val * direction < 0) && (thresh * direction > ax_val * direction);
|
return (ax_val * direction < -thresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// spares many characters
|
// spares many characters
|
||||||
@ -48,7 +48,7 @@ JoystickLayout create_default_layout()
|
|||||||
{
|
{
|
||||||
JoystickLayout jlo;
|
JoystickLayout jlo;
|
||||||
|
|
||||||
jlo.axes_dead_border = 1024;
|
jlo.axes_deadzone = g_settings->getU16("joystick_deadzone");
|
||||||
|
|
||||||
const JoystickAxisLayout axes[JA_COUNT] = {
|
const JoystickAxisLayout axes[JA_COUNT] = {
|
||||||
{0, 1}, // JA_SIDEWARD_MOVE
|
{0, 1}, // JA_SIDEWARD_MOVE
|
||||||
@ -93,14 +93,14 @@ JoystickLayout create_default_layout()
|
|||||||
// Now about the buttons simulated by the axes
|
// Now about the buttons simulated by the axes
|
||||||
|
|
||||||
// Movement buttons, important for vessels
|
// Movement buttons, important for vessels
|
||||||
JLO_A_PB(KeyType::FORWARD, 1, 1, 1024);
|
JLO_A_PB(KeyType::FORWARD, 1, 1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::BACKWARD, 1, -1, 1024);
|
JLO_A_PB(KeyType::BACKWARD, 1, -1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::LEFT, 0, 1, 1024);
|
JLO_A_PB(KeyType::LEFT, 0, 1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::RIGHT, 0, -1, 1024);
|
JLO_A_PB(KeyType::RIGHT, 0, -1, jlo.axes_deadzone);
|
||||||
|
|
||||||
// Scroll buttons
|
// Scroll buttons
|
||||||
JLO_A_PB(KeyType::HOTBAR_PREV, 2, -1, 1024);
|
JLO_A_PB(KeyType::HOTBAR_PREV, 2, -1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::HOTBAR_NEXT, 5, -1, 1024);
|
JLO_A_PB(KeyType::HOTBAR_NEXT, 5, -1, jlo.axes_deadzone);
|
||||||
|
|
||||||
return jlo;
|
return jlo;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ JoystickLayout create_xbox_layout()
|
|||||||
{
|
{
|
||||||
JoystickLayout jlo;
|
JoystickLayout jlo;
|
||||||
|
|
||||||
jlo.axes_dead_border = 7000;
|
jlo.axes_deadzone = 7000;
|
||||||
|
|
||||||
const JoystickAxisLayout axes[JA_COUNT] = {
|
const JoystickAxisLayout axes[JA_COUNT] = {
|
||||||
{0, 1}, // JA_SIDEWARD_MOVE
|
{0, 1}, // JA_SIDEWARD_MOVE
|
||||||
@ -146,10 +146,10 @@ JoystickLayout create_xbox_layout()
|
|||||||
JLO_B_PB(KeyType::FREEMOVE, 1 << 16, 1 << 16); // down
|
JLO_B_PB(KeyType::FREEMOVE, 1 << 16, 1 << 16); // down
|
||||||
|
|
||||||
// Movement buttons, important for vessels
|
// Movement buttons, important for vessels
|
||||||
JLO_A_PB(KeyType::FORWARD, 1, 1, 1024);
|
JLO_A_PB(KeyType::FORWARD, 1, 1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::BACKWARD, 1, -1, 1024);
|
JLO_A_PB(KeyType::BACKWARD, 1, -1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::LEFT, 0, 1, 1024);
|
JLO_A_PB(KeyType::LEFT, 0, 1, jlo.axes_deadzone);
|
||||||
JLO_A_PB(KeyType::RIGHT, 0, -1, 1024);
|
JLO_A_PB(KeyType::RIGHT, 0, -1, jlo.axes_deadzone);
|
||||||
|
|
||||||
return jlo;
|
return jlo;
|
||||||
}
|
}
|
||||||
@ -219,16 +219,19 @@ bool JoystickController::handleEvent(const irr::SEvent::SJoystickEvent &ev)
|
|||||||
|
|
||||||
for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
|
for (size_t i = 0; i < KeyType::INTERNAL_ENUM_COUNT; i++) {
|
||||||
if (keys_pressed[i]) {
|
if (keys_pressed[i]) {
|
||||||
if (!m_past_pressed_keys[i] &&
|
if (!m_past_keys_pressed[i] &&
|
||||||
m_past_pressed_time[i] < m_internal_time - doubling_dtime) {
|
m_past_pressed_time[i] < m_internal_time - doubling_dtime) {
|
||||||
m_past_pressed_keys[i] = true;
|
m_past_keys_pressed[i] = true;
|
||||||
m_past_pressed_time[i] = m_internal_time;
|
m_past_pressed_time[i] = m_internal_time;
|
||||||
}
|
}
|
||||||
} else if (m_pressed_keys[i]) {
|
} else if (m_keys_down[i]) {
|
||||||
m_past_released_keys[i] = true;
|
m_keys_released[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pressed_keys[i] = keys_pressed[i];
|
if (keys_pressed[i] && !(m_keys_down[i]))
|
||||||
|
m_keys_pressed[i] = true;
|
||||||
|
|
||||||
|
m_keys_down[i] = keys_pressed[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < JA_COUNT; i++) {
|
for (size_t i = 0; i < JA_COUNT; i++) {
|
||||||
@ -236,23 +239,22 @@ bool JoystickController::handleEvent(const irr::SEvent::SJoystickEvent &ev)
|
|||||||
m_axes_vals[i] = ax_la.invert * ev.Axis[ax_la.axis_id];
|
m_axes_vals[i] = ax_la.invert * ev.Axis[ax_la.axis_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoystickController::clear()
|
void JoystickController::clear()
|
||||||
{
|
{
|
||||||
m_pressed_keys.reset();
|
m_keys_pressed.reset();
|
||||||
m_past_pressed_keys.reset();
|
m_keys_down.reset();
|
||||||
m_past_released_keys.reset();
|
m_past_keys_pressed.reset();
|
||||||
|
m_keys_released.reset();
|
||||||
memset(m_axes_vals, 0, sizeof(m_axes_vals));
|
memset(m_axes_vals, 0, sizeof(m_axes_vals));
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 JoystickController::getAxisWithoutDead(JoystickAxis axis)
|
s16 JoystickController::getAxisWithoutDead(JoystickAxis axis)
|
||||||
{
|
{
|
||||||
s16 v = m_axes_vals[axis];
|
s16 v = m_axes_vals[axis];
|
||||||
if (((v > 0) && (v < m_layout.axes_dead_border)) ||
|
if (abs(v) < m_layout.axes_deadzone)
|
||||||
((v < 0) && (v > -m_layout.axes_dead_border)))
|
|
||||||
return 0;
|
return 0;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ struct JoystickLayout {
|
|||||||
std::vector<JoystickButtonCmb> button_keys;
|
std::vector<JoystickButtonCmb> button_keys;
|
||||||
std::vector<JoystickAxisCmb> axis_keys;
|
std::vector<JoystickAxisCmb> axis_keys;
|
||||||
JoystickAxisLayout axes[JA_COUNT];
|
JoystickAxisLayout axes[JA_COUNT];
|
||||||
s16 axes_dead_border;
|
s16 axes_deadzone;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JoystickController {
|
class JoystickController {
|
||||||
@ -111,37 +111,32 @@ public:
|
|||||||
|
|
||||||
bool wasKeyDown(GameKeyType b)
|
bool wasKeyDown(GameKeyType b)
|
||||||
{
|
{
|
||||||
bool r = m_past_pressed_keys[b];
|
bool r = m_past_keys_pressed[b];
|
||||||
m_past_pressed_keys[b] = false;
|
m_past_keys_pressed[b] = false;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
bool getWasKeyDown(GameKeyType b)
|
|
||||||
{
|
|
||||||
return m_past_pressed_keys[b];
|
|
||||||
}
|
|
||||||
void clearWasKeyDown(GameKeyType b)
|
|
||||||
{
|
|
||||||
m_past_pressed_keys[b] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wasKeyReleased(GameKeyType b)
|
bool wasKeyReleased(GameKeyType b)
|
||||||
{
|
{
|
||||||
bool r = m_past_released_keys[b];
|
return m_keys_released[b];
|
||||||
m_past_released_keys[b] = false;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
bool getWasKeyReleased(GameKeyType b)
|
|
||||||
{
|
|
||||||
return m_past_pressed_keys[b];
|
|
||||||
}
|
}
|
||||||
void clearWasKeyReleased(GameKeyType b)
|
void clearWasKeyReleased(GameKeyType b)
|
||||||
{
|
{
|
||||||
m_past_pressed_keys[b] = false;
|
m_keys_released[b] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wasKeyPressed(GameKeyType b)
|
||||||
|
{
|
||||||
|
return m_keys_pressed[b];
|
||||||
|
}
|
||||||
|
void clearWasKeyPressed(GameKeyType b)
|
||||||
|
{
|
||||||
|
m_keys_pressed[b] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isKeyDown(GameKeyType b)
|
bool isKeyDown(GameKeyType b)
|
||||||
{
|
{
|
||||||
return m_pressed_keys[b];
|
return m_keys_down[b];
|
||||||
}
|
}
|
||||||
|
|
||||||
s16 getAxis(JoystickAxis axis)
|
s16 getAxis(JoystickAxis axis)
|
||||||
@ -162,12 +157,13 @@ private:
|
|||||||
|
|
||||||
u8 m_joystick_id = 0;
|
u8 m_joystick_id = 0;
|
||||||
|
|
||||||
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_pressed_keys;
|
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_down;
|
||||||
|
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_pressed;
|
||||||
|
|
||||||
f32 m_internal_time;
|
f32 m_internal_time;
|
||||||
|
|
||||||
f32 m_past_pressed_time[KeyType::INTERNAL_ENUM_COUNT];
|
f32 m_past_pressed_time[KeyType::INTERNAL_ENUM_COUNT];
|
||||||
|
|
||||||
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_past_pressed_keys;
|
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_past_keys_pressed;
|
||||||
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_past_released_keys;
|
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_released;
|
||||||
};
|
};
|
||||||
|
@ -279,6 +279,7 @@ void set_default_settings(Settings *settings)
|
|||||||
settings->setDefault("joystick_type", "");
|
settings->setDefault("joystick_type", "");
|
||||||
settings->setDefault("repeat_joystick_button_time", "0.17");
|
settings->setDefault("repeat_joystick_button_time", "0.17");
|
||||||
settings->setDefault("joystick_frustum_sensitivity", "170");
|
settings->setDefault("joystick_frustum_sensitivity", "170");
|
||||||
|
settings->setDefault("joystick_deadzone", "2048");
|
||||||
|
|
||||||
// Main menu
|
// Main menu
|
||||||
settings->setDefault("main_menu_path", "");
|
settings->setDefault("main_menu_path", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user