The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
OS X raw mouse experiment
eric.w


Joined: 12 Feb 2014
Posts: 38
Hi,

Currently, SDL_MOUSEMOTION events on OS X seem to arrive at maximum of 60Hz. I guess something in the OS is throttling them to that rate (energy saving reasons?). I thought it might be nice for FPS games to get raw mouse events, e.g. if they’re running at over 60 FPS with tearing, and I guess the OS’s throttling of mouse events to 60Hz must add some latency.

Here is an experimental patch that uses the IOHIDManager API to get raw motion events, which are used to create SDL_MOUSEMOTION events in relative mouse mode. These arrive at the full rate of the mouse (e.g. 1000Hz for my logitech g400) and have no acceleration!


Some notes on the code:
-In a first iteration, I tried running the IOHIDManager callback on the main thread. This had a problem; if you didn’t call SDL_PumpEvents often enough, some of the IOHIDManager callbacks would be lost. Presumably some internal event queue in CFRunLoop or IOHIDManager was getting filled up and dropping events?

-The ugly part of the patch is that it starts a background thread the first time you enable relative mouse mode. This just runs a CFRunLoop waiting for events from the mouse. The problem is it seems to take a fair bit of CPU time. Based on a quick look at the Xcode profiler running my project (QuakeSpasm), 15% of the cpu time was spent in the raw mouse thread, almost all of it in CFRunLoop/IOHIDManager internals, which seems pretty excessive. I guess it’s not surprising given that the events are coming at 1000Hz.

-Based on the above, I’m not sure if this is a good idea for general use. But I though I would just send it out anyway in case it’s useful to anyone.

I borrowed some of the IOHIDManager setup code from SDL_sysjoystick.c, and the IOHIDManager callback is based on the one from https://icculus.org/manymouse/ (zlib license).

Cheers,
Eric

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org