-
Notifications
You must be signed in to change notification settings - Fork 1
Implement input action abstraction in pad_handler #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
This additional level of indirection concerns me. Not only is it forcing a bunch of locking but also we now have two levels of map lookups that could probably just be optimized to one. |
|
Suggestion: rather than limit yourself to the design decisions of a 20 year old game with this |
008d713 to
ad8045e
Compare
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.