Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runners explicitly call App.initialize() #690

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl App {
.run(&mut self.schedule, &mut self.world, &mut self.resources);
}

pub fn run(mut self) {
pub fn initialize(&mut self) {
self.startup_schedule
.initialize(&mut self.world, &mut self.resources);
self.startup_executor.initialize(&mut self.resources);
Expand All @@ -72,7 +72,9 @@ impl App {
&mut self.world,
&mut self.resources,
);
}

pub fn run(mut self) {
self.executor.initialize(&mut self.resources);
let runner = std::mem::replace(&mut self.runner, Box::new(run_once));
(runner)(self);
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_app/src/schedule_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ impl Plugin for ScheduleRunnerPlugin {
fn build(&self, app: &mut AppBuilder) {
let run_mode = self.run_mode;
app.set_runner(move |mut app: App| {
app.initialize();

let mut app_exit_event_reader = EventReader::<AppExit>::default();
match run_mode {
RunMode::Once => {
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ pub fn winit_runner(mut app: App) {
&mut create_window_event_reader,
);

app.initialize();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is down here instead of at the top? This would be a slight change in init behavior, this now does window creation / event loop creation before running the startup systems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do it right before entering the main loop.

  • preparation
  • initialize()
  • loop {}

Copy link
Member Author

@smokku smokku Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this change is to have access to resources created by runner in startup systems.
It is not needed in case of bevy_winit but we should keep things consistent across different plugins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me!


log::debug!("Entering winit event loop");

let should_return_from_run = app
Expand Down