Remove add_default_plugins and add MinimalPlugins for simple "headless" scenarios (#767)

Remove add_default_plugins and add MinimalPlugins for simple "headless" scenarios
This commit is contained in:
Nathan Stocks 2020-11-02 19:38:37 -07:00 committed by GitHub
parent 2f87ff6618
commit 9871e7e24b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 92 additions and 80 deletions

View File

@ -29,21 +29,20 @@ impl Default for RunMode {
} }
} }
/// Configures an App to run its [Schedule](bevy_ecs::Schedule) according to a given [RunMode] #[derive(Copy, Clone, Default)]
#[derive(Default)] pub struct ScheduleRunnerSettings {
pub struct ScheduleRunnerPlugin {
pub run_mode: RunMode, pub run_mode: RunMode,
} }
impl ScheduleRunnerPlugin { impl ScheduleRunnerSettings {
pub fn run_once() -> Self { pub fn run_once() -> Self {
ScheduleRunnerPlugin { ScheduleRunnerSettings {
run_mode: RunMode::Once, run_mode: RunMode::Once,
} }
} }
pub fn run_loop(wait_duration: Duration) -> Self { pub fn run_loop(wait_duration: Duration) -> Self {
ScheduleRunnerPlugin { ScheduleRunnerSettings {
run_mode: RunMode::Loop { run_mode: RunMode::Loop {
wait: Some(wait_duration), wait: Some(wait_duration),
}, },
@ -51,14 +50,21 @@ impl ScheduleRunnerPlugin {
} }
} }
/// Configures an App to run its [Schedule](bevy_ecs::Schedule) according to a given [RunMode]
#[derive(Default)]
pub struct ScheduleRunnerPlugin {}
impl Plugin for ScheduleRunnerPlugin { impl Plugin for ScheduleRunnerPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut AppBuilder) {
let run_mode = self.run_mode; let settings = app
.resources_mut()
.get_or_insert_with(ScheduleRunnerSettings::default)
.to_owned();
app.set_runner(move |mut app: App| { app.set_runner(move |mut app: App| {
app.initialize(); app.initialize();
let mut app_exit_event_reader = EventReader::<AppExit>::default(); let mut app_exit_event_reader = EventReader::<AppExit>::default();
match run_mode { match settings.run_mode {
RunMode::Once => { RunMode::Once => {
app.update(); app.update();
} }

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(animate_sprite_system.system()) .add_system(animate_sprite_system.system())
.run(); .run();

View File

@ -4,7 +4,7 @@ use bevy::{asset::LoadState, prelude::*, sprite::TextureAtlasBuilder};
fn main() { fn main() {
App::build() App::build()
.init_resource::<RpgSpriteHandles>() .init_resource::<RpgSpriteHandles>()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(load_atlas.system()) .add_system(load_atlas.system())
.run(); .run();

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -6,7 +6,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -5,7 +5,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(rotator_system.system()) .add_system(rotator_system.system())
.run(); .run();

View File

@ -10,7 +10,7 @@ use rand::{rngs::StdRng, Rng, SeedableRng};
/// NOTE: Bevy still has a number of optimizations to do in this area. Expect the performance here to go way up in the future /// NOTE: Bevy still has a number of optimizations to do in this area. Expect the performance here to go way up in the future
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(PrintDiagnosticsPlugin::default()) .add_plugin(PrintDiagnosticsPlugin::default())
.add_startup_system(setup.system()) .add_startup_system(setup.system())

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example shows various ways to configure texture materials in 3D /// This example shows various ways to configure texture materials in 3D
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -9,7 +9,7 @@ use bevy::{
/// This example visualizes camera z-ordering by setting the material of rotating cubes to their distance from the camera /// This example visualizes camera z-ordering by setting the material of rotating cubes to their distance from the camera
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(rotator_system.system()) .add_system(rotator_system.system())
.add_system(camera_order_color_system.system()) .add_system(camera_order_color_system.system())

View File

@ -1,5 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
fn main() { fn main() {
App::build().add_default_plugins().run(); App::build().add_plugin_group(DefaultPlugins).run();
} }

View File

@ -1,7 +1,7 @@
use bevy::{app::ScheduleRunnerPlugin, prelude::*}; use bevy::{app::ScheduleRunnerSettings, prelude::*};
use std::time::Duration; use std::time::Duration;
// This example disables the default plugins by not registering them during setup. // This example only enables a minimal set of plugins required for bevy to run.
// You can also completely remove rendering / windowing Plugin code from bevy // You can also completely remove rendering / windowing Plugin code from bevy
// by making your import look like this in your Cargo.toml // by making your import look like this in your Cargo.toml
// //
@ -12,15 +12,17 @@ use std::time::Duration;
fn main() { fn main() {
// this app runs once // this app runs once
App::build() App::build()
.add_plugin(ScheduleRunnerPlugin::run_once()) .add_resource(ScheduleRunnerSettings::run_once())
.add_plugin_group(MinimalPlugins)
.add_system(hello_world_system.system()) .add_system(hello_world_system.system())
.run(); .run();
// this app loops forever at 60 fps // this app loops forever at 60 fps
App::build() App::build()
.add_plugin(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64( .add_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / 60.0, 1.0 / 60.0,
))) )))
.add_plugin_group(MinimalPlugins)
.add_system(counter.system()) .add_system(counter.system())
.run(); .run();
} }

View File

@ -6,7 +6,7 @@ use std::time::Duration;
/// This example illustrates how to create a simple plugin that prints out a message. /// This example illustrates how to create a simple plugin that prints out a message.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
// plugins are registered as part of the "app building" process // plugins are registered as part of the "app building" process
.add_plugin(PrintMessagePlugin { .add_plugin(PrintMessagePlugin {
wait_duration: Duration::from_secs(1), wait_duration: Duration::from_secs(1),

View File

@ -3,7 +3,7 @@ use bevy::{app::PluginGroupBuilder, prelude::*};
/// PluginGroups are a way to group sets of plugins that should be registered together. /// PluginGroups are a way to group sets of plugins that should be registered together.
fn main() { fn main() {
App::build() App::build()
// The app.add_default_plugins() you see in all of the examples is just an alias for this: // Two PluginGroups that are included with bevy are DefaultPlugins and MinimalPlugins
.add_plugin_group(DefaultPlugins) .add_plugin_group(DefaultPlugins)
// Adding a plugin group adds all plugins in the group by default // Adding a plugin group adds all plugins in the group by default
.add_plugin_group(HelloWorldPlugins) .add_plugin_group(HelloWorldPlugins)

View File

@ -7,7 +7,7 @@ fn main() {
return_from_run: true, return_from_run: true,
}) })
.add_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8))) .add_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8)))
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.run(); .run();
println!("Running another App."); println!("Running another App.");
App::build() App::build()
@ -15,7 +15,7 @@ fn main() {
return_from_run: true, return_from_run: true,
}) })
.add_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2))) .add_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2)))
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.run(); .run();
println!("Done."); println!("Done.");
} }

View File

@ -5,6 +5,6 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_resource(DefaultTaskPoolOptions::with_num_threads(4)) .add_resource(DefaultTaskPoolOptions::with_num_threads(4))
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.run(); .run();
} }

View File

@ -4,7 +4,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -35,7 +35,7 @@ impl AssetLoader for CustomAssetLoader {
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.init_resource::<State>() .init_resource::<State>()
.add_asset::<CustomAsset>() .add_asset::<CustomAsset>()
.init_asset_loader::<CustomAssetLoader>() .init_asset_loader::<CustomAssetLoader>()

View File

@ -5,7 +5,7 @@ use bevy::prelude::*;
/// This example illustrates hot reloading mesh changes. /// This example illustrates hot reloading mesh changes.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example illustrates how to load and play an audio file /// This example illustrates how to load and play an audio file
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -6,7 +6,7 @@ use bevy::{
/// This example illustrates how to create a custom diagnostic /// This example illustrates how to create a custom diagnostic
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
// The "print diagnostics" plugin is optional. It just visualizes our diagnostics in the console // The "print diagnostics" plugin is optional. It just visualizes our diagnostics in the console
.add_plugin(PrintDiagnosticsPlugin::default()) .add_plugin(PrintDiagnosticsPlugin::default())
.add_startup_system(setup_diagnostic_system.system()) .add_startup_system(setup_diagnostic_system.system())

View File

@ -5,7 +5,7 @@ use bevy::{
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
// Adds frame time diagnostics // Adds frame time diagnostics
.add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(FrameTimeDiagnosticsPlugin::default())
// Adds a system that prints diagnostics to the console // Adds a system that prints diagnostics to the console

View File

@ -1,5 +1,5 @@
use bevy::{ use bevy::{
app::{AppExit, ScheduleRunnerPlugin}, app::{AppExit, ScheduleRunnerPlugin, ScheduleRunnerSettings},
prelude::*, prelude::*,
}; };
use rand::random; use rand::random;
@ -244,12 +244,14 @@ fn local_state_system(mut state: Local<State>, query: Query<(&Player, &Score)>)
fn main() { fn main() {
// Bevy apps are created using the builder pattern. We use the builder to add systems, resources, and plugins to our app // Bevy apps are created using the builder pattern. We use the builder to add systems, resources, and plugins to our app
App::build() App::build()
// Plugins are just a grouped set of app builder calls (just like we're doing here).
// We could easily turn our game into a plugin, but you can check out the plugin example for that :)
// The plugin below runs our app's "system schedule" once every 5 seconds.
.add_plugin(ScheduleRunnerPlugin::run_loop(Duration::from_secs(5)))
// Resources can be added to our app like this // Resources can be added to our app like this
.add_resource(State { counter: 0 }) .add_resource(State { counter: 0 })
// Some systems are configured by adding their settings as a resource
.add_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs(5)))
// Plugins are just a grouped set of app builder calls (just like we're doing here).
// We could easily turn our game into a plugin, but you can check out the plugin example for that :)
// The plugin below runs our app's "system schedule" once every 5 seconds (configured above).
.add_plugin(ScheduleRunnerPlugin::default())
// Resources that implement the Default or FromResources trait can be added like this: // Resources that implement the Default or FromResources trait can be added like this:
.init_resource::<GameState>() .init_resource::<GameState>()
// Startup systems run exactly once BEFORE all other systems. These are generally used for // Startup systems run exactly once BEFORE all other systems. These are generally used for

View File

@ -4,7 +4,7 @@ use bevy::prelude::*;
/// and a system that prints a message whenever the event is received. /// and a system that prints a message whenever the event is received.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_event::<MyEvent>() .add_event::<MyEvent>()
.init_resource::<EventTriggerState>() .init_resource::<EventTriggerState>()
.add_system(event_trigger_system.system()) .add_system(event_trigger_system.system())

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(rotate.system()) .add_system(rotate.system())
.run(); .run();

View File

@ -73,7 +73,7 @@ fn bounce_system(
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(spawn_system.system()) .add_startup_system(spawn_system.system())
.add_system(move_system.system()) .add_system(move_system.system())
.add_system(bounce_system.system()) .add_system(bounce_system.system())

View File

@ -7,7 +7,7 @@ use bevy::{
/// An implementation of the classic game "Breakout" /// An implementation of the classic game "Breakout"
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_resource(Scoreboard { score: 0 }) .add_resource(Scoreboard { score: 0 })
.add_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9))) .add_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9)))
.add_startup_system(setup.system()) .add_startup_system(setup.system())

View File

@ -4,7 +4,7 @@ use bevy_utils::HashSet;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.init_resource::<GamepadLobby>() .init_resource::<GamepadLobby>()
.add_system_to_stage(stage::PRE_UPDATE, connection_system.system()) .add_system_to_stage(stage::PRE_UPDATE, connection_system.system())
.add_system(gamepad_system.system()) .add_system(gamepad_system.system())

View File

@ -3,7 +3,7 @@ use bevy_input::gamepad::{GamepadEvent, GamepadEventType};
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(gamepad_events.system()) .add_system(gamepad_events.system())
.run(); .run();
} }

View File

@ -5,7 +5,7 @@ use bevy::{
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(keyboard_input_system.system()) .add_system(keyboard_input_system.system())
.run(); .run();
} }

View File

@ -2,7 +2,7 @@ use bevy::{input::keyboard::KeyboardInput, prelude::*};
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(print_keyboard_event_system.system()) .add_system(print_keyboard_event_system.system())
.run(); .run();
} }

View File

@ -2,7 +2,7 @@ use bevy::prelude::*;
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(mouse_click_system.system()) .add_system(mouse_click_system.system())
.run(); .run();
} }

View File

@ -6,7 +6,7 @@ use bevy::{
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(print_mouse_events_system.system()) .add_system(print_mouse_events_system.system())
.run(); .run();
} }

View File

@ -2,7 +2,7 @@ use bevy::{input::touch::*, prelude::*};
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(touch_system.system()) .add_system(touch_system.system())
.run(); .run();
} }

View File

@ -2,7 +2,7 @@ use bevy::{input::touch::*, prelude::*};
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(touch_event_system.system()) .add_system(touch_event_system.system())
.run(); .run();
} }

View File

@ -1,8 +1,8 @@
use bevy::{ use bevy::{
prelude::{ prelude::{
shape, AddDefaultPlugins, App, Assets, Camera3dComponents, Color, Commands, shape, App, Assets, Camera3dComponents, Color, Commands, DefaultPlugins, IntoQuerySystem,
IntoQuerySystem, LightComponents, Mesh, Msaa, PbrComponents, ResMut, StandardMaterial, LightComponents, Mesh, Msaa, PbrComponents, ResMut, StandardMaterial, Transform, Vec3,
Transform, Vec3, WindowDescriptor, WindowDescriptor,
}, },
window::WindowMode, window::WindowMode,
}; };
@ -17,7 +17,7 @@ extern "C" fn main_rs() {
..Default::default() ..Default::default()
}) })
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
/// familiar with "reflection" in other languages, Properties are very similar to that concept. /// familiar with "reflection" in other languages, Properties are very similar to that concept.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
// If you need to deserialize custom property types, register them like this: // If you need to deserialize custom property types, register them like this:
.register_property::<Test>() .register_property::<Test>()
.register_property::<Nested>() .register_property::<Nested>()

View File

@ -3,7 +3,7 @@ use bevy::{prelude::*, type_registry::TypeRegistry};
/// This example illustrates loading and saving scenes from files /// This example illustrates loading and saving scenes from files
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
// Registering components informs Bevy that they exist. This allows them to be used when loading scenes // Registering components informs Bevy that they exist. This allows them to be used when loading scenes
// This step is only required if you want to load your components from scene files. // This step is only required if you want to load your components from scene files.
// Unregistered components can still be used in your code, but they will be ignored during scene save/load. // Unregistered components can still be used in your code, but they will be ignored during scene save/load.

View File

@ -13,7 +13,7 @@ use bevy::{
/// This example illustrates how to add a custom attribute to a mesh and use it in a custom shader. /// This example illustrates how to add a custom attribute to a mesh and use it in a custom shader.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_asset::<MyMaterialWithVertexColorSupport>() .add_asset::<MyMaterialWithVertexColorSupport>()
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();

View File

@ -13,7 +13,7 @@ use bevy::{
/// This example illustrates how to create a custom material asset and a shader that uses that material /// This example illustrates how to create a custom material asset and a shader that uses that material
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_asset::<MyMaterial>() .add_asset::<MyMaterial>()
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();

View File

@ -14,7 +14,7 @@ use bevy::{
/// In Bevy, "shader defs" are a way to selectively enable parts of a shader based on values set in a component or asset. /// In Bevy, "shader defs" are a way to selectively enable parts of a shader based on values set in a component or asset.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_asset::<MyMaterial>() .add_asset::<MyMaterial>()
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system_to_stage( .add_system_to_stage(

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example illustrates how to create a button that changes color and text based on its interaction state. /// This example illustrates how to create a button that changes color and text based on its interaction state.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.init_resource::<ButtonMaterials>() .init_resource::<ButtonMaterials>()
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(button_system.system()) .add_system(button_system.system())

View File

@ -4,7 +4,7 @@ use bevy::{prelude::*, text::FontAtlasSet};
fn main() { fn main() {
App::build() App::build()
.init_resource::<State>() .init_resource::<State>()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(text_update_system.system()) .add_system(text_update_system.system())
.add_system(atlas_render_system.system()) .add_system(atlas_render_system.system())

View File

@ -6,7 +6,7 @@ use bevy::{
/// This example illustrates how to create text and update it in a system. It displays the current FPS in the upper left hand corner. /// This example illustrates how to create text and update it in a system. It displays the current FPS in the upper left hand corner.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.add_system(text_update_system.system()) .add_system(text_update_system.system())

View File

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example illustrates the various features of Bevy UI. /// This example illustrates the various features of Bevy UI.
fn main() { fn main() {
App::build() App::build()
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -19,7 +19,7 @@ fn main() {
.add_resource(AssetServerSettings { .add_resource(AssetServerSettings {
asset_folder: "/".to_string(), asset_folder: "/".to_string(),
}) })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_asset::<RustSourceCode>() .add_asset::<RustSourceCode>()
.init_asset_loader::<RustSourceCodeLoader>() .init_asset_loader::<RustSourceCodeLoader>()
.add_startup_system(load_asset.system()) .add_startup_system(load_asset.system())

View File

@ -1,7 +1,10 @@
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
extern crate console_error_panic_hook; extern crate console_error_panic_hook;
use bevy::{app::ScheduleRunnerPlugin, prelude::*}; use bevy::{
app::{ScheduleRunnerPlugin, ScheduleRunnerSettings},
prelude::*,
};
use std::time::Duration; use std::time::Duration;
fn main() { fn main() {
@ -12,9 +15,10 @@ fn main() {
} }
App::build() App::build()
.add_plugin(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64( .add_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / 60.0, 1.0 / 60.0,
))) )))
.add_plugin(ScheduleRunnerPlugin::default())
.add_startup_system(hello_world_system.system()) .add_startup_system(hello_world_system.system())
.add_system(counter.system()) .add_system(counter.system())
.run(); .run();

View File

@ -22,7 +22,7 @@ fn main() {
height: 300, height: 300,
..Default::default() ..Default::default()
}) })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
// One time greet // One time greet
.add_startup_system(hello_wasm_system.system()) .add_startup_system(hello_wasm_system.system())
// Track ticks (sanity check, whether game loop is running) // Track ticks (sanity check, whether game loop is running)

View File

@ -3,6 +3,6 @@ use bevy::{prelude::*, render::pass::ClearColor};
fn main() { fn main() {
App::build() App::build()
.add_resource(ClearColor(Color::rgb(0.5, 0.5, 0.9))) .add_resource(ClearColor(Color::rgb(0.5, 0.5, 0.9)))
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.run(); .run();
} }

View File

@ -16,7 +16,7 @@ use bevy::{
fn main() { fn main() {
App::build() App::build()
.add_resource(Msaa { samples: 4 }) .add_resource(Msaa { samples: 4 })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_startup_system(setup.system()) .add_startup_system(setup.system())
.run(); .run();
} }

View File

@ -11,7 +11,7 @@ fn main() {
resizable: false, resizable: false,
..Default::default() ..Default::default()
}) })
.add_default_plugins() .add_plugin_group(DefaultPlugins)
.add_system(change_title.system()) .add_system(change_title.system())
.add_system(toggle_cursor.system()) .add_system(toggle_cursor.system())
.run(); .run();

View File

@ -1,7 +1,5 @@
use bevy_app::{PluginGroup, PluginGroupBuilder}; use bevy_app::{PluginGroup, PluginGroupBuilder};
use crate::app::AppBuilder;
pub struct DefaultPlugins; pub struct DefaultPlugins;
impl PluginGroup for DefaultPlugins { impl PluginGroup for DefaultPlugins {
@ -47,12 +45,12 @@ impl PluginGroup for DefaultPlugins {
} }
} }
pub trait AddDefaultPlugins { pub struct MinimalPlugins;
fn add_default_plugins(&mut self) -> &mut Self;
}
impl AddDefaultPlugins for AppBuilder { impl PluginGroup for MinimalPlugins {
fn add_default_plugins(&mut self) -> &mut Self { fn build(&mut self, group: &mut PluginGroupBuilder) {
self.add_plugin_group(DefaultPlugins) group.add(bevy_type_registry::TypeRegistryPlugin::default());
group.add(bevy_core::CorePlugin::default());
group.add(bevy_app::ScheduleRunnerPlugin::default());
} }
} }

View File

@ -1,7 +1,7 @@
pub use crate::{ pub use crate::{
app::prelude::*, asset::prelude::*, core::prelude::*, ecs::prelude::*, input::prelude::*, app::prelude::*, asset::prelude::*, core::prelude::*, ecs::prelude::*, input::prelude::*,
math::prelude::*, property::prelude::*, scene::prelude::*, transform::prelude::*, math::prelude::*, property::prelude::*, scene::prelude::*, transform::prelude::*,
type_registry::RegisterType, window::prelude::*, AddDefaultPlugins, DefaultPlugins, type_registry::RegisterType, window::prelude::*, DefaultPlugins, MinimalPlugins,
}; };
#[cfg(feature = "bevy_audio")] #[cfg(feature = "bevy_audio")]