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

feat: set global input state, synchronize methods #1

Closed
wants to merge 22 commits into from
Closed

feat: set global input state, synchronize methods #1

wants to merge 22 commits into from

Conversation

wlsnmrk
Copy link

@wlsnmrk wlsnmrk commented Jan 10, 2024

To enable users to test that operations happen at the time they're requested, rather than at an indeterminate point in the next couple frames, this PR removes async/await from as many driver functions as practicable. This is especially useful for operations that require same-frame checks, such as Input::IsActionJustPressed/Released(). This change also speeds up many tests, since there is less waiting on the engine to process frames. Users can continue to support multi-frame tests by using the waiting extension methods themselves.

Additionally, this PR adds support/workaround for the separation of input action events and input action state in Godot 4.2, so that StartAction() and EndAction() extension methods continue to set global input state (e.g., Input::IsActionPressed()).

Exceptions to synchronization

  • ActionsControlExtensions::HoldActionFor() - requires an await to hold the action
  • KeyboardControlExtensions::HoldKeyFor() - requires an await to hold the key press
  • Camera2DDriver::MoveIntoView() and Camera2DDriver::WaitUntilSteady() - because Camera2D incorporates its own motion-easing model, it's not straightforward to eliminate asynchrony in waiting for its motion to finish. I've added a method that starts moving the camera and returns immediately, but users who want to have the camera at its new position afterwards will need to use WaitUntilSteady() themselves.
  • Fixture::AddToRoot() and dependent methods - requires waiting a frame for a new Node's _Ready() method to be called
  • Fixture cleanup actions - may require asynchronous operations (e.g., deleting a file)

Other notes

I've made TabContainerDriver methods for selecting a tab synchronous, even though Godot takes an extra frame to update content visibility. In lieu of waiting for contents to become visible, I've added a note to the documentation for tab-selection methods about this, and updated the content-visibility test to manually wait a frame after selecting a tab and before checking visibility.

BREAKING CHANGES

Most driver methods are no longer async, are void instead of returning Task (or return T instead of Task<T>), and do not have a frame delay.

Added new test input action, test scene and script with (currently
failing) tests for changes to simulation of global input state in
Godot 4.2, in which Input::ParseInputEvent() no longer sets
Input::IsActionPressed().
Updated action-input simulation extension methods to simulate global
input state in addition to events. Fixes behavior of StartAction()
and EndAction() to correctly set Input::IsActionPressed() in Godot
4.2.
Added new (currently failing) tests for
Input::IsActionJustPressed/Released(), which should be true
immediately after starting or ending an action, respectively.
To enable testing global input state immediately following inputs,
made action-input extensions synchronous, excepting HoldActionFor().
Tests for Input::IsActionJustPressed/Released() now pass.

BREAKING CHANGE: where possible, action-input methods are no longer
async, are void instead of returning Task, and have no frame delay.
BREAKING CHANGE: where possible, keyboard-input methods are no longer
async, are void instead of returning Task, and have no frame delay.
To make tests relying on mouse input more frame-accurate, made mouse-
input extensions synchronous. Set Relative property on simulated
mouse-motion events, since relative motion will no longer accumulate
in input buffer with immediate event flushing. Propagated
synchronicity to dependent driver methods and tests.

BREAKING CHANGE: mouse-input methods and many driver methods are no
longer async, are void instead of returning Task, and have no frame
delay.
To make tests relying on Control behavior more frame-accurate, made
control driver's GrabFocus() and ReleaseFocus() methods synchronous.

BREAKING CHANGE: Control driver's Grab/ReleaseFocus() methods are no
longer async, are void instead of returning Task, and have no frame
delay.
Make BaseButtonDriver::Press() synchronous and update dependent
tests.

BREAKING CHANGE: BaseButtonDriver::Press() is no longer async, is
void instead of returning Task, and has no frame delay.
Verified the return value of the Camera2DDriver::MoveIntoView()
method to ensure the camera stabilizes in its new position. Fixed
comment to reflect truth/falsity of sprite visibility.
BREAKING CHANGE: ItemList driver methods are no longer async, are
void instead of returning Task, and have no frame delay.
BREAKING CHANGE: LineEdit driver methods are no longer async, are
void instead of returning Task, and have no frame delay.
BREAKING CHANGE: OptionButtuon driver methods are no longer async,
are void instead of returning Task, and have no frame delay.
BREAKING CHANGE: PopupMenu driver methods are no longer async, are
void instead of returning Task, and have no frame delay.
BREAKING CHANGE: TextEdit driver methods are no longer async, are
void instead of returning Task, and have no frame delay.
BREAKING CHANGE: Window driver methods are no longer async, are void
instead of returning Task, and have no frame delay.
Updated description of WindowDriver::Close() to reflect that it
doesn't operate by clicking.
Also updated docs to reflect that Godot requires a frame after a tab
is selected before updating visibility of tab contents.

Also updated TabContainerDriver test to wait a frame after selecting
a tab, before checking content visibility, since the driver method no
longer has a frame delay.

BREAKING CHANGE: TabContainer driver methods are no longer async, are
void instead of returning Task, and have no frame delay.
* Changed code examples in README that no longer require async/await
* Updated description of input simulation to reflect synchrony
* Changed FAQ on asynchrony to describe it as a requirement only in
  some cases
* Pointed users toward the waiting extension examples from multiple
  other parts of README in case they need to pump frames in tests
* Removed guidance to limit state modification to the engine's
  process notifications
* Removed guidance to include frame delays in driver code, in favor
  of precise frame pumping in tests as needed
BREAKING CHANGE: Fixture::LoadScene() methods are no longer async,
return T instead of Task<T>, and have no frame delay.
Changed Fixture::AddToRoot() to wait 1 frame intead of 2 for a new
node's _Ready() to be called.
To provide a synchronous option to users, added a method to the
Camera2D driver to start moving a target position into view without
waiting for the camera's motion to finish.
@wlsnmrk
Copy link
Author

wlsnmrk commented Jan 22, 2024

Closing in favor of chickensoft-games/GodotTestDriver#1

@wlsnmrk wlsnmrk closed this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant