Ok, this is how it currently works. Honestly, the more I look at this solution, the less I like it (I like the general principal of generic action mapping, I just dislike my implementation; one thing I would like to add is a generic concept of controllers for both physical controllers like a keyboard, and logic controllers like an AI agent, or network stream so that they can utilise the same code path).
Code: Select all
//! Enum of your action IDs, these can be anything as long as they are unique within the key map
enum MyActionID
{
MYACTIONID_SOMETHING,
};
//! Just an example class, could be anything really
class MyClass
{
public:
MyClass()
{
// Register the S key on the keyboard to do the something action
m_inputMap.addKeyboardKey(OIS::KC_S, MYACTIONID_SOMETHING);
// Register the A button on the 0th 360 controller to do the something action
m_inputMap.addJoyStickButton(0, EXBOX360BUTTON_A, MYACTIONID_SOMETHING);
// Bound the something action to the something callback
m_inputMap.assignActionCallback(MYACTIONID_SOMETHING, TInputMapCallback(this, &CCorridorTestGame::somethingCallback));
}
void update(const float deltaTime)
{
// Each update you would call processInputMap to check the current input state and perform any callbacks
m_inputMap.processInputMap(deltaTime);
}
private:
CInputMap m_inputMap;
void somethingCallback(
const SInputMapCallbackInfo &info //!< Input info
)
{
// You would handle your input here
}
};
Now the main thing I dislike about this is that to handle any info more complex than a button press, you have to actually know what produced the input (from the callback info) which defeats the point of the abstraction. I have used
another library which got around this by using a context float value that would be set to something relevant for the input; for instance, if you bound your movement to a keyboard button and a joystick, when input was received from the button the context value would be 1.0f, but when it was received from a joystick it would be the offset of the joystick normalised between 0.0f and 1.0f. This meant to handle movement you just had to multiply your desired speed by the context float in order to get the speed the player wanted.