-
Notifications
You must be signed in to change notification settings - Fork 33
Use Bevy state API for client and server states #487
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
Conversation
This allows users to utilize things like `StateScoped` and run systems more efficiently using `OnEnter` or `OnExit` without evaluating conditions every frame. As a result, we now require `StatesPlugin` to be present. It's included by default in `DefaultPlugins`, but with `MinimalPlugins` you have to add it manually. In tests, I had to add `StatesPlugin` everywhere. This also changes the behavior a little bit: - On disconnect, we still apply all received messages and disconnect only after that, because the `StateTransitions` schedule runs right after `PreUpdate`. But I think this behavior is actually better. - We no longer check if `RepliconClient` or `RepliconServer` can actually accept messages. I currently preserved the original behavior where we reset them after exiting `Connected` or `Running`. But it might be worth considering doing a reset on exiting `Disconnected` or `Stopped` to ensure a clean start, like we did with events. I would appreciate opinions on this. Fix formatting Fix tests
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #487 +/- ##
==========================================
+ Coverage 81.16% 81.69% +0.52%
==========================================
Files 52 51 -1
Lines 2989 2922 -67
==========================================
- Hits 2426 2387 -39
+ Misses 563 535 -28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate what this PR is trying to do, but don't like the loss of precision it causes.
- In
bevy_replicon_renet2
we have this sequence of systems. As soon as the backend connects a client, any packets that show up after that are immediately read into the replicon client. With this PR, there will be a 1-tick delay in reading those packets. - In my
bevy_girk
backend, I have a delicate setup for advancing my own states. With this PR, the precision of that setup is reduced since every transition will waste a tick (and overlap with my custom states erroneously).
.add_systems( | ||
OnExit(ClientState::Connected), | ||
reset.in_set(ClientSet::Reset), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not equivalent. client_just_disconnected
also encompasses the connecting -> disconnected sequence.
.add_systems( | ||
OnEnter(ClientState::Connected), | ||
reset.in_set(ClientSet::ResetEvents), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
Those are valid concerns! Let's see if it's possible to address them. I see 3 options:
I'm currently leaning toward option 3. Maybe you have other ideas? Closing the PR is also an option 🙂 |
I don't think we should split behavior between replicon internals and the user-facing API. It can lead to subtle bugs and inefficiencies. What we have right now works even though it's a bit ugly. So I'm in favor of closing the PR. |
I think I may have phrased it poorly - it shouldn't split the behavior. Let me expand this idea a little bit more:
But I'd implement steps 1-2 in a separate PR to minimize conflicts with open PRs. |
I don't see how this would be any different than this PR in terms of state change precision. |
Right now when connecting, you pass received messages to Replicon, but they are only applied when in a "ready" state ( I propose processing received messages whenever they arrive. I.e. inside the |
Tested the proposed idea locally - too weird 😅 |
This allows users to utilize things like
StateScoped
and run systems more efficiently usingOnEnter
orOnExit
without evaluating conditions every frame.As a result, we now require
StatesPlugin
to be present. It's included by default inDefaultPlugins
, but withMinimalPlugins
you have to add it manually. In tests, I had to addStatesPlugin
everywhere.This also changes the behavior a little bit:
StateTransitions
schedule runs right afterPreUpdate
. But I think this behavior is actually better.RepliconClient
orRepliconServer
can actually accept messages. I currently preserved the original behavior where we reset them after exitingConnected
orRunning
. But it might be worth considering doing a reset on exitingDisconnected
orStopped
to ensure a clean start, like we did with events. I would appreciate opinions on this.