While I'm doing that, I decided to get other bits of programming done. First, I want to get Gamepad configuration working. Basically, the player should be able to configure their gamepad controls for the game, no matter what gamepad they are using. This configuration will be saved in a text file after setup, and recalled whenever the player uses that gamepad.
This is difficult to program, as I need to find a way to make gamepad input the same, no matter how the player configured it. My first idea was to have a class with function pointers representing commands such as Up, Down, Jump, Start, etc. This way, no matter what the player set as the Jump button, I would just call the Jump boolean function pointer to see if it was input. This sounded great, but when I sat down to code it, I realized that I would have to write a different function for each possible number of gamepad sticks, hats, and buttons, so that the function pointers could have something to point to. So I had to come up with a different method, and sadly, I did not fulfill my lifelong dream of actually using a function pointer in my game code[sad]
The other, and much simpler method, is to have each of the commands represented as an abstract class PadCommand, with derived classes JoystickCommand, HatCommand, and ButtonCommand. This way I can cover any amount of sticks, hats, and buttons a gamepad could have.
One reason I wrote this is that I'm going to code this tomorrow, and I don't want to forget what I was going to do[grin]
it was something like:
So, if you assigned a keyboard key, it would look like
A joystick axis would be like:
Note that, for the value index on that, I have a flag for negative (which is the high bit, 0x80000000). If that bit is not set, then it's the positive axis. Thus, RIGHT is generally assigned to axis 0, positive and LEFT is axis 0, negative.
A joystick button would be:
So, I have an array of these (one for each control key, like Jump, Left, Right, Crouch, Attack, etc). I also had a for each, like InputDefinition::JoystickButton(0, 4); (Joystick 0, button 4).
Given that array, you could scan through to see which devices are assigned (i.e. if you have no joysticks on any controls, you don't have to poll any joysticks), to only poll the relevant devices.
Finally, to assign, it would essentially poll in a loop (for joysticks - for keyboard it'd check for windows messages), and whatever the first input was, it would build the corresponding structure and assign it.
This data was pretty easy to output to a text-based format.
You can probably make something a little cleaner than that, but that's how I did it, so that I only had to check the values of assigned buttons, and not loop through all buttons.
The downside is that it only allows one key per action, but you could theoretically make an array of up to N values for each action, so you could have 3 attack keys if you wanted (and add a third InputType_None for unassigned controls).
Hope that helps a bit, that system has worked really well for me :)