Merge pull request #7352 from Robyt3/Engine-Input-Antistatic

Replace static variables in `MouseRelative` with member variable
This commit is contained in:
Dennis Felsing 2023-10-15 22:29:14 +00:00 committed by GitHub
commit 0666646f40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View file

@ -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;
}

View file

@ -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];