gamercade-io / gamercade_console

A Neo-Retro Fantasy Console. Make WASM-powered, networked multiplayer games.
https://gamercade.io
Apache License 2.0
166 stars 10 forks source link

Pack InputState into a 64 bits (i64) & InputState::as_raw_state() #10

Closed RobDavenport closed 1 year ago

RobDavenport commented 1 year ago

It's possible to convert the whole input state into ~60-64 bites of data. This can then be used as the return of the as_raw_state functions.

I believe it could look something like this:

This actually leaves us at 62 bits. The last two can be used to signal a bad input state, such as when the wasm requests a player_id which is out of the range of connected players.

In the future I could see some alternative version where we use only 60 bits, by removing the R2/L2 as buttons and relying on the analog trigger data. Alternatively, down to 48 bits if we just scrapped analog triggers entirely.

Long term considerations:

We also may want to allow mouse input in the long term future, so it would be good to consider how to potentilaly represent that state as 64 bits too. For example, triggers or analog inputs and giving us room for pixel-perfect UI screen coordinates for mouse (11 bits to each to support 1920 x 1080 resolution).

RobDavenport commented 1 year ago

I came across these crates which may be helpful https://crates.io/crates/deku and https://crates.io/crates/modular-bitfield

RobDavenport commented 1 year ago

Fixed in: e82f418a5d475d96b298519ca609c09d09dc238a