-
Notifications
You must be signed in to change notification settings - Fork 38
Use Bevy state API for client and server states v2 #565
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
Changes from 1 commit
d859659
837e1bd
181cf74
79e4764
8c49c09
b6286ee
b069f99
f518137
dc5c386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,40 +48,45 @@ impl Plugin for ClientPlugin { | |
| PreUpdate, | ||
| ( | ||
| ClientSet::ReceivePackets, | ||
| ( | ||
| ClientSet::ResetEvents.run_if(client_just_connected), | ||
| ClientSet::Reset.run_if(client_just_disconnected), | ||
| ), | ||
| ClientSet::Receive, | ||
| ClientSet::Diagnostics, | ||
| ) | ||
| .chain(), | ||
| ) | ||
| .configure_sets( | ||
| PostUpdate, | ||
| OnEnter(ClientState::Connected), | ||
| ( | ||
| ClientSet::PrepareSend, | ||
| ClientSet::Send, | ||
| ClientSet::SendPackets, | ||
| ClientSet::ResetEvents, | ||
| ClientSet::Receive, | ||
| ClientSet::Diagnostics, | ||
| ) | ||
| .chain(), | ||
| ) | ||
| .configure_sets( | ||
| PostUpdate, | ||
| (ClientSet::Send, ClientSet::SendPackets).chain(), | ||
| ) | ||
| .add_systems( | ||
| PreUpdate, | ||
| receive_replication | ||
| .in_set(ClientSet::Receive) | ||
| .run_if(client_connected), | ||
| .run_if(in_state(ClientState::Connected)), | ||
| ) | ||
| .add_systems( | ||
| OnEnter(ClientState::Connected), | ||
| receive_replication.in_set(ClientSet::Receive), | ||
| ) | ||
| .add_systems(PreUpdate, reset.in_set(ClientSet::Reset)); | ||
| .add_systems( | ||
| OnExit(ClientState::Connected), | ||
| reset.in_set(ClientSet::Reset), | ||
| ); | ||
|
|
||
| let auth_method = *app.world().resource::<AuthMethod>(); | ||
| debug!("using authorization method `{auth_method:?}`"); | ||
| if auth_method == AuthMethod::ProtocolCheck { | ||
| app.add_observer(log_protocol_error).add_systems( | ||
| PreUpdate, | ||
| send_protocol_hash | ||
| .in_set(ClientSet::Receive) | ||
| .run_if(client_just_connected), | ||
| OnEnter(ClientState::Connected), | ||
| send_protocol_hash.in_set(ClientSet::SendHash), | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -165,12 +170,14 @@ pub(super) fn receive_replication( | |
| } | ||
|
|
||
| fn reset( | ||
| mut client: ResMut<RepliconClient>, | ||
| mut update_tick: ResMut<ServerUpdateTick>, | ||
| mut entity_map: ResMut<ServerEntityMap>, | ||
| mut buffered_mutations: ResMut<BufferedMutations>, | ||
| mutate_ticks: Option<ResMut<ServerMutateTicks>>, | ||
| stats: Option<ResMut<ClientReplicationStats>>, | ||
| ) { | ||
| client.clear(); | ||
| *update_tick = Default::default(); | ||
| entity_map.clear(); | ||
| buffered_mutations.clear(); | ||
|
|
@@ -744,32 +751,26 @@ struct ReceiveParams<'a> { | |
| /// Set with replication and event systems related to client. | ||
| #[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone, Copy)] | ||
| pub enum ClientSet { | ||
| /// Systems that receive packets from the messaging backend. | ||
| /// Systems that receive packets from the messaging backend and update [`ClientState`]. | ||
| /// | ||
| /// Used by messaging backend implementations. | ||
| /// | ||
| /// Runs in [`PreUpdate`]. | ||
| ReceivePackets, | ||
| /// Systems that receive data from [`RepliconClient`]. | ||
| /// | ||
| /// Used by `bevy_replicon`. | ||
| /// | ||
| /// Runs in [`PreUpdate`]. | ||
| /// Runs in [`PreUpdate`] and [`OnEnter`] for [`ClientState::Connected`] (to avoid 1 frame delay). | ||
| Receive, | ||
| /// Systems that populate Bevy's [`Diagnostics`](bevy::diagnostic::Diagnostics). | ||
| /// | ||
| /// Used by `bevy_replicon`. | ||
| /// | ||
| /// Runs in [`PreUpdate`]. | ||
| /// Runs in [`PreUpdate`] and [`OnEnter`] for [`ClientState::Connected`] (to avoid 1 frame delay). | ||
| Diagnostics, | ||
| /// Systems that prepare for sending data to [`RepliconClient`]. | ||
| /// System that sends [`ProtocolHash`]. | ||
| /// | ||
| /// Can be used by backends to add custom logic before sending data, such as transition to a disconnected or connecting state. | ||
| PrepareSend, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to keep this for renet2 to use.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not against, but how do you plan to use it? I ported
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No necessary anymore. Just like with the server everything can be done in |
||
| /// Runs in [`OnEnter`] for [`ClientState::Connected`]. | ||
| SendHash, | ||
| /// Systems that send data to [`RepliconClient`]. | ||
| /// | ||
| /// Used by `bevy_replicon`. | ||
| /// | ||
| /// Runs in [`PostUpdate`]. | ||
| Send, | ||
| /// Systems that send packets to the messaging backend. | ||
|
|
@@ -780,13 +781,13 @@ pub enum ClientSet { | |
| SendPackets, | ||
| /// Systems that reset queued server events. | ||
| /// | ||
| /// Runs in [`PreUpdate`] immediately after the client connects to ensure client sessions have a fresh start. | ||
| /// | ||
| /// This is a separate set from [`ClientSet::Reset`] to avoid sending events that were sent before the connection. | ||
| /// | ||
| /// Runs in [`OnEnter`] for [`ClientState::Connected`]. | ||
| ResetEvents, | ||
| /// Systems that reset the client. | ||
| /// | ||
| /// Runs in [`PreUpdate`] when the client just disconnected. | ||
| /// Runs in [`OnExit`] for [`ClientState::Connected`]. | ||
| Reset, | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,11 @@ impl Plugin for ClientDiagnosticsPlugin { | |
| PreUpdate, | ||
| add_measurements | ||
| .in_set(ClientSet::Diagnostics) | ||
| .run_if(client_connected), | ||
| .run_if(in_state(ClientState::Connected)), | ||
| ) | ||
| .add_systems( | ||
| OnEnter(ClientState::Connected), | ||
| add_measurements.in_set(ClientSet::Diagnostics), | ||
| ) | ||
|
Comment on lines
19
to
26
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks very awkward to me. Adding states means there are systems in the main schedule and in state schedules, which is an increase in complexity not a decrease.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran Replicon systems upon entering the schedule and within the schedule. This lets me process packets immediately after connection. It's not ideal, but I think it's worth it. |
||
| .register_diagnostic( | ||
| Diagnostic::new(RTT) | ||
|
|
||
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.
Should be before
receive_packets.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.
Not necessary, the packets can be passed into
ServerMessagesbefore we change the state.