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

Support enum in Config::Input #40

Open
Vrixyz opened this issue Nov 9, 2022 · 9 comments · Fixed by #41 · May be fixed by #44
Open

Support enum in Config::Input #40

Vrixyz opened this issue Nov 9, 2022 · 9 comments · Fixed by #41 · May be fixed by #44
Labels
enhancement New feature or request

Comments

@Vrixyz
Copy link
Contributor

Vrixyz commented Nov 9, 2022

I would like to use enums in Config::Input to differentiate different possible inputs.

Config::Input is requiring on Pod, which has a lot of constraints, main one is that any bit patterns should be correct, making most enum potentially unfit.

The trait Pod has been split in different traits in this PR: Lokathor/bytemuck#91 ; If I'm not mistaken, ideally CheckedBitPattern should be enough.

This should enable us to have enums within Config::Input.

Somewhat related issue: Lokathor/bytemuck#84

As noted #41 (comment), I think we're dependent on bytemuck to support more than fieldless enums.

@Vrixyz Vrixyz added the enhancement New feature or request label Nov 9, 2022
@gschup
Copy link
Owner

gschup commented Nov 9, 2022

Easing the trait bounds on Input is generally good, we just have to check if this remains sound. If you are willing, you could give it a try. PRs are always welcome :)

@Vrixyz
Copy link
Contributor Author

Vrixyz commented Nov 14, 2022

I would not consider this closed until we support enum with fields 😈 ; supporting « only » fieldless enum is still quite a big restriction.

It might be possible to support enum with fields currently, but it requires unsafe code which can be hard to write, so I’m advocating for considering:

  • an example
  • a better support in bytemuck
  • some helper in ggrs

@Umatriz
Copy link

Umatriz commented Jan 28, 2024

I'm not very familiar with p2p networks. But why cant we allow sending any kind of data? Why cant we just serialize it and then deserialize?

@gschup
Copy link
Owner

gschup commented Jan 28, 2024

The constraints on the data come mostly from the compression algorithm being used. If your usecase does not fit the restrictions directly, you can always serialize your inputs outside of GGRS and create Inputs based on your serialization. One important aspect is that all inputs need to have exactly the same number of bits.

@Umatriz
Copy link

Umatriz commented Jan 28, 2024

Is there an example of such serialization?

@gschup
Copy link
Owner

gschup commented Jan 28, 2024

This input encoding example is from a much older version of GGRS, but the main idea holds:
Either use an u8/u16 where each bit represents a button being pressed or not and encode the input yourself or use a library like bincode. This example does both, which is quite unnecessary :D

Basically, if you can encode your input into a single fixed-size sequence of bits, then you are good to go. With the current GGRS you can simply define the input as a u8/u16/etc that holds these bits.

@Umatriz
Copy link

Umatriz commented Jan 28, 2024

The problem is that I want to send a position where a thing should be spawned. (I use bevy) And I have no idea how to send this position. Ans as I understand its impossible todo, because it cannot be fixed. Right?

@gschup
Copy link
Owner

gschup commented Jan 28, 2024

GGRS was built with the assumption that each client sends their inputs each frame (e.g. button inputs from a controller) and that nothing else is necessary to keep the gamestate synchronized. The framework does not have a convenient way to sync the gamestate via occasional events. It is assumed that all gamestate logic can be derived from the controller inputs (aka an input from a player under specific condition leads to an object spawning).

If you are looking for more general networking frameworks (that work via events), I recommend asking in the networking channel of the bevy discord. There are lots of great people there that can help you much better than I could!

@Umatriz
Copy link

Umatriz commented Jan 28, 2024

Okay, Thank You!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants