1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
//! Provides sets to use with any system to provide consistent ordering.
use bevy::prelude::*;
/// Provides sets to use with any system to provide consistent ordering.
///
/// The ordering is configured in the `SchedulingPlugin` and by putting systems within
/// one of these sets will ensure that they are run in the correct order.
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
pub enum GameSet {
/// User input systems.
UserInput,
/// Entity update systems.
///
/// This set is for systems that update entities in the game world, e.g. movement,
/// status effects, etc.
EntityUpdate,
/// Collision systems.
///
/// This set is for systems that handle collision detection and tagging (for specific
/// resolution either in a despawn system or entity update system).
Collision,
/// Despawn systems.
///
/// This set is for systems that handle despawning entities from the game world.
Despawn,
}
/// Plugin to configure the scheduling of systems.
pub struct SchedulingPlugin;
impl Plugin for SchedulingPlugin {
fn build(&self, app: &mut App) {
app.configure_sets(
Update,
(
GameSet::Despawn,
// We flush before the next..
GameSet::UserInput,
GameSet::EntityUpdate,
GameSet::Collision,
)
.chain(),
)
.add_systems(
Update,
apply_deferred
.after(GameSet::Despawn)
.before(GameSet::UserInput),
);
}
}