Implement input action abstraction in pad_handler #151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request implements input action abstraction in pad_handler, similar to the behavior of CPadControl in the original Dark Cloud 2. Actions can be registered with an input, and then polled at a later time.
Example usage for registering an input button action:
Example usage for polling an input button action:
Analog actions work similarly, but return the float value of a particular axis instead of a boolean digital value like buttons.
A callback function can also be optionally provided as a third argument for the registration functions, or set at a later time using
pad_set_button_action_callback(const pad_handler::button_action btn_action, std::function<void(bool pressed)> callback)/pad_set_analog_action_callback(const pad_handler::analog_action ana_action, std::function<void(f32 axis)> callback). Callback functions are invoked for buttons when the pressed state changes, while callback functions for analog are invoked with the axis value every frame.Shortcomings:
action_button/action_analogentry, including its callbacks. This means that re-registering an input may invalidate existing callbacks, so we may want to check to see if the entry already exists in the map and, if so, just updatem_input_keyandm_valuewhile preservingm_callback.