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

Consolidate input types to avoid portability hazards #107

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

rib
Copy link
Collaborator

@rib rib commented Aug 7, 2023

The following types have been moved from game_activity/input.rs to input.rs so they can be shared by both backends:

Axis, ButtonState, EdgeFlags, KeyAction, KeyEventFlags, Keycode, MetaState, MotionAction, MotionEventFlags

This addresses a portability hazard whereby code (such as Winit) would inadvertently use the ndk type which works OK with the native-activity backend but then wouldn't compile against the game-activity backend.

The alternative of consolidating on the ndk::events types instead was considered but we've repeatedly needed to diverge from the ndk API for the sake of maintaining a consistent input API across the game-activity and native-activity backends (input is an area where the backends differ significantly in their implementation) and so it generally seems slightly preferable to consolidate on types from this crate (though it shouldn't make much difference for these types which are almost direct bindings from ndk_sys).

The types can be converted to their ndk::events counterpart via the From trait.

For now some of the From trait implementations rely on try_from().unwrap() but the intention is to replace these with infallible implementations once we bump the MSRV > 1.66 where we can use num_enum::FromPrimitive after adding a catch-all Other(u32) to these enums.

Fixes: #92

Base automatically changed from rib/pr/game-activity-disable-get-unicode-char to main August 7, 2023 22:21
The following types have been moved from game_activity/input.rs to
input.rs so they can be shared by both backends:

Axis, ButtonState, EdgeFlags, KeyAction, KeyEventFlags, Keycode,
MetaState, MotionAction, MotionEventFlags

This addresses a portability hazard whereby code (such as Winit)
would inadvertently use the `ndk` type which works OK with the
native-activity backend but then wouldn't compile against the
game-activity backend.

The alternative of consolidating on the `ndk::events` types instead was
considered but we've repeatedly needed to diverge from the `ndk` API for
the sake of maintaining a consistent input API across the
`game-activity` and `native-activity` backends (input is an area where
the backends differ significantly in their implementation) and so it
generally seems slightly preferable to consolidate on types from this
crate (though it shouldn't make much difference for these types which
are almost direct bindings from ndk_sys).

The types can be converted to their `ndk::events` counterpart
via the `From` trait.

For now some of the `From` trait implementations rely on
`try_from().unwrap()` but the intention is to replace these with
infallible implementations once we bump the MSRV > 1.66
where we can use `num_enum::FromPrimitive` after adding a
catch-all `Other(u32)` to these enums.
@rib rib force-pushed the rib/pr/consolidate-more-input-types branch from e78ece5 to 1b33341 Compare August 15, 2023 18:31
@rib rib merged commit 379f064 into main Aug 15, 2023
3 checks passed
@rib rib deleted the rib/pr/consolidate-more-input-types branch August 15, 2023 21:08
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.

Use common Keycode type across backends
1 participant