Skip to content
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

Fully expose InputBindings to Lua #5965

Merged
merged 10 commits into from
Nov 14, 2024

Conversation

sturnclaw
Copy link
Member

Since the Input subsystem was written, we've had partial support for interacting with it from Lua code. Over time, those capabilities have been expanded, but have remained strictly read-only.

This PR changes that, providing a proper way for Lua code to register input bindings, make those bindings active and able to receive input, and listen for input events coming from those bindings.

Now, Lua code can register Action/AxisBindings at startup, create an InputFrame to make those bindings active, push that frame when appropriate, register callbacks to be called from C++ when the input binding is activated, and then pop the input frame when the bindings should no longer be receiving input.

This PR does not:

  • Provide support for Lua to add an Action/Axis binding to an InputFrame owned by C++
  • Add mechanisms to automatically push/pop InputFrames, e.g. on view change
  • Automatically clean up registered callbacks on hot-reload of the file that defined the callback
  • Migrate any existing code to use the new API

Further work by other developers would be very much appreciated to move old code using the ui.isKeyPressed() API to the new Input API, and to provide keybindings to otherwise un-bindable actions that are currently only accessible through the UI.

Copy link
Contributor

@mwerle mwerle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't pretend to understand half of this, and haven't actually tried it, but looking good.

Otsukaresamadeshita!

src/lua/LuaInput.cpp Show resolved Hide resolved
src/lua/LuaInput.cpp Outdated Show resolved Hide resolved
src/lua/LuaPiGui.cpp Show resolved Hide resolved
- Migrated from ui.keys, kept redirection assignment
- Functions querying UI key state remain in the pigui namespace
- These callbacks are unused and we typically do not have a need for an input frame owner to be notified of when someone else pushes an input frame to the stack
- Allows better identifying which input frame is currently active and is responsible for registering specific inputs
- Allows Lua to create and register InputFrames and associate input bindings with those frames
- InputFrames are automatically removed from the input stack if they go out-of-scope and are cleaned up by Lua GC
- AddActionBinding / AddAxisBinding always overwrite existing bindings
- Add separate query functions to allow determining the existence of a binding before clobbering it
- Lua can now create and register axis and action bindings.
- A warning message will be logged if a binding is attempted to be registered twice (i.e. hot-reload)
- These functions are not callbacks and are used to artificially toggle the state of an action binding from Lua
- Lua callbacks for action press/release and axis value-change events are supported
- Multiple callbacks can be registered per binding, and support is present to unregister a callback from all associated bindings
@sturnclaw sturnclaw merged commit f9e759f into pioneerspacesim:master Nov 14, 2024
4 checks passed
@sturnclaw sturnclaw deleted the lua-input-bindings branch November 14, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants