From d7f9da49eb3766ab3f23684eed1e3bf655842a43 Mon Sep 17 00:00:00 2001 From: grorp Date: Sun, 5 May 2024 13:28:50 +0200 Subject: [PATCH] Fix shootline not being updated if press and release happen in the same step (#14606) --- src/gui/touchscreengui.cpp | 4 +++- src/gui/touchscreengui.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index d35d6f18d..2a2fa36ed 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -703,6 +703,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_move_pos = touch_pos; // DON'T reset m_tap_state here, otherwise many short taps // will be ignored if you tap very fast. + m_had_move_id = true; } } } @@ -821,13 +822,14 @@ void TouchScreenGUI::step(float dtime) // Note that the shootline isn't used if touch_use_crosshair is enabled. // Only updating when m_has_move_id means that the shootline will stay at // it's last in-world position when the player doesn't need it. - if (!m_draw_crosshair && m_has_move_id) { + if (!m_draw_crosshair && (m_has_move_id || m_had_move_id)) { v2s32 pointer_pos = getPointerPos(); m_shootline = m_device ->getSceneManager() ->getSceneCollisionManager() ->getRayFromScreenCoordinates(pointer_pos); } + m_had_move_id = false; } void TouchScreenGUI::resetHotbarRects() diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 014cb6fef..ca6c05e18 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -259,6 +259,9 @@ private: u64 m_move_downtime = 0; // m_move_pos stays valid even after m_move_id has been released. v2s32 m_move_pos; + // This is needed so that we don't miss if m_has_move_id is true for less + // than one client step, i.e. press and release happen in the same step. + bool m_had_move_id = false; bool m_has_joystick_id = false; size_t m_joystick_id;