I'm (re)working on my input system and I thought "what if I decide to add controller support? How would I do it?"
Since there are so many different controllers and systems, I was thinking in a way to keep it as generic as possible to easily adapt to whatever controller available.
At first I had a bool[256] for keyboard and bool[16] for mouse, but I was worried there might be different mouses (with even more buttons) or even those multimedia keyboards with > 256 keyCodes, so I was thinking of how to deal with that.
So, the way I thought to handle this is:
class ControllerKey
{
public:
int keyID;
int keyDataPosition;
};
class Controller
{
public:
//Adds a new ControllerKey to the vector, keyType defines the size of it's data
void AddKey(int keyID, KeyTypeEnum keyType);
//Returns &_keyData[i], where _keys[i]->keyID == keyID;
char* GetKey(int keyID);
//Sets a bool value keyValue at _keys[i];
void SetKey(int keyID, bool keyValue);
//Sets a float value keyValue at _keys[i];
void SetKey(int keyID, float keyValue);
//Creates the _keyData array
void CreateController();
private:
char* _keyData;
vector<ControllerKey*> _keys;
};
So I keep a char array for a total of byte sizes equal to all keys before I "create" the controller, and when I change a value, it looks up for the keyPosition in the array and changes the address according to the keyType (4 bytes for float, 1 byte for bool).
This way I can "create" any type of controller on my game, and even filter some input that my game receives (instead of receiving all keyboard input and only using a few for example, if my game doesn't use other keys at all).
Mapping keys to actions would be done on a higher level.
I'd like to ask suggestions and opinions if this is a good idea or not, because I have no clue... I'm not sure how developers deal with different controllers/systems, and trying to google it I only found conceptual ideas on how to handle input events, not different types of input.