Joystick events don't send
Joystick events don't send
I am working on getting joystick support in my game, and my receiver works with keyboard and mouse, but no joystick events are sent. I do initialize the device I have with an array for joystick state(s). But I don't ever receive any events, even though the check returns true and there is a controller found in the joystick state array. For context, my Irrlicht window is a child of a glfw window, but I have never had issues in the past with this approach.
Re: Joystick events don't send
Can you try as first step if Irrlicht example 19.MouseAndJoystick works on your system?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Joystick events don't send
Yeah it does.
Re: Joystick events don't send
Good, so works in theory :) Did you call device->activateJoysticks? Does it return true and the array contains a joystick info afterwards?
And which system (Windows/Linux) and compiler is this? (joystick has very different implementations, even Windows has 2 think).
And which system (Windows/Linux) and compiler is this? (joystick has very different implementations, even Windows has 2 think).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Joystick events don't send
Yep, activateJoysticks works and returns true. I get my controller in the array as well. Using Windows and MSVC.
Re: Joystick events don't send
Not much missing. Last part you need is to ensure device->run() is called once per frame and that should be it. Not seeing any window dependencies in code so far. What I'd do is would be to compile Irrlicht in debug and step through this in debugger once to see where it fails. Starting at device->run() - it's short function and then step into pollJoysticks.
Only place that disables _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ seems to be when compiling with Solaris, but I assume you don't have defines #if __SVR4 or __sun set anywhere (you'd probably get way more errors then).
Can you maybe post the OnEvent function of your event handler? Just in case it's some trivial bug there?
The example only checks first joystick - maybe you get events for a second one or something like that.
edit: OK, I guess that is the problem - when giving up windows loop to another gui you ususally also don't call device->run() anymore...
You can still update timer manually but calling device->run also handles sytem messages which you don't want in that case. And Joysticks have no public interface. Sorry, can't fix this in my lunch pause... will have to think about this in the evening. Either we have to add an interface (similar like for cursors) or have to add parameters to run so you can call it without handling system messages. Either way this will need some change in Irrlicht.
Only place that disables _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ seems to be when compiling with Solaris, but I assume you don't have defines #if __SVR4 or __sun set anywhere (you'd probably get way more errors then).
Can you maybe post the OnEvent function of your event handler? Just in case it's some trivial bug there?
The example only checks first joystick - maybe you get events for a second one or something like that.
edit: OK, I guess that is the problem - when giving up windows loop to another gui you ususally also don't call device->run() anymore...
You can still update timer manually but calling device->run also handles sytem messages which you don't want in that case. And Joysticks have no public interface. Sorry, can't fix this in my lunch pause... will have to think about this in the evening. Either we have to add an interface (similar like for cursors) or have to add parameters to run so you can call it without handling system messages. Either way this will need some change in Irrlicht.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Joystick events don't send
Aha! I was missing device->run. I swear I was going crazy or something. Thank you!
Re: Joystick events don't send
Yeah, but you are not missing it. Adding it when you have already another system handling windows events is bad - you don't want 2 systems competing for that. I'll check what I can do to change Irrlicht, but have to check first a bit on how Joysticks are handled on different devices in Irrlicht (I never worked with those myself so far, for some reason which I don't even remember I added SDL to the only game where I used Joysticks). I also have some washed out memories that there was once some discussion about another joystick interface back in the dark ages ...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Joystick events don't send
I see... For now it's working but I'll look into changing input to a different library or something sometime in the future...
Re: Joystick events don't send
Phew, OK... I get now why we didn't just add another function to poll/update joysticks to the IrrlichtDevice back then (we're talking about 2014). It was because we feared the IrrlichtDevice interface polluting too much (around that point we were also adding gyroscope to Android). And the idea was a common interface for io devices. Seems this planned interface change was also what was holding back merging the ogl-es branch into trunk at that time.
It is a bit work (affects Windows, Linux, SDL, MacOS). And the quickest solution might be shoddy. Either adding a function to IrrlichtDevice like updateJoysticks or pollJoysticks or sendJoystick events. Or adding a new interface IJoysticks or IJoystickController. Or the 2014 idea with another layer above it to unify all controllers, but I'm unlikely to do that.
The original discussion about this was also about events vs polling. I think Windows 98 and XP (and maybe Vista) only supported polling joysticks while Linux already had events for the buttons (so you don't risk losing inputs when users click faster than the framerate). And that was likely the reason I switched to SDL for my game, thought I probably should have given Irrlicht a shot as it likely would have been good enough (missing events is rare I think - all games used that poll interface before Windows 10 I think and many likely still do).
I had hoped I could quickly fix this, but guess not. Maybe quickest fix is adding one more function to the IrrlichtDevice and then deprecating it in future when we do the nicer interface (2038 or so...). Not something any programmer likes doing, but I guess I won't have the energy for a cleaner solution :-(
Or maybe you want to do it? I might accept patches for this...
edit: Sorry for bringing up all this old stuff. Partly summarizing it for myself. But this topic also brought back some memories as it was around that time that Hybrid stopped contributing and I think this might have been the last thing he was working on. And I still wonder if the discussion surrounding this was part of the reason he stopped (I hope it wasn't).
It is a bit work (affects Windows, Linux, SDL, MacOS). And the quickest solution might be shoddy. Either adding a function to IrrlichtDevice like updateJoysticks or pollJoysticks or sendJoystick events. Or adding a new interface IJoysticks or IJoystickController. Or the 2014 idea with another layer above it to unify all controllers, but I'm unlikely to do that.
The original discussion about this was also about events vs polling. I think Windows 98 and XP (and maybe Vista) only supported polling joysticks while Linux already had events for the buttons (so you don't risk losing inputs when users click faster than the framerate). And that was likely the reason I switched to SDL for my game, thought I probably should have given Irrlicht a shot as it likely would have been good enough (missing events is rare I think - all games used that poll interface before Windows 10 I think and many likely still do).
I had hoped I could quickly fix this, but guess not. Maybe quickest fix is adding one more function to the IrrlichtDevice and then deprecating it in future when we do the nicer interface (2038 or so...). Not something any programmer likes doing, but I guess I won't have the energy for a cleaner solution :-(
Or maybe you want to do it? I might accept patches for this...
edit: Sorry for bringing up all this old stuff. Partly summarizing it for myself. But this topic also brought back some memories as it was around that time that Hybrid stopped contributing and I think this might have been the last thing he was working on. And I still wonder if the discussion surrounding this was part of the reason he stopped (I hope it wasn't).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm