Browse Source

Fix some more joystick issues (#10624)

pull/10727/head
Markus 4 months ago
committed by GitHub
parent
commit
af22dd86e3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 48 deletions
  1. +3
    -0
      builtin/settingtypes.txt
  2. +3
    -0
      minetest.conf.example
  3. +2
    -2
      src/client/game.cpp
  4. +1
    -1
      src/client/inputhandler.h
  5. +26
    -24
      src/client/joystick_controller.cpp
  6. +17
    -21
      src/client/joystick_controller.h
  7. +1
    -0
      src/defaultsettings.cpp

+ 3
- 0
builtin/settingtypes.txt View File

@@ -152,6 +152,9 @@ joystick_type (Joystick type) enum auto auto,generic,xbox
# when holding down a joystick button combination.
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
# ingame view frustum around.
joystick_frustum_sensitivity (Joystick frustum sensitivity) float 170


+ 3
- 0
minetest.conf.example View File

@@ -129,6 +129,9 @@
# type: float min: 0.001
# repeat_joystick_button_time = 0.17

# The deadzone of the joystick
# joystick_deadzone = 2048

# The sensitivity of the joystick axes for moving the
# ingame view frustum around.
# type: float


+ 2
- 2
src/client/game.cpp View File

@@ -3139,8 +3139,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
wasKeyDown(KeyType::DIG);
wasKeyDown(KeyType::PLACE);

input->joystick.clearWasKeyDown(KeyType::DIG);
input->joystick.clearWasKeyDown(KeyType::PLACE);
input->joystick.clearWasKeyPressed(KeyType::DIG);
input->joystick.clearWasKeyPressed(KeyType::PLACE);

input->joystick.clearWasKeyReleased(KeyType::DIG);
input->joystick.clearWasKeyReleased(KeyType::PLACE);


+ 1
- 1
src/client/inputhandler.h View File

@@ -279,7 +279,7 @@ public:
}
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)
{


+ 26
- 24
src/client/joystick_controller.cpp View File

@@ -37,7 +37,7 @@ bool JoystickAxisCmb::isTriggered(const irr::SEvent::SJoystickEvent &ev) const
{
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
@@ -48,7 +48,7 @@ JoystickLayout create_default_layout()
{
JoystickLayout jlo;

jlo.axes_dead_border = 1024;
jlo.axes_deadzone = g_settings->getU16("joystick_deadzone");

const JoystickAxisLayout axes[JA_COUNT] = {
{0, 1}, // JA_SIDEWARD_MOVE
@@ -93,14 +93,14 @@ JoystickLayout create_default_layout()
// Now about the buttons simulated by the axes

// Movement buttons, important for vessels
JLO_A_PB(KeyType::FORWARD, 1, 1, 1024);
JLO_A_PB(KeyType::BACKWARD, 1, -1, 1024);
JLO_A_PB(KeyType::LEFT, 0, 1, 1024);
JLO_A_PB(KeyType::RIGHT, 0, -1, 1024);
JLO_A_PB(KeyType::FORWARD, 1, 1, jlo.axes_deadzone);
JLO_A_PB(KeyType::BACKWARD, 1, -1, jlo.axes_deadzone);
JLO_A_PB(KeyType::LEFT, 0, 1, jlo.axes_deadzone);
JLO_A_PB(KeyType::RIGHT, 0, -1, jlo.axes_deadzone);

// Scroll buttons
JLO_A_PB(KeyType::HOTBAR_PREV, 2, -1, 1024);
JLO_A_PB(KeyType::HOTBAR_NEXT, 5, -1, 1024);
JLO_A_PB(KeyType::HOTBAR_PREV, 2, -1, jlo.axes_deadzone);
JLO_A_PB(KeyType::HOTBAR_NEXT, 5, -1, jlo.axes_deadzone);

return jlo;
}
@@ -109,7 +109,7 @@ JoystickLayout create_xbox_layout()
{
JoystickLayout jlo;

jlo.axes_dead_border = 7000;
jlo.axes_deadzone = 7000;

const JoystickAxisLayout axes[JA_COUNT] = {
{0, 1}, // JA_SIDEWARD_MOVE
@@ -146,10 +146,10 @@ JoystickLayout create_xbox_layout()
JLO_B_PB(KeyType::FREEMOVE, 1 << 16, 1 << 16); // down

// Movement buttons, important for vessels
JLO_A_PB(KeyType::FORWARD, 1, 1, 1024);
JLO_A_PB(KeyType::BACKWARD, 1, -1, 1024);
JLO_A_PB(KeyType::LEFT, 0, 1, 1024);
JLO_A_PB(KeyType::RIGHT, 0, -1, 1024);
JLO_A_PB(KeyType::FORWARD, 1, 1, jlo.axes_deadzone);
JLO_A_PB(KeyType::BACKWARD, 1, -1, jlo.axes_deadzone);
JLO_A_PB(KeyType::LEFT, 0, 1, jlo.axes_deadzone);
JLO_A_PB(KeyType::RIGHT, 0, -1, jlo.axes_deadzone);

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++) {
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_keys[i] = true;
m_past_keys_pressed[i] = true;
m_past_pressed_time[i] = m_internal_time;
}
} else if (m_pressed_keys[i]) {
m_past_released_keys[i] = true;
} else if (m_keys_down[i]) {
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++) {
@@ -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];
}


return true;
}

void JoystickController::clear()
{
m_pressed_keys.reset();
m_past_pressed_keys.reset();
m_past_released_keys.reset();
m_keys_pressed.reset();
m_keys_down.reset();
m_past_keys_pressed.reset();
m_keys_released.reset();
memset(m_axes_vals, 0, sizeof(m_axes_vals));
}

s16 JoystickController::getAxisWithoutDead(JoystickAxis axis)
{
s16 v = m_axes_vals[axis];
if (((v > 0) && (v < m_layout.axes_dead_border)) ||
((v < 0) && (v > -m_layout.axes_dead_border)))
if (abs(v) < m_layout.axes_deadzone)
return 0;
return v;
}

+ 17
- 21
src/client/joystick_controller.h View File

@@ -96,7 +96,7 @@ struct JoystickLayout {
std::vector<JoystickButtonCmb> button_keys;
std::vector<JoystickAxisCmb> axis_keys;
JoystickAxisLayout axes[JA_COUNT];
s16 axes_dead_border;
s16 axes_deadzone;
};

class JoystickController {
@@ -111,37 +111,32 @@ public:

bool wasKeyDown(GameKeyType b)
{
bool r = m_past_pressed_keys[b];
m_past_pressed_keys[b] = false;
bool r = m_past_keys_pressed[b];
m_past_keys_pressed[b] = false;
return r;
}
bool getWasKeyDown(GameKeyType b)

bool wasKeyReleased(GameKeyType b)
{
return m_past_pressed_keys[b];
return m_keys_released[b];
}
void clearWasKeyDown(GameKeyType b)
void clearWasKeyReleased(GameKeyType b)
{
m_past_pressed_keys[b] = false;
m_keys_released[b] = false;
}

bool wasKeyReleased(GameKeyType b)
bool wasKeyPressed(GameKeyType b)
{
bool r = m_past_released_keys[b];
m_past_released_keys[b] = false;
return r;
}
bool getWasKeyReleased(GameKeyType b)
{
return m_past_pressed_keys[b];
return m_keys_pressed[b];
}
void clearWasKeyReleased(GameKeyType b)
void clearWasKeyPressed(GameKeyType b)
{
m_past_pressed_keys[b] = false;
m_keys_pressed[b] = false;
}

bool isKeyDown(GameKeyType b)
{
return m_pressed_keys[b];
return m_keys_down[b];
}

s16 getAxis(JoystickAxis axis)
@@ -162,12 +157,13 @@ private:

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_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_released_keys;
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_past_keys_pressed;
std::bitset<KeyType::INTERNAL_ENUM_COUNT> m_keys_released;
};

+ 1
- 0
src/defaultsettings.cpp View File

@@ -279,6 +279,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("joystick_type", "");
settings->setDefault("repeat_joystick_button_time", "0.17");
settings->setDefault("joystick_frustum_sensitivity", "170");
settings->setDefault("joystick_deadzone", "2048");

// Main menu
settings->setDefault("main_menu_path", "");


Loading…
Cancel
Save