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

Input buffering framework + Leverage on Android #51597

Merged
merged 4 commits into from
Aug 13, 2021

Conversation

RandomShaper
Copy link
Member

@RandomShaper RandomShaper commented Aug 12, 2021

Forward port of #42220 + #51601 to 4.0.

UPDATE:
Smoke tested on the Windows editor and the Android multitouch view test project. Everything seems fine.
Regarding the real benefits, they should be the same as in the 3.x version, but it's not easy to test.

@RandomShaper RandomShaper added this to the 4.0 milestone Aug 12, 2021
@RandomShaper RandomShaper changed the title Input buffering Input buffering framework + Leverage on Android Aug 13, 2021
@RandomShaper RandomShaper requested a review from m4gr3d August 13, 2021 00:29
@RandomShaper RandomShaper marked this pull request as ready for review August 13, 2021 00:29
@RandomShaper RandomShaper requested review from a team as code owners August 13, 2021 00:29
@akien-mga
Copy link
Member

The classref needs to be synced to fix ordering and a syntax error (missing </member>):
https://github.com/godotengine/godot/runs/3317681823
https://github.com/godotengine/godot/runs/3317681832

- API has been simplified: all events now go through `parse_input_event()`. Whether they are accumulated or not depends on the `use_accumulated_input` flag.
- Event accumulation is now thread-safe (it was not needed so far, but it prepares the ground for the following changes).
- Touch drag events now support accumulation.
Input buffering is implicitly used by event accumulation, but this commit makes it more generic so it can be enabled for other uses.

For desktop OSs it's currently not feasible given main and UI threads are the same).
If enabled, key/touch/joystick events will be flushed just before every idle and physics frame.

Enabling this can greatly improve the responsiveness to input, specially in devices that need to run multiple physics frames per each idle frame, because of not being powerful enough to run at the target frame rate.

This will only work for platforms using input buffering (regardless event accumulation). Currenly, only Android does so, but could be implemented for iOS in an upcoming PR.
Key, touch and joystick events will be passed directly from the UI thread to Godot, so they can benefit from agile input flushing.

As another consequence of this new way of passing events, less Java object are created at runtime (`Runnable`), which is good since the garbage collector needs to run less.

`AndroidInputHandler` is introduced to have a smaller cross-thread surface. `main_loop_request_go_back()` is removed in favor just inline calling `send_window_event()` at the most caller's convenience (i.e., leveraging the new `p_deferred`` parameter as appropriate).

Lastly, `get_mouse_position()` and `get_mouse_button_state()` now just call through `Input` to avoid the need of sync of mouse data tracked on the UI thread.
@akien-mga akien-mga merged commit 3a3be76 into godotengine:master Aug 13, 2021
@akien-mga
Copy link
Member

Thanks!

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.

3 participants