Skip to content

Commit

Permalink
Merge pull request #110 from hymm/stage-yeet-cleanup-outer-schedules
Browse files Browse the repository at this point in the history
add a method on add to create a simple outer schedule
  • Loading branch information
alice-i-cecile authored Jan 29, 2023
2 parents 41d0b86 + e7f8cc2 commit 075209e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
14 changes: 14 additions & 0 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,20 @@ impl App {
self
}

/// adds a single threaded outer schedule to the [`App`] that just runs the main schedule
pub fn add_simple_outer_schedule(&mut self) -> &mut Self {
fn run_main_schedule(world: &mut World) {
world.run_schedule(CoreSchedule::Main);
}

self.edit_schedule(CoreSchedule::Outer, |schedule| {
schedule.set_executor_kind(bevy_ecs::scheduling::ExecutorKind::SingleThreaded);
schedule.add_system(run_main_schedule);
});

self
}

/// Setup the application to manage events of type `T`.
///
/// This is done by adding a [`Resource`] of type [`Events::<T>`],
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ impl CoreSchedule {
world.run_schedule(CoreSchedule::Main);
}

/// Initializes a schedule for [`CoreSchedule::Outer`] that contains the [`outer_loop`] system.
/// Initializes a single threaded schedule for [`CoreSchedule::Outer`] that contains the [`outer_loop`] system.
pub fn outer_schedule() -> Schedule {
let mut schedule = Schedule::new();
schedule.set_executor_kind(bevy_ecs::scheduling::ExecutorKind::SingleThreaded);
schedule.add_system(Self::outer_loop);
schedule
}
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl Plugin for RenderPlugin {
let asset_server = app.world.resource::<AssetServer>().clone();

let mut render_app = App::empty();
render_app.add_simple_outer_schedule();
let mut render_schedule = RenderSet::base_schedule();

// Prepare the schedule which extracts data from the main world to the render world
Expand All @@ -238,13 +239,7 @@ impl Plugin for RenderPlugin {

render_schedule.add_system(World::clear_entities.in_set(RenderSet::Cleanup));

let mut outer_schedule = Schedule::new();
outer_schedule.add_system(|world: &mut World| {
world.run_schedule(CoreSchedule::Main);
});

render_app
.add_schedule(CoreSchedule::Outer, outer_schedule)
.add_schedule(CoreSchedule::Main, render_schedule)
.init_resource::<render_graph::RenderGraph>()
.insert_resource(RenderInstance(instance))
Expand Down
8 changes: 2 additions & 6 deletions crates/bevy_render/src/pipelined_rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_channel::{Receiver, Sender};

use bevy_app::{App, AppLabel, CoreSchedule, Plugin, SubApp};
use bevy_ecs::{
scheduling::{MainThreadExecutor, Schedule},
scheduling::MainThreadExecutor,
system::Resource,
world::{Mut, World},
};
Expand Down Expand Up @@ -72,12 +72,8 @@ impl Plugin for PipelinedRenderingPlugin {
app.insert_resource(MainThreadExecutor::new());

let mut sub_app = App::empty();
sub_app.add_simple_outer_schedule();
sub_app.init_schedule(CoreSchedule::Main);
let mut outer_schedule = Schedule::new();
outer_schedule.add_system(|world: &mut World| {
world.run_schedule(CoreSchedule::Main);
});
sub_app.add_schedule(CoreSchedule::Outer, outer_schedule);
app.insert_sub_app(RenderExtractApp, SubApp::new(sub_app, update_rendering));
}

Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_time/src/fixed_timestep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
use crate::Time;
use bevy_app::CoreSchedule;
use bevy_ecs::{
system::Resource,
world::{Mut, World},
};
use bevy_ecs::{system::Resource, world::World};
use bevy_utils::Duration;
use thiserror::Error;

Expand Down

0 comments on commit 075209e

Please sign in to comment.