macosgamecontrollergcmouse

GCMouse input buffering and latency


I've connected a callback to my GCMouse like so:

mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY) {
  info( "Mouse moved %f %f", deltaX, deltaY );
};

However, the output seems to be being buffered, and being sent to my program in huge spurts (no events for a few seconds, then ~1000 events in one game frame)

Log message format is: [ type ][ thread ][ time ][ Frame Number ]: (..message..)

[ ⚪️ Info ][ M-300977600 ][ 21:23:19 ][ 449 ]:  Mouse moved 1.000000 -0.000000
connect_block_invoke InputMan_Mac.mm @ 46

[ ⚪️ Info ][ M-300977600 ][ 21:23:19 ][ 449 ]:  Mouse moved 1.000000 -0.000000
connect_block_invoke InputMan_Mac.mm @ 46

[ ⚪️ Info ][ M-300977600 ][ 21:23:19 ][ 449 ]:  Mouse moved 0.000000 1.000000
connect_block_invoke InputMan_Mac.mm @ 46


... ~500 move events, all in frame 449:

[ ⚪️ Info ][ M-300977600 ][ 21:23:20 ][ 533 ]:  Mouse moved 2.000000 1.000000
connect_block_invoke InputMan_Mac.mm @ 46

[ ⚪️ Info ][ M-300977600 ][ 21:23:20 ][ 533 ]:  Mouse moved 4.000000 2.000000
connect_block_invoke InputMan_Mac.mm @ 46

[ ⚪️ Info ][ M-300977600 ][ 21:23:20 ][ 533 ]:  Mouse moved 8.000000 4.000000
connect_block_invoke InputMan_Mac.mm @ 46

... ~ 200 move events, all in frame 533

[ ⚪️ Info ][ M-300977600 ][ 21:23:25 ][ 1169 ]:  Mouse moved 2.000000 -14.000000
connect_block_invoke InputMan_Mac.mm @ 46

[ ⚪️ Info ][ M-300977600 ][ 21:23:25 ][ 1169 ]:  Mouse moved 2.000000 -8.000000
connect_block_invoke InputMan_Mac.mm @ 46

[ ⚪️ Info ][ M-300977600 ][ 21:23:25 ][ 1169 ]:  Mouse moved 1.000000 -7.000000
connect_block_invoke InputMan_Mac.mm @ 46

... hundreds of events all in frame 1169 ...


Is there a setting or something that I can disable the input buffering? I want the input immediately. I am able to get input thru Cocoa messages without any latency whatsoever


Solution

  • You should set the GCMouse.handlerQueue to a higher priority queue than the main queue

    mouse.handlerQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    

    The default queue that events are being processed on is dispatch_get_main_queue(), which is actually quite slow to process events on

    Note that doing this puts your input handler callback onto a background thread (whereas without editing the handler queue the default is to put the input onto the main thread)