Jerky/jittering mouse movement

Hi,

ioQuake3 is an open source 3D shooter project that has recently moved to
SDL for handling input and such, but the problem is that jerky mouse
movement was introduced. For example, it’s highly noticable when moving
in circles, like around a column in a room.

In my test case, on Windows XP, I capped the game at 7 frames per
second, moved the mouse at a constant speed to the right (for that, I
used a script program called AutoIT3), and noted the relative movement
received from the event system.

When I only moved the mouse, I got continuous movement data (positive
relative x motion values for every frame): 13 13 13 14 13 13 13 14 13 13
13 14.
But when I held down a keyboard key, mouse movement was weird: 3 2 13 2
13 2 1 1 13 2 1 2 13 2 1 2 1 2 1 2 1 3 13 9 14 (key repeats were
disabled, so I still received exactly 1 mouse event per frame).
It seems that somehow, holding a key “chops down” some of the mouse motion.
I even moved the mouse by hand (while holding a keyboard key): 32 3 20
29 16 4 31 3 1 3 31 3 39 6 41 4 34 6 3 3 1 7 2 4 56 9 4 5 32 13 3 (some
minor y-axis movement omitted)
Finally, the jerk lowers as the FPS value increases, at 125 FPS it’s not
noticable: 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 2 1

The SDL version used by the game is not the latest one. So just today I
checked out the latest SDL-1.2, and tried to statically link that. I’m
not sure if I did everything correctly, I just packed a bunch of related
SDL .c files into the project, and some dinput8.lib and guid?.lib into
the build project. The in-game movement sensitivity changes as I change
the settings in the operating system, so the game isn’t getting the raw
data.

Previously (before SDL), the game had the option to natively use either
DirectInput or basic Win32 input methods, which worked. In both cases, I
could not reproduce the mouse jittering, which makes me think that SDL
is behind it.

Could some SDL expert please look at this issue? Thx!

<asd1234qwerty gmail.com> writes:

Hi,

ioQuake3 is an open source 3D shooter project that has recently moved to
SDL for handling input and such, but the problem is that jerky mouse
movement was introduced. For example, it’s highly noticable when moving
in circles, like around a column in a room.

In my test case, on Windows XP, I capped the game at 7 frames per
second, moved the mouse at a constant speed to the right (for that, I
used a script program called AutoIT3), and noted the relative movement
received from the event system.

When I only moved the mouse, I got continuous movement data (positive
relative x motion values for every frame): 13 13 13 14 13 13 13 14 13 13
13 14.
But when I held down a keyboard key, mouse movement was weird: 3 2 13 2
13 2 1 1 13 2 1 2 13 2 1 2 1 2 1 2 1 3 13 9 14 (key repeats were
disabled, so I still received exactly 1 mouse event per frame).
It seems that somehow, holding a key “chops down” some of the mouse motion.
I even moved the mouse by hand (while holding a keyboard key): 32 3 20
29 16 4 31 3 1 3 31 3 39 6 41 4 34 6 3 3 1 7 2 4 56 9 4 5 32 13 3 (some
minor y-axis movement omitted)
Finally, the jerk lowers as the FPS value increases, at 125 FPS it’s not
noticable: 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 2 1

The SDL version used by the game is not the latest one. So just today I
checked out the latest SDL-1.2, and tried to statically link that. I’m
not sure if I did everything correctly, I just packed a bunch of related
SDL .c files into the project, and some dinput8.lib and guid?.lib into
the build project. The in-game movement sensitivity changes as I change
the settings in the operating system, so the game isn’t getting the raw
data.

Previously (before SDL), the game had the option to natively use either
DirectInput or basic Win32 input methods, which worked. In both cases, I
could not reproduce the mouse jittering, which makes me think that SDL
is behind it.

Could some SDL expert please look at this issue? Thx!

I’ve experienced this problem with cursors too, if you’re using a custom cursor
( an image blitted at the position of the cursor ) or just the normal cursor,
you could try putting a SDL_Delay(2) at each event reading, it might look
strange to put a delay there, but usually it helps smooth out the mouse, it
worked fine in OpenGL too for me, which also had mouse jittering.

If you’re using an image that is drawn at the mouse cursor, and you have to get
the mouse position to update its x and y width, use SDL_GetMouseState(x, y) to
get the positions of the mouse, avoid using event::button::x and
event::button::y since they’re just much slower, plus you have to pass the
event structure around each time.

Hopefully this was of some help,
Creature

Creature wrote:

<asd1234qwerty gmail.com> writes:

Hi,

ioQuake3 is an open source 3D shooter project that has recently moved to
SDL for handling input and such, but the problem is that jerky mouse
movement was introduced. For example, it’s highly noticable when moving
in circles, like around a column in a room.

In my test case, on Windows XP, I capped the game at 7 frames per
second, moved the mouse at a constant speed to the right (for that, I
used a script program called AutoIT3), and noted the relative movement
received from the event system.

When I only moved the mouse, I got continuous movement data (positive
relative x motion values for every frame): 13 13 13 14 13 13 13 14 13 13
13 14.
But when I held down a keyboard key, mouse movement was weird: 3 2 13 2
13 2 1 1 13 2 1 2 13 2 1 2 1 2 1 2 1 3 13 9 14 (key repeats were
disabled, so I still received exactly 1 mouse event per frame).
It seems that somehow, holding a key “chops down” some of the mouse motion.
I even moved the mouse by hand (while holding a keyboard key): 32 3 20
29 16 4 31 3 1 3 31 3 39 6 41 4 34 6 3 3 1 7 2 4 56 9 4 5 32 13 3 (some
minor y-axis movement omitted)
Finally, the jerk lowers as the FPS value increases, at 125 FPS it’s not
noticable: 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 2 1

The SDL version used by the game is not the latest one. So just today I
checked out the latest SDL-1.2, and tried to statically link that. I’m
not sure if I did everything correctly, I just packed a bunch of related
SDL .c files into the project, and some dinput8.lib and guid?.lib into
the build project. The in-game movement sensitivity changes as I change
the settings in the operating system, so the game isn’t getting the raw
data.

Previously (before SDL), the game had the option to natively use either
DirectInput or basic Win32 input methods, which worked. In both cases, I
could not reproduce the mouse jittering, which makes me think that SDL
is behind it.

Could some SDL expert please look at this issue? Thx!

I’ve experienced this problem with cursors too, if you’re using a custom cursor
( an image blitted at the position of the cursor ) or just the normal cursor,
you could try putting a SDL_Delay(2) at each event reading, it might look
strange to put a delay there, but usually it helps smooth out the mouse, it
worked fine in OpenGL too for me, which also had mouse jittering.

It’s not about cursors, the mouse is hidden and grabbed. It’s about
getting accurate movement data from SDL, which seems to be bugged.
SDL_Delay(2) didn’t do anything but lagged the game at the event system
polls by 2msec every frame.

If you’re using an image that is drawn at the mouse cursor, and you have to get
the mouse position to update its x and y width, use SDL_GetMouseState(x, y) to
get the positions of the mouse, avoid using event::button::x and
event::button::y since they’re just much slower, plus you have to pass the
event structure around each time.

Using events, SDL_GetRelativeMouseState(dx, dy) or SDL_GetMouseState(x,
y) yielded exactly the same data, and I wouldn’t even expect that such
would differ.

Hopefully this was of some help,
Creature

Oh well, thanks anyway.

Update: as keyboard keys seem to randomly chop down mouse movement,
mouse clicks also have the effect tempering with it, but in contrast,
they mostly increase movement.

Some thought that on slow computers this effect originated from the
relatively small SDL event queue, in which events were simply dropped.
In my test case, I have changed MAXEVENTS from 128 to 16384 to make sure
that the queue will never fill up.

Short on replies I’ve looked into the SDL code and traced the “chopped
data” coming from the window manager. WinMessage() receives inaccurate
data from lParam along with WM_MOVEMOUSE. I tried to use the
GetCursorPos() method to see if it differs, and surprisingly it does
seem to get the accurate data. Attached is a patch showing what I did.
With it, there is no more distortion in the mouse movement. I still
don’t know why this works better, there’s nothing about this on MSDN.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: sdl-wm_movemouse.patch
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080718/7e03e8fb/attachment.txt