Skip to content

Commit

Permalink
Merge pull request #91 from devil-ira/stage-yeet-patch
Browse files Browse the repository at this point in the history
Stage-yeet patch
  • Loading branch information
alice-i-cecile authored Jan 24, 2023
2 parents e414ea6 + c6a7539 commit 62200a4
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 24 deletions.
17 changes: 14 additions & 3 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl SubApp {
pub fn run(&mut self) {
self.app
.world
.run_schedule(&self.app.default_schedule_label);
.run_schedule(&*self.app.outer_schedule_label);
self.app.world.clear_trackers();
}

Expand All @@ -168,7 +168,6 @@ impl Default for App {
let mut app = App::empty();
#[cfg(feature = "bevy_reflect")]
app.init_resource::<AppTypeRegistry>();
app.init_resource::<Schedules>();

app.add_default_schedules();
app.add_default_sets();
Expand Down Expand Up @@ -197,8 +196,10 @@ impl App {
///
/// This constructor should be used if you wish to provide custom scheduling, exit handling, cleanup, etc.
pub fn empty() -> App {
let mut world = World::new();
world.init_resource::<Schedules>();
Self {
world: Default::default(),
world,
runner: Box::new(run_once),
sub_apps: HashMap::default(),
plugin_registry: Vec::default(),
Expand Down Expand Up @@ -458,6 +459,16 @@ impl App {
self.add_systems_to_schedule(systems, &CoreSchedule::Startup)
}

/// Configures a system set in the default schedule, adding it if it does not exist.
pub fn configure_set(&mut self, set: impl IntoSystemSetConfig) -> &mut Self {
self.world
.resource_mut::<Schedules>()
.get_mut(&*self.default_schedule_label)
.unwrap()
.configure_set(set);
self
}

/// Adds standardized schedules and labels to an [`App`].
///
/// Adding these schedules is necessary to make almost all core engine features work.
Expand Down
8 changes: 3 additions & 5 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ impl Plugin for AssetPlugin {

app.register_type::<HandleId>();

let main_schedule = app.schedule_mut(&CoreSchedule::Main).unwrap();

main_schedule
.configure_set(AssetSet::LoadAssets.before(CoreSet::PreUpdate))
.configure_set(AssetSet::AssetEvents.after(CoreSet::PostUpdate))
app
.configure_set(AssetSet::LoadAssets.no_default_set().before(CoreSet::PreUpdate))
.configure_set(AssetSet::AssetEvents.no_default_set().after(CoreSet::PostUpdate))
.add_system(asset_server::free_unused_assets_system.in_set(CoreSet::PreUpdate));

#[cfg(all(
Expand Down
40 changes: 32 additions & 8 deletions crates/bevy_ecs/src/scheduling/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bevy_ecs_macros::all_tuples;
use bevy_utils::default;

use crate::{
scheduling::{
Expand Down Expand Up @@ -29,11 +28,7 @@ impl SystemSetConfig {

Self {
set,
graph_info: GraphInfo {
sets: Vec::new(),
dependencies: Vec::new(),
ambiguous_with: default(),
},
graph_info: GraphInfo::default(),
conditions: Vec::new(),
}
}
Expand All @@ -54,8 +49,7 @@ impl SystemConfig {
system,
graph_info: GraphInfo {
sets,
dependencies: Vec::new(),
ambiguous_with: default(),
..Default::default()
},
conditions: Vec::new(),
}
Expand Down Expand Up @@ -94,6 +88,8 @@ pub trait IntoSystemSetConfig: sealed::IntoSystemSetConfig {
fn into_config(self) -> SystemSetConfig;
/// Add to the provided `set`.
fn in_set(self, set: impl SystemSet) -> SystemSetConfig;
/// Don't add this set to the schedules's default set.
fn no_default_set(self) -> SystemSetConfig;
/// Run before all systems in `set`.
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfig;
/// Run after all systems in `set`.
Expand Down Expand Up @@ -125,6 +121,10 @@ where
self.into_config().in_set(set)
}

fn no_default_set(self) -> SystemSetConfig {
self.into_config().no_default_set()
}

fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfig {
self.into_config().before(set)
}
Expand Down Expand Up @@ -159,6 +159,10 @@ impl IntoSystemSetConfig for BoxedSystemSet {
self.into_config().in_set(set)
}

fn no_default_set(self) -> SystemSetConfig {
self.into_config().no_default_set()
}

fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemSetConfig {
self.into_config().before(set)
}
Expand Down Expand Up @@ -198,6 +202,11 @@ impl IntoSystemSetConfig for SystemSetConfig {
self
}

fn no_default_set(mut self) -> SystemSetConfig {
self.graph_info.add_default_set = false;
self
}

fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
self.graph_info.dependencies.push(Dependency::new(
DependencyKind::Before,
Expand Down Expand Up @@ -244,6 +253,8 @@ pub trait IntoSystemConfig<Params>: sealed::IntoSystemConfig<Params> {
fn into_config(self) -> SystemConfig;
/// Add to `set` membership.
fn in_set(self, set: impl SystemSet) -> SystemConfig;
/// Don't add this system to the schedules's default set.
fn no_default_set(self) -> SystemConfig;
/// Run before all systems in `set`.
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfig;
/// Run after all systems in `set`.
Expand Down Expand Up @@ -275,6 +286,10 @@ where
self.into_config().in_set(set)
}

fn no_default_set(self) -> SystemConfig {
self.into_config().no_default_set()
}

fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfig {
self.into_config().before(set)
}
Expand Down Expand Up @@ -309,6 +324,10 @@ impl IntoSystemConfig<()> for BoxedSystem<(), ()> {
self.into_config().in_set(set)
}

fn no_default_set(self) -> SystemConfig {
self.into_config().no_default_set()
}

fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfig {
self.into_config().before(set)
}
Expand Down Expand Up @@ -348,6 +367,11 @@ impl IntoSystemConfig<()> for SystemConfig {
self
}

fn no_default_set(mut self) -> SystemConfig {
self.graph_info.add_default_set = false;
self
}

fn before<M>(mut self, set: impl IntoSystemSet<M>) -> Self {
self.graph_info.dependencies.push(Dependency::new(
DependencyKind::Before,
Expand Down
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/scheduling/graph_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ pub(crate) struct GraphInfo {
pub(crate) sets: Vec<BoxedSystemSet>,
pub(crate) dependencies: Vec<Dependency>,
pub(crate) ambiguous_with: Ambiguity,
pub(crate) add_default_set: bool,
}

impl Default for GraphInfo {
fn default() -> Self {
GraphInfo {
sets: Vec::new(),
dependencies: Vec::new(),
ambiguous_with: Ambiguity::default(),
add_default_set: true,
}
}
}

/// Converts 2D row-major pair of indices into a 1D array index.
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/scheduling/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl ScheduleGraph {
let id = NodeId::System(self.systems.len());

if let [single_set] = graph_info.sets.as_slice() {
if single_set.is_system_type() {
if single_set.is_system_type() && graph_info.add_default_set {
if let Some(default) = self.default_set.as_ref() {
graph_info.sets.push(default.dyn_clone());
}
Expand Down Expand Up @@ -434,7 +434,7 @@ impl ScheduleGraph {

// a system set can be configured multiple times, so this "default check"
// should only happen the first time `configure_set` is called on it
if !already_configured && graph_info.sets.is_empty() {
if !already_configured && graph_info.sets.is_empty() && graph_info.add_default_set {
if let Some(default) = self.default_set.as_ref() {
info!("adding system set `{:?}` to default: `{:?}`", set, default);
graph_info.sets.push(default.dyn_clone());
Expand Down Expand Up @@ -524,6 +524,7 @@ impl ScheduleGraph {
sets,
dependencies,
ambiguous_with,
..
} = graph_info;

if !self.hierarchy.graph.contains_node(id) {
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ impl Plugin for RenderPlugin {
let asset_server = app.world.resource::<AssetServer>().clone();

let mut render_app = App::empty();
render_app.init_resource::<Schedules>();
let mut render_schedule = RenderSet::base_schedule();

// Prepare the schedule which extracts data from the main world to the render world
Expand Down
8 changes: 3 additions & 5 deletions examples/ecs/ecs_guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use bevy::{
app::{AppExit, ScheduleRunnerPlugin, ScheduleRunnerSettings},
ecs::scheduling::ReportExecutionOrderAmbiguities,
log::LogPlugin,
prelude::*,
utils::Duration,
Expand Down Expand Up @@ -290,10 +289,10 @@ fn main() {
// "before_round": new_player_system, new_round_system
// "update": print_message_system, score_system
// "after_round": score_check_system, game_over_system
.configure_set(MySet::BeforeRound.before(CoreSet::Update))
.configure_set(MySet::AfterRound.after(CoreSet::Update))
.configure_set(MySet::BeforeRound.no_default_set().before(CoreSet::Update))
.configure_set(MySet::AfterRound.no_default_set().after(CoreSet::Update))
.add_system(new_round_system.in_set(MySet::BeforeRound))
.add_system(new_player_system.after(new_round_system.in_set(MySet::BeforeRound)))
.add_system(new_player_system.after(new_round_system).in_set(MySet::BeforeRound))
.add_system(exclusive_player_system.in_set(MySet::BeforeRound))
.add_system(score_check_system.in_set(MySet::AfterRound))
.add_system(
Expand All @@ -307,7 +306,6 @@ fn main() {
// Be aware that not everything reported by this checker is a potential problem, you'll have
// to make that judgement yourself.
.add_plugin(LogPlugin::default())
.init_resource::<ReportExecutionOrderAmbiguities>()
// This call to run() starts the app we just built!
.run();
}

0 comments on commit 62200a4

Please sign in to comment.