Author Topic: Problem with GETNUMJOYSTICKS() when adding gampads AFTER your app has started  (Read 4294 times)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2653
    • View Profile
Seems to be a problem with GETNUMJOYSTICKS() if you turn the gamepad on (I'm using a wireless 360 gamepad) after your app has started, it's always zero. I could tell people that it will require a restart if their gamepad is not recognised but this feels a bit clumsy.

Any tips on how to avoid this?
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4156
  • On the shoulders of giants.
    • View Profile
    • My Apps
IIRC this was always a problem on Windows (historically) in general; f you plugged in a joypad after running any program it fails to register. Had this issue with MAME BITD. Don't know if it's sorted iin newer versions of Windows though - I haven't used a pad on a pc in years.
I came. I saw. I played.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3800
    • View Profile
    • Space Fractal
Im confirm, its not a Windows issue. Im can see the way the function is used in the source code.

Take a look into this one:
http://stackoverflow.com/questions/21224023/why-does-sdl-numjoysticks-never-update

in glbasic, NumJoysticks variable is only set on init, and then SDL_NumJoysticks() is newer rechecked for any changes at all, which means its does not detect a changed connection at all.

MAME might have been did the same thing.

On Windows its not a big issue at all, but this can been more happens much more on iOS example. This feature is required to been checked for MFi controller support and is included in GameInput Api (etc a game should pause on a change example).

« Last Edit: 2016-Feb-27 by spacefractal »
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4156
  • On the shoulders of giants.
    • View Profile
    • My Apps
I note you changed your original post, which stated -

Quote
Yes, its a Windows issue. Something that can been checked on both Android and iOS. on iOS, MFI controllers might also been disconneted or connected while a app is running and require to perform a pause or such when that happens. Howover its was quite easy on iOS.

on Windows, connections is property only checked when DirectInput is init. Thun its impossible to fix it.

So dont except this can been fixed, and if its does then its would been inside GameInput Api me thinks.

It would have been best to strikethough your original commet and state that on investigation it looks like it can be fixed.

Obviously Windows has changed since I last used a pad. Hopefully it can be fixed in GLB. :)

As for MAME - no the issues back then was windows, as that never showed the joypad after it was connected after boot up either. Like I said, newer Windows versions probably fixed this.


[EDIT] But yeah, perhaps neither MAME or GLB bothered checking after initial start-up.
« Last Edit: 2016-Feb-27 by Ian Price »
I came. I saw. I played.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3800
    • View Profile
    • Space Fractal
yes, im should property posted a new post, but im was not excepted you was quite fast to post it, because im changed it quite very fast after the original post, why im edited it after checking the source code.

btw game like Witcher 3 does not have the issue, but many games does not check status after init.
« Last Edit: 2016-Feb-27 by spacefractal »
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

MrTAToad

  • Guest
Yes, most games dont check to see if the number of joysticks changes - its not particularly easy to do as such (which is probably one of the reasons most dont bother).

SDL2 does have a specific event for joysticks being added (or removed) whilst a program is running.  Note that SDL2 treats joysticks separately from game controllers

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2653
    • View Profile
OK, that's clear now. It's more of an annoyance than a bug I suppose but if it was possible to do a SDL_NumJoysticks() from a command or an inlined sub then that would be better than an app restart. I'll look into this further when my todo list shrinks a bit.

Thanks for your input guys.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2653
    • View Profile
Still looking into a solution to this. I think GLB is using DirectInput on Windows, if so, then the following article suggests using a callback for windows messaging that activates if something is plugged in or removed...

http://web.archive.org/web/20141211154922/http://www.spellofplay.com/blogs/hobbe/detecting-if-game-pad-plugged-or-removed.html
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline UBERmonkeybot

  • Mr. Polyvector
  • ***
  • Posts: 243
    • View Profile
Bigsofty did you get anywhere with this issue?

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10728
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
You have to restart the app. (shellcmd)

Offline UBERmonkeybot

  • Mr. Polyvector
  • ***
  • Posts: 243
    • View Profile