Skip to content

Commit

Permalink
Consolidate input types to avoid portability hazards
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rib committed Aug 7, 2023
1 parent 6b33074 commit e78ece5
Show file tree
Hide file tree
Showing 6 changed files with 696 additions and 623 deletions.
Loading

0 comments on commit e78ece5

Please sign in to comment.