My goal is to be able to bind multiple actions to a single method call, but be able to differentiate between the different actions for a skill bar based game. The player has skills 1-8, which are each bound to a separate key on the keyboard. I would like to avoid having separate method calls for each ability, as that seems like a messy way to structure code.
My first idea was to use std::bind
and bind the single method with a parameter that specifies which skill index was pressed. For example I would have a OnAbilityPressed(int AbilityIndex)
which I would bind each action with a different argument number. Unfortunately BindAction(...)
is not compatible with std::bind
.
My second idea was to use axis events. I would have an Axis event for using abilities, with the scale bound to each ability index. For example, the key ‘1’ would have a scale of 1, ‘2’ would have a scale of 2, etc. and I would parse those in the event. However, I learned that axis events are additive, which would cause problems tracking Pressed and Released events when the player is pressing multiple keys at once. The solution to this problem would be to use bitmasks, each scale value would have to be a power of two and I would use fancy bitwise math to parse the events. This seemed like a complex solution to such a simple problem, not to mention there may be performance issues since axis events are polled every frame.
Is there another solution I am missing, or am I stuck with one of these solutions?