Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
feat: remove more schedule logic
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Jan 7, 2024
1 parent 6aa9adb commit bb6bee1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 46 deletions.
24 changes: 8 additions & 16 deletions bevy-silk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,17 @@ impl Plugin for SilkClientPlugin {
OnEnter(SilkConnectionState::Disconnected),
systems::reset_socket,
)
.add_systems(Update, systems::connection_request_handler)
.add_systems(
SilkSchedule,
systems::on_login.in_set(SilkSet::NetworkRead),
)
.add_systems(
SilkSchedule,
common_socket_reader
(
common_socket_reader,
systems::client_event_writer,
systems::on_login,
)
.chain()
.run_if(resource_exists::<SilkSocket>())
.before(SilkSet::NetworkRead),
)
.add_systems(
SilkSchedule,
systems::client_socket_reader
.in_set(SilkSet::NetworkRead)
.run_if(resource_exists::<SilkSocket>()),
)
.add_systems(
Update,
systems::client_event_writer.after(systems::on_login),
.before(SilkSet::PreUpdate),
);
}
}
4 changes: 2 additions & 2 deletions bevy-silk/src/client/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ impl AddNetworkMessageExt for App {
IncomingMessages::<M>::receive_payloads,
)
.chain()
.before(SilkSet::NetworkRead)
.before(SilkSet::PreUpdate)
.after(common_socket_reader)
.run_if(resource_exists::<SilkSocket>()),
)
.add_systems(
SilkSchedule,
OutgoingMessages::<M>::send_payloads
.after(SilkSet::NetworkWrite)
.after(SilkSet::PostUpdate)
.run_if(resource_exists::<SilkSocket>()),
);
self
Expand Down
4 changes: 2 additions & 2 deletions bevy-silk/src/client/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn reset_socket(
}

/// Reads and handles connection request events
pub(crate) fn client_event_writer(
pub(crate) fn connection_request_handler(
mut cxn_event_reader: EventReader<ConnectionRequest>,
mut state: ResMut<SilkState>,
mut next_connection_state: ResMut<NextState<SilkConnectionState>>,
Expand Down Expand Up @@ -82,7 +82,7 @@ pub(crate) fn client_event_writer(
}

/// Translates socket updates into bevy events
pub(crate) fn client_socket_reader(
pub(crate) fn client_event_writer(
mut state: ResMut<SilkState>,
mut socket: ResMut<SilkSocket>,
mut event_wtr: EventWriter<SilkClientEvent>,
Expand Down
6 changes: 0 additions & 6 deletions bevy-silk/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ pub struct SilkSchedule;

#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet, EnumDisplay)]
pub enum SilkSet {
/// An exclusive system to read sockets
NetworkRead,
/// An exclusive system to analyze network traffic before use.
Process,
/// Apply updates before the main update.
Expand All @@ -19,20 +17,16 @@ pub enum SilkSet {
Update,
/// Apply updates after the main update.
PostUpdate,
/// An exclusive system for sending payloads
NetworkWrite,
}

impl SilkSet {
pub fn sets() -> SystemSetConfigs {
// Define the ordering of systems here
(
Self::NetworkRead,
Self::Process,
Self::PreUpdate,
Self::Update,
Self::PostUpdate,
Self::NetworkWrite,
)
.chain()
}
Expand Down
17 changes: 7 additions & 10 deletions bevy-silk/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ impl Plugin for SilkServerPlugin {
)
.add_systems(
SilkSchedule,
systems::on_login.in_set(SilkSet::NetworkRead),
)
.add_systems(
SilkSchedule,
common_socket_reader
(
common_socket_reader,
systems::on_login,
systems::server_event_writer,
)
.chain()
.run_if(resource_exists::<SilkSocket>())
.before(SilkSet::NetworkRead),
)
.add_systems(
Update,
systems::server_event_writer.after(systems::on_login),
.before(SilkSet::PreUpdate),
);
}
}
4 changes: 2 additions & 2 deletions bevy-silk/src/server/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ impl AddNetworkMessageExt for App {
IncomingMessages::<M>::receive_payloads,
)
.chain()
.before(SilkSet::NetworkRead)
.before(SilkSet::PreUpdate)
.after(common_socket_reader),
)
.add_systems(
SilkSchedule,
OutgoingMessages::<M>::send_payloads
.after(SilkSet::NetworkWrite)
.after(SilkSet::PostUpdate)
.run_if(resource_exists::<SilkSocket>()),
);

Expand Down
10 changes: 5 additions & 5 deletions demo/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bevy_silk::{
SilkClientEvent, SilkClientPlugin, SilkConnectionState, SilkState,
},
protocol::AuthenticationRequest,
schedule::{SilkSchedule, SilkSet},
schedule::SilkSchedule,
};
use chat::ChatState;
use painting::PaintingState;
Expand All @@ -42,10 +42,10 @@ fn main() {
.add_network_message::<ChatPayload>()
.add_network_message::<DrawLinePayload>()
.add_systems(Update, handle_events)
.add_systems(SilkSchedule, read_chats.in_set(SilkSet::NetworkRead))
.add_systems(SilkSchedule, read_lines.in_set(SilkSet::NetworkRead))
.add_systems(SilkSchedule, send_chats.in_set(SilkSet::NetworkWrite))
.add_systems(SilkSchedule, send_lines.in_set(SilkSet::NetworkWrite))
.add_systems(SilkSchedule, read_chats)
.add_systems(SilkSchedule, read_lines)
.add_systems(SilkSchedule, send_chats)
.add_systems(SilkSchedule, send_lines)
.add_systems(Update, app_ui)
.add_systems(
OnEnter(SilkConnectionState::Disconnected),
Expand Down
6 changes: 3 additions & 3 deletions demo/server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{log::LogPlugin, prelude::*};
use bevy_silk::{
packets::auth::SilkLoginResponsePayload,
schedule::{SilkSchedule, SilkSet},
schedule::SilkSchedule,
server::{
AddNetworkMessageExt, NetworkReader, NetworkWriter, SilkServerEvent,
SilkServerPlugin,
Expand All @@ -20,8 +20,8 @@ fn main() {
.add_network_message::<ChatPayload>()
.add_network_message::<DrawLinePayload>()
.add_systems(Update, handle_events)
.add_systems(SilkSchedule, send_draw_points.in_set(SilkSet::Update))
.add_systems(SilkSchedule, send_chats.in_set(SilkSet::Update))
.add_systems(SilkSchedule, send_draw_points)
.add_systems(SilkSchedule, send_chats)
.run();
}

Expand Down

0 comments on commit bb6bee1

Please sign in to comment.