Hello! This is a bit long thread about a little issue I've encountered.
Yesterday I started looking at joysticks, and how to use them in my games. I found this to be fairly easy. I made an input system so I could register new controllers fairly easy. However, a problem has come up!
In the settings in my game, you get a list of all controllers connected to your computer. So you basically just choose one, and you can play with that controller.
Right now, I have configured an XBOX360 controller and an Nintendo 64 controller. After adding the N64, I realised the problem.
I needed to know which controller was which. So I added an "id" property to my joystick class. The game would then set an "id" to each controller, so it would know which action to do.
The code to add an input looks like this, pseudocodeishly:
int ACTION_PAUSE = joystick->add_input();
joystick->add_trigger(ACTION_PAUSE, new button_press(XBOX360_BUTTON_START, CONTROLLER_XBOX360, input_state::pressed));
joystick->add_trigger(ACTION_PAUSE, new button_press(N64_BUTTON_START, CONTROLLER_N64, input_state::pressed));
joystick->add_trigger(ACTION_PAUSE, new key_press(key_return, input_state::pressed));
So it's all fine, until I realise I have to actually idenfity the controller.
What I thought first I could do was
joystick->open(controller_index, CONTROLLER_XBOX360);
Then I realised... I have no idea which controller is which.
I know I can call SDL_JoystickName for the name of the controller, but the Nintendo 64 controller, which I can use through an adapter, names the controller for "USB Controller". I have two of those, as there are two ports in the adapter. So what if I get, let's say, a GC adapter, and use a GC controller. Then I get possibly another "USB Controller" name. So I can't just use that name to identify the controller.
Also, I noticed that an XBOX360 controller of a friend of mine was a special one with a unique name. So I can't even see which is which of the same type.
So I'm wondering if there is a way to figure it out?
I thought of making a function that checks how many buttons, axes, hats and balls the controller has - but what if it's a special-made N64 controller? I saw one online that had special buttons on it. Regardless of that, it's a stupid idea anyway, lol.
So yeah, any thoughts?
Thanks in advance.