Skip to content

Commit 9f04fc0

Browse files
authored
Expose BRP system scheduling and add system set (#16400)
# Objective When adding custom BRP methods one might need to: - Run custom systems in the `RemoteLast` schedule. - Order those systems before/after request processing and cleanup. For example in `bevy_remote_inspector` we need a way to perform some preparation _before_ request processing. And to perform cleanup _between_ request processing and watcher cleanup. ## Solution - Make `RemoteLast` public - Add `RemoteSet` with `ProcessRequests` and `Cleanup` variants.
1 parent 3ec0958 commit 9f04fc0

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

crates/bevy_remote/src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ use bevy_app::{prelude::*, MainScheduleOrder};
305305
use bevy_derive::{Deref, DerefMut};
306306
use bevy_ecs::{
307307
entity::Entity,
308-
schedule::{IntoSystemConfigs, ScheduleLabel},
308+
schedule::{IntoSystemConfigs, IntoSystemSetConfigs, ScheduleLabel, SystemSet},
309309
system::{Commands, In, IntoSystem, ResMut, Resource, System, SystemId},
310310
world::World,
311311
};
@@ -442,21 +442,36 @@ impl Plugin for RemotePlugin {
442442
app.insert_resource(remote_methods)
443443
.init_resource::<RemoteWatchingRequests>()
444444
.add_systems(PreStartup, setup_mailbox_channel)
445+
.configure_sets(
446+
RemoteLast,
447+
(RemoteSet::ProcessRequests, RemoteSet::Cleanup).chain(),
448+
)
445449
.add_systems(
446450
RemoteLast,
447451
(
448-
process_remote_requests,
449-
process_ongoing_watching_requests,
450-
remove_closed_watching_requests,
451-
)
452-
.chain(),
452+
(process_remote_requests, process_ongoing_watching_requests)
453+
.chain()
454+
.in_set(RemoteSet::ProcessRequests),
455+
remove_closed_watching_requests.in_set(RemoteSet::Cleanup),
456+
),
453457
);
454458
}
455459
}
456460

457461
/// Schedule that contains all systems to process Bevy Remote Protocol requests
458462
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
459-
struct RemoteLast;
463+
pub struct RemoteLast;
464+
465+
/// The systems sets of the [`RemoteLast`] schedule.
466+
///
467+
/// These can be useful for ordering.
468+
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
469+
pub enum RemoteSet {
470+
/// Processing of remote requests.
471+
ProcessRequests,
472+
/// Cleanup (remove closed watchers etc)
473+
Cleanup,
474+
}
460475

461476
/// A type to hold the allowed types of systems to be used as method handlers.
462477
#[derive(Debug)]

0 commit comments

Comments
 (0)