devkitPro / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
15 stars 12 forks source link

[joystick] Wii: introduce split-joysticks option #30

Closed mardy closed 4 months ago

mardy commented 1 year ago

Add an option to present the Wii controller expansions as independent controllers.

Introduce the SDL_WII_JOYSTICK_SPLIT environment variable, which, if set to "1" before initializing the joystick subsystem, changes the number of reported joysticks from 8 to 12:

This is for the benefits of those applications which need to alter their behaviour depending on the controller that generated the event, or even to increase the number of possible players in a game, assuming that it needs just the directional keys and a couple of buttons.

Due to the refactoring, some changes were made to the default non-split view of the controllers, a couple of which are actually bugfixes:

All these changes can be easily tested with this application; both modes of operation can be tested, just by commenting out the

setenv("SDL_WII_JOYSTICK_SPLIT", "1", 1);

line in the init() function, if you want to check the non-split functionality. The application can also be built against the devkitPro version of the SDL, for a comparison. Please let me know if you'd like the binary DOL file for quicker testing.

WinterMute commented 11 months ago

It seems kind of odd to me to treat wiimote expansions as separate joysticks. What's the reasoning for this?

For behaviour of wiimotes with expansions it's probably worth looking at what official games typically do. We should probably look into figuring out some kind of guidelines for controller usage (as Nintendo do although clearly we don't need to be as proscriptive) It also seems slightly odd to have wiimote buttons produce the same events as attached classic controllers. Have you looked at how official games use expansions?

I think there are too many changes here for a single commit. The axis reset seems like an obvious fix that can & should be a single commit.

mardy commented 11 months ago

It seems kind of odd to me to treat wiimote expansions as separate joysticks. What's the reasoning for this?

It is odd indeed, and as far as I know no official game uses this: my guess is that for safety reasons Nintendo prohibited (or at least discouraged) this usage of controllers, because if players get too excited they could make some movements that would pull the cord a bit too much and damage it (or the connector).

There are, anyway, a few requests for this feature (a quick search led me to this and this. In my case, I'm developing a simple top-down car game (https://gitlab.com/mardy/wicked-sliders) which can be played with just the directional arrows and two buttons, so this feature would allow local multiplayer even for people that have just a wiimote + expansion.

I understand that it's not a common use case, but that's why I'm hiding it behind an environment variable.

I think there are too many changes here for a single commit. The axis reset seems like an obvious fix that can & should be a single commit.

I agree. I'll file a separate PR for that. As for the split-joystick functionality, it's already part of the SDL2 port that I'm working on :-)

halotroop2288 commented 10 months ago

This sometimes makes sense for Classic Controllers but not for the Nunchuck.

It would be very nice to be able to play multiplayer on simple d-pad + 2 button games using just a Wiimote and Wii Classic (Pro) Controller or (S)NES Classic controller.

But it would also make backwards compatibility quite awkward for games that would otherwise fit fine into the standard Wiimote and Nunchuck configuration. Consider that some engines which might implement SDL might not have the ability to treat multiple gamepads as one input device, or might abstract that information away from the engine user and make it confusing to develop for.

mardy commented 10 months ago

It would be very nice to be able to play multiplayer on simple d-pad + 2 button games using just a Wiimote and Wii Classic (Pro) Controller or (S)NES Classic controller.

Indeed. For the nunchuck this is much less useful, as you rightfully pointed out, but there are still games that can be played with just a directional control and two buttons (I'm working on one at the moment, and that's what inspired this PR).

But it would also make backwards compatibility quite awkward for games that would otherwise fit fine into the standard Wiimote and Nunchuck configuration. Consider that some engines which might implement SDL might not have the ability to treat multiple gamepads as one input device, or might abstract that information away from the engine user and make it confusing to develop for.

I'm fully away of this, and that's why this split behaviour is only activated if the game sets an environment variable; otherwise, you'll get the normal behaviour.

mardy commented 6 months ago

I updated the branch to work with the consolidated joystick code.