Help wanted with mojo joystick code!

About Monkey 2 Forums Monkey 2 Development Help wanted with mojo joystick code!

This topic contains 13 replies, has 6 voices, and was last updated by  Mark Sibly 1 year, 6 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #11552

    Mark Sibly
    Keymaster

    Hi,

    Could anyone using the latest develop version of monkey2 who has some joysticks lying around please give the ‘joystick’ banana a try and post whether it works or not below?

    In particular, I’m interested in what happens when you remove/add joysticks?

    It is working fine here, but there are reports of it crashing on Windows 10. If it crashes for you, could you please provide as much info as possible? When does it crash? When you remove a joystick? When you add a joystick? When you use a joystick? etc.

    Thanks!

    #11565

    Diffrenzy
    Keymaster

    This is as close as I’ve gotton to a reasonable crash detection. Note that this is on my own code, but I had the same error with one of the develop versions. Tell me if I need to do a different type of log/screenshot If it happens again.

    In this case I have this in my App class: App.SdlEventFilter = MySdlEventFilter , and then

    Attachments:
    #11570

    abakobo
    Participant

    After around 100 plug-unplug of two different gamepads I had no crash… Nothing except some few times the pad was not detected but I think it’s a normal usb thing when you change plugs too fast.

    #11572

    EdzUp
    Participant

    Tried with a XBox360 pad and a Pandora gamepad no crashes to report 🙂

    #11576

    Mark Sibly
    Keymaster

    In this case I have this in my App class: App.SdlEventFilter = MySdlEventFilter , and then

    This is weird because the latest code doesn’t use events at all!

    Well, nearly, I still grab jevent->which for debugging, so jevent better never be NULL.

    So some things to try: Remove ALL code from event handlers in joystick.monkey2. Check if other apps crash when joysticks are added/removed – maybe it’s an SDL event thing. Comment out stuff until it works. Stick some print statements around SDL calls – there shouldn’t be many of them left. You could also build a debug version and use gdb to debug it, but you’d have to tweak env_windows.txt a bit…Let me know if you want to try this.

    I think the approach I’m using is good – in fact, latest SDL 2.0.7 adds a function that will make it even easier.

    You could actually try latest SDL if you want, there are quite a few changes to joystick so they may have fixed something. Grab SDL 2.0.7 source from here: https://www.libsdl.org/download-2.0.php and copy the ‘include’ and ‘src’ dirs into the current sdl2/SDL dir, overwriting existing dirs (backup or whatever first!). Then, copy all the SDL_config_blah.h files from current include dir (ie: from your backup) to the new 2.0.7 include dir. Tried this yesterday and it seemed to work fine on windows, joystick and ted2go worked anyway. Much more testing to do before I can ‘officially’ upgrade sdl2 though.

    After around 100 plug-unplug of two different gamepads I had no crash…

    Thanks for super comprehensive test! I’ve also had SDL fail to register plugins a few times, but it never seems to cause any problems. Still, perhaps indicative of something bad going on in SDL, as I still get the ‘ping’ when it’s plugged in…but SDL misses it.

    Tried with a XBox360 pad and a Pandora gamepad no crashes to report 🙂

    Thanks!

    #11579

    Diffrenzy
    Keymaster

    Thanks Mark, you’ve helped this along far more than can be expected, so feel free to let it go here.

    I’m not expecting you can fix errors you can’t reproduce.

    Your GameController addition is absolutely GREAT, because mapping of buttons/axis is now a breeze with the gamepad tool.

    I’ll be looking forward to the SDL 2.0.7 fixes, and might try them out myself as you suggest, because there ARE some joystick glitches in SDL (or Windows)

    My conclusions (with two trouble makin’ controllers) for now are:

    Remove one of two controllers and SDL will send an instanceid for removal, then sometimes immediately  after a “SDL_JOYSTICKADDED”

    If you faithfully react on these events, you’ll end up with two “controllers” though only one device is plugged in.

    You can also end up with 3  “controllers” for two devices, where one physical device is mapped to two players.

    It all leads down to that  SDL is not to be trusted 100% , so some sanitizing is to be expected.

    I’ll makle sure to check for NULL events, as I am going to have a go at this approch : http://blog.5pmcasual.com/game-controller-api-in-sdl2.html and make the whole thing event based, instead of polling.

    Thanks again for your dedication and hard work!

    #11580

    Mark Sibly
    Keymaster

    No problem, I was also very interested in how well my code worked as so far it’s only had a 50% success rate!

    Up to 75% now so I feel a bit better…

    #11586

    Angus
    Participant

    Not exactly useful info here as I’m running windows 7 and it worked just fine, connecting and reconnecting joypads and joysticks.  Even an old joystick that the machine installed drivers for appeared ok.  Though it didn’t see the little hat thing at the top of the stick, not sure how unusual that is.

    A tiny thing is that the Format function seems to think numbers like 0.05 are 0.5, but it’s not exactly relevant.

    Following the instructions on the GutHub page worked nicely to make the develop version, which isn’t something I’ve done before and feels novel.  But that’s not relevant to this either sorry.

    #11592

    Diffrenzy
    Keymaster

    Just some info on SDL 2.0.7 on Mac:

    Sdl2+Mojo works out of the box, after completing the steps described above, and doing a “rebuild modules” for sdl2 and mojo.

    I tried the new SDLSDL 2.0.7 because my noname controllers are only recognised as Joysticks on Mac OS, not SDL_IsGameController(), so I can’t test the new Monkey GameController interface with them.

    If SDLGameController won’t work with these trouble makin’ controllers, maybe that’s all for the best. I’m sticking with using GameController for input from now on.

    My PS3 controller DOES work on Mac as GameController with latest Monkey develop version. 🙂

    Note however that it will show up as two controlles if it’s connected via both Bluetooth and wired.

    Only the Bluetooth instance will get input. I think this is standard behaviour, and has nothing to do with monkey.

    #11596

    DruggedBunny
    Participant

    I’ll have a go later, though I’m on 7 and only have a few Xbox360/One wired and wireless pads to try.

    #11597

    Diffrenzy
    Keymaster

    Have a go at GameController.bananas too, it would be nice to know that works  and if it detects your controlles correctly.

    #11603

    DruggedBunny
    Participant

    Working fine here on ‘7 with X360 wired controller and XB1 wireless controller — can plug/unplug repeatedly, get picked up right away and correctly noted as not present when disconnected. Both working at once.

    (Realised my 360 wireless controller doesn’t have PC interface, duh.)

    bananas\GameController looks like same thing to me, but same results there anyway!

    #11604

    abakobo
    Participant

    Yes what’s the difference between a game controller and a Joystick? I know it from the time we where playing with real sticks, but nowadays?

    #11607

    Mark Sibly
    Keymaster

    Not exactly useful info here as I’m running windows 7 and it worked just fine,

    Very useful as I now know joysticks work on window 7! Also, 80% success rate…

    Sdl2+Mojo works out of the box,

    …except for joysticks I assume? ie: joysticks are still crashing on windows 10? Or have you only tried on Macos? I’m actually more interested in Windows in this case for once!

    Working fine here on ‘7 with X360 wired controller and XB1 wireless controller

    83%!

    As for GameController, it’s actually a sort of ‘virtual’ joystick that maps a joystick’s physical axes/buttons to a fixed set of predefined ‘gamecontroller’ axes/buttons, so you can always use the same ‘button names’ no matter what device is attached. It’s something I’ve tried to do in the past in hacky ways but have never really achieved. It’s really nothing monkey2 couldn’t do on it’s own without any help from SDL though. The button/axis mappings are defined in a ‘config’ file so you can add you own mappings. There’s a public database of mappings here:

    https://github.com/gabomdq/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt

    If your gamecontroller isn’t in the database you’re kind of stuck, you ‘ll need to edit the database file. There’s a pretty cool tool to help with this though:

    http://www.generalarcade.com/gamepadtool/

    I used this to configure my unrecognized saitek controller and it worked fine. I guess the idea is to do a pull request to the public DB now…might just try creating an issue first, always balls up pull requests! I’d recommend all monkey2 users do this too if they have to add a controller, as it benefits everyone.

    The gamecontroller and joystick classes could actually be pretty easily merged, ie: I could theoretically use the gamecontroller database to auto-remap joystick axes/buttons and just ditch ‘game controllers’ altogether (now that I get how it works), although I’m OK with things the way they are right now. Thoughts?

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.