From 9cbbc0aca6d9aa1e11738135bf5cd2f66d7f72dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 15 Oct 2023 20:35:25 +0200 Subject: [PATCH] Replace static variables in `MouseRelative` with member variable Avoid using a global variable for last mouse position on Android. --- src/engine/client/input.cpp | 21 ++++++++------------- src/engine/client/input.h | 3 +++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/engine/client/input.cpp b/src/engine/client/input.cpp index 4db6e7a44..7d9b63ab8 100644 --- a/src/engine/client/input.cpp +++ b/src/engine/client/input.cpp @@ -259,23 +259,18 @@ bool CInput::MouseRelative(float *pX, float *pY) if(!m_MouseFocus || !m_InputGrabbed) return false; - int nx = 0, ny = 0; + ivec2 Relative; #if defined(CONF_PLATFORM_ANDROID) // No relative mouse on Android - static int s_LastX = 0; - static int s_LastY = 0; - SDL_GetMouseState(&nx, &ny); - int XTmp = nx - s_LastX; - int YTmp = ny - s_LastY; - s_LastX = nx; - s_LastY = ny; - nx = XTmp; - ny = YTmp; + ivec2 CurrentPos; + SDL_GetMouseState(&CurrentPos.x, &CurrentPos.y); + Relative = CurrentPos - m_LastMousePos; + m_LastMousePos = CurrentPos; #else - SDL_GetRelativeMouseState(&nx, &ny); + SDL_GetRelativeMouseState(&Relative.x, &Relative.y); #endif - *pX = nx; - *pY = ny; + *pX = Relative.x; + *pY = Relative.y; return *pX != 0.0f || *pY != 0.0f; } diff --git a/src/engine/client/input.h b/src/engine/client/input.h index 9de494c20..b0576b52c 100644 --- a/src/engine/client/input.h +++ b/src/engine/client/input.h @@ -77,6 +77,9 @@ private: bool m_MouseFocus; bool m_MouseDoubleClick; +#if defined(CONF_PLATFORM_ANDROID) // No relative mouse on Android + ivec2 m_LastMousePos = ivec2(0, 0); +#endif // IME support char m_aComposition[MAX_COMPOSITION_ARRAY_SIZE];