{V85A+}: Input Bottleneck in 'BBGlfwGame'

Monkey Forums/Monkey Bug Reports/{V85A+}: Input Bottleneck in 'BBGlfwGame'

ImmutableOctet(SKNG)(Posted 2015) [#1]
Hey Mark, I found a small mistake in 'BBGlfwGame::PollJoystick'... The thing is, the results are terrifying. By changing one line, I went from 100 FPS on the Mojo 2 "Hello world" example to ~3000.

GLFW unfortunately uses the old WinMM API, so calling 'glfwJoystickPresent' ends up being incredibly slow. Now, if this was called once, or on occasion, nobody would care. Except, this line says differently (Applies to GLFW3+ANGLE as well). You're apparently checking if 'port' is 0 or less than zero, which itself is pointless. I assume you meant to accesss 'pjoys', but that would still make this lag until the entire array was full. Checking on occasion, or at 'StartGame' would be a lot better. I'm not sure if that was even structured correctly, but a single call to 'glfwJoystickPresent' takes the framerate on a normal scene from 900+ FPS to somewhere between 80 and 100. Now, when it starts lagging, this becomes a serious time sink. A time sink that could actually be spent on the game, not checking for ~4 joysticks every single frame.

I suggest using a timer based on 'GetTime' (Or doing it asynchronously), that way it's not bottlenecking the entire program. The alternative would be adopting XInput on Windows, something I've already done here.

If you're not willing to fix this, I understand, but is there any chance of publicizing 'mojo.inputdevice' / making an interface? If I was able to make an XInput 'InputDevice' without editing Mojo, this wouldn't really be a problem.

EDIT: I should mention that the other GLFW commands are fine, it's just 'glfwJoystickPresent' that causes major stalls.


Nobuyuki(Posted 2015) [#2]
+1 for swapping winmm for xinput, solves some compatibility issues even if it might kill some legacy support

but even just a simple patch to fix this would be great.


marksibly(Posted 2015) [#3]
Ok, how about I add a 'CountJoysticks()' function that does the joystick detection stuff (and is called at least once for you automatically)?

xinput's definitely a good idea, but I think that's planned for glfw anyway.


ImmutableOctet(SKNG)(Posted 2015) [#4]
Sounds good to me. But maybe you should add a preprocessor macro that makes it still work the old way, if for nothing else but compatibility? Just an idea. If I had to have one change, it'd definitely be fixing this, though. Thanks, Mark.


marksibly(Posted 2015) [#5]
Ok, I've added a CountJoysticks( update:bool ) for dealing with slow winmm joystick detection. Just pushed to repos.

Use CountJoysticks( True ) to do a full recount (what's currently happening every update) and CountJoysticks( False ) to get the last count quickly,

Glfw3 only for now, will add more targets over time.