From 764d106d507ac07c5ced97abe5e24ea1cd716529 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Wed, 4 May 2022 03:04:26 +0200 Subject: [PATCH] Work around issues with SDL_WarpMouse() in SDL > 2.0.20 Without this and using an affected SDL version, the song circle is all jittery; the mouse cursor appears to really like to stick to notes in the left half of the circle. This issue first appeared in SDL commit 82793ac279d19b5 and caused the entire game to hang (infinitely firing mouse motion events); SDL commit 31f8c3ef4409a93fa fixed the hang but instead made SDL_WarpCursor() jittery. (Also see SDL commit 331859079674465 for a follow-up) --- BBGE/Core.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 4517a36..c4c9ff3 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -1259,7 +1259,7 @@ bool Core::doMouseConstraint() { Vector h = mouseConstraintCenter; Vector d = mouse.position - h; - if (!d.isLength2DIn(mouseCircle)) + if (!d.isLength2DIn(mouseCircle + 1)) // Only move mouse if it'll actually move (works around issues in SDL > 2.0.20) { d.setLength2D(mouseCircle); mouse.position = h+d; @@ -1313,15 +1313,8 @@ void Core::onEvent(const SDL_Event& event) { if (focus && updateMouse) { - mouse.lastPosition = mouse.position; - mouse.position.x = ((event.motion.x) * (float(virtualWidth)/float(getWindowWidth()))) - getVirtualOffX(); mouse.position.y = event.motion.y * (float(virtualHeight)/float(getWindowHeight())); - - mouse.change = mouse.position - mouse.lastPosition; - - if (doMouseConstraint()) - setMousePosition(mouse.position); } } break; @@ -1421,10 +1414,19 @@ void Core::pollEvents(float dt) mouse.scrollWheelChange = 0; mouse.change = Vector(0,0); + mouse.lastPosition = mouse.position; } window->handleInput(); + if(updateMouse) + { + if (doMouseConstraint()) + setMousePosition(mouse.position); + + mouse.change = mouse.position - mouse.lastPosition; + } + for(size_t i = 0; i < joysticks.size(); ++i) if(joysticks[i]) joysticks[i]->update(dt);