1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

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)
This commit is contained in:
fgenesis 2022-05-04 03:04:26 +02:00
parent e32603e6c0
commit 764d106d50

View file

@ -1259,7 +1259,7 @@ bool Core::doMouseConstraint()
{ {
Vector h = mouseConstraintCenter; Vector h = mouseConstraintCenter;
Vector d = mouse.position - h; 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); d.setLength2D(mouseCircle);
mouse.position = h+d; mouse.position = h+d;
@ -1313,15 +1313,8 @@ void Core::onEvent(const SDL_Event& event)
{ {
if (focus && updateMouse) if (focus && updateMouse)
{ {
mouse.lastPosition = mouse.position;
mouse.position.x = ((event.motion.x) * (float(virtualWidth)/float(getWindowWidth()))) - getVirtualOffX(); mouse.position.x = ((event.motion.x) * (float(virtualWidth)/float(getWindowWidth()))) - getVirtualOffX();
mouse.position.y = event.motion.y * (float(virtualHeight)/float(getWindowHeight())); mouse.position.y = event.motion.y * (float(virtualHeight)/float(getWindowHeight()));
mouse.change = mouse.position - mouse.lastPosition;
if (doMouseConstraint())
setMousePosition(mouse.position);
} }
} }
break; break;
@ -1421,10 +1414,19 @@ void Core::pollEvents(float dt)
mouse.scrollWheelChange = 0; mouse.scrollWheelChange = 0;
mouse.change = Vector(0,0); mouse.change = Vector(0,0);
mouse.lastPosition = mouse.position;
} }
window->handleInput(); window->handleInput();
if(updateMouse)
{
if (doMouseConstraint())
setMousePosition(mouse.position);
mouse.change = mouse.position - mouse.lastPosition;
}
for(size_t i = 0; i < joysticks.size(); ++i) for(size_t i = 0; i < joysticks.size(); ++i)
if(joysticks[i]) if(joysticks[i])
joysticks[i]->update(dt); joysticks[i]->update(dt);