Repository navigation
P3: Stop scripted button presses repeating in Lua additive button mode - #8074
Open
dustinspace217 wants to merge 1 commit into
Open
dustinspace217 wants to merge 1 commit into
dustinspace217 wants to merge 1 commit into
Conversation
In LUA_ADDITIVE_BUTTON_CONTROL mode, game_process_keys merged the script's buttons into the player's and then copied the merged result back into the script's buffer, so any press (the player's or the script's) stayed set and fired again every frame. Clear the script's buffer after the merge instead, so a scripted press acts once like a key press. Scripts set buttons from hooks that run after game_process_keys, so their presses are still merged on the next call before the clear. Fixes scp-fs2open#4108
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
In
LUA_ADDITIVE_BUTTON_CONTROLmode, a button press now acts once instead of repeating forever.Why?
With a script that turns on additive button mode, pressing almost any key (target next ship, ETS, countermeasure) makes the action repeat on its own every frame (the report says it even carries into the next mission). One press of T in the first FS2 mission kept cycling the target through every ship. A scripted press from
useButtonControldoes the same thing. The only way out today is for the script to callclearLuaButtonInfoevery frame.How?
After the script's buttons are merged into the player's, the script's buffer is cleared instead of having the merged result copied back into it. Scripts set buttons from hooks that run after
game_process_keys, so a scripted press still gets merged on the next frame before the clear. That answers the worry in the issue thread that clearing it would disable scripted controls. A button a script wants held still has to be set every frame, same as with the workaround, and scripts that already callclearLuaButtonInfoevery frame keep sending buttons as before. From reading the code, a press made right as a mission ends now fires once in the next mission instead of forever.One change for scripts that read buttons: in additive mode,
getButtonInfo/accessButtonInfono longer show the player's own presses, only what the script has set since the last frame. Before, they showed the merged bits, which never cleared. That includes workaround scripts that read the buttons before clearing them: they now see only their own bits. From reading the code,pollAllButtonsstill reports the player's buttons (I didn't run it). Normal and override modes are untouched.Testing?
Release and Debug builds on Fedora, 0 compiler warnings in both; unit tests 358 passed, 1 skipped. Master (94d278a; the Debug comparison used the commit before it) vs this branch (cdf7b09), OpenGL, 1280x720, mission SM1-01, MediaVPs 5.0.3 plus the GOTY Mission Pack 1.0.3 (MediaVPs 5.0.3 requires it), and a test mod holding only this table (the issue's script plus a frame hook that counts target changes):
useButtonControl(-1, "TARGET_NEXT"): master kept cycling, branch changed once.getButtonInfoin the same frame sees it set; it reads clear after the merge, with one target change.-vulkanwith the T press test: same result as OpenGL.Anything Else?
I used Claude Code to help write and test this.
Fixes #4108