Merge AppBuilder into App (#2531)

This is extracted out of eb8f973646476b4a4926ba644a77e2b3a5772159 and includes some additional changes to remove all references to AppBuilder and fix examples that still used App::build() instead of App::new(). In addition I didn't extract the sub app feature as it isn't ready yet.

You can use `git diff --diff-filter=M eb8f973646476b4a4926ba644a77e2b3a5772159` to find all differences in this PR. The `--diff-filtered=M` filters all files added in the original commit but not in this commit away.

Co-Authored-By: Carter Anderson <mcanders1@gmail.com>
This commit is contained in:
bjorn3 2021-07-27 20:21:06 +00:00
parent c83a184e2f
commit 6d6bc2a8b4
130 changed files with 712 additions and 764 deletions

View file

@ -1,8 +1,15 @@
use crate::app_builder::AppBuilder;
use crate::{CoreStage, Events, Plugin, PluginGroup, PluginGroupBuilder, StartupStage};
use bevy_ecs::{
schedule::{Schedule, Stage},
component::{Component, ComponentDescriptor},
prelude::{FromWorld, IntoExclusiveSystem, IntoSystem},
schedule::{
IntoSystemDescriptor, RunOnce, Schedule, Stage, StageLabel, State, SystemSet, SystemStage,
},
world::World,
};
use bevy_utils::tracing::debug;
use std::{fmt::Debug, hash::Hash};
#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;
@ -20,7 +27,7 @@ use bevy_utils::tracing::info_span;
/// # use bevy_ecs::prelude::*;
///
/// fn main() {
/// App::build()
/// App::new()
/// .add_system(hello_world_system.system())
/// .run();
/// }
@ -37,22 +44,35 @@ pub struct App {
impl Default for App {
fn default() -> Self {
let mut app = App::empty();
#[cfg(feature = "bevy_reflect")]
app.init_resource::<bevy_reflect::TypeRegistryArc>();
app.add_default_stages()
.add_event::<AppExit>()
.add_system_to_stage(CoreStage::Last, World::clear_trackers.exclusive_system());
#[cfg(feature = "bevy_ci_testing")]
{
crate::ci_testing::setup_app(&mut app);
}
app
}
}
impl App {
pub fn new() -> App {
App::default()
}
pub fn empty() -> App {
Self {
world: Default::default(),
schedule: Default::default(),
runner: Box::new(run_once),
}
}
}
fn run_once(mut app: App) {
app.update();
}
impl App {
pub fn build() -> AppBuilder {
AppBuilder::default()
}
pub fn update(&mut self) {
#[cfg(feature = "trace")]
@ -62,15 +82,504 @@ impl App {
self.schedule.run(&mut self.world);
}
pub fn run(mut self) {
/// Start the application (through main runner)
///
/// Runs the application main loop.
///
/// Usually the main loop is handled by Bevy integrated plugins (`winit`), but
/// one can also set the runner function through [`App::set_runner`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// App::new()
/// // all required plugin insertions, systems, etc inserted here
/// // finally, call:
/// .run();
/// ```
pub fn run(&mut self) {
#[cfg(feature = "trace")]
let bevy_app_run_span = info_span!("bevy_app");
#[cfg(feature = "trace")]
let _bevy_app_run_guard = bevy_app_run_span.enter();
let runner = std::mem::replace(&mut self.runner, Box::new(run_once));
(runner)(self);
let mut app = std::mem::replace(self, App::empty());
let runner = std::mem::replace(&mut app.runner, Box::new(run_once));
(runner)(app);
}
pub fn add_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.schedule.add_stage(label, stage);
self
}
pub fn add_stage_after<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.schedule.add_stage_after(target, label, stage);
self
}
pub fn add_stage_before<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.schedule.add_stage_before(target, label, stage);
self
}
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage(label, stage)
});
self
}
pub fn add_startup_stage_after<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage_after(target, label, stage)
});
self
}
pub fn add_startup_stage_before<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage_before(target, label, stage)
});
self
}
pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
&mut self,
label: impl StageLabel,
func: F,
) -> &mut Self {
self.schedule.stage(label, func);
self
}
/// Adds a system that runs every time `app.update()` is called by the runner
///
/// Systems are the main building block in the Bevy ECS app model. You can define
/// normal rust functions, and call `.system()` to make them be Bevy systems.
///
/// System functions can have parameters, through which one can query and
/// mutate Bevy ECS states.
/// See [The Bevy Book](https://bevyengine.org/learn/book/introduction/) for more information.
///
/// Systems are run in parallel, and the execution order is not deterministic.
/// If you want more fine-grained control for order, see [`App::add_system_to_stage`].
///
/// For adding a system that runs only at app startup, see [`App::add_startup_system`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// #
/// fn my_system(_commands: Commands) {
/// println!("My system, triggered once per frame");
/// }
///
/// App::new()
/// .add_system(my_system.system());
/// ```
pub fn add_system<Params>(&mut self, system: impl IntoSystemDescriptor<Params>) -> &mut Self {
self.add_system_to_stage(CoreStage::Update, system)
}
pub fn add_system_set(&mut self, system_set: SystemSet) -> &mut Self {
self.add_system_set_to_stage(CoreStage::Update, system_set)
}
pub fn add_system_to_stage<Params>(
&mut self,
stage_label: impl StageLabel,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.schedule.add_system_to_stage(stage_label, system);
self
}
pub fn add_system_set_to_stage(
&mut self,
stage_label: impl StageLabel,
system_set: SystemSet,
) -> &mut Self {
self.schedule
.add_system_set_to_stage(stage_label, system_set);
self
}
/// Adds a system that is run once at application startup
///
/// Startup systems run exactly once BEFORE all other systems. These are generally used for
/// app initialization code (ex: adding entities and resources).
///
/// * For adding a system that runs for every frame, see [`App::add_system`].
/// * For adding a system to specific stage, see [`App::add_system_to_stage`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// #
/// fn my_startup_system(_commands: Commands) {
/// println!("My startup system");
/// }
///
/// App::new()
/// .add_startup_system(my_startup_system.system());
/// ```
pub fn add_startup_system<Params>(
&mut self,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.add_startup_system_to_stage(StartupStage::Startup, system)
}
pub fn add_startup_system_set(&mut self, system_set: SystemSet) -> &mut Self {
self.add_startup_system_set_to_stage(StartupStage::Startup, system_set)
}
pub fn add_startup_system_to_stage<Params>(
&mut self,
stage_label: impl StageLabel,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_system_to_stage(stage_label, system)
});
self
}
pub fn add_startup_system_set_to_stage(
&mut self,
stage_label: impl StageLabel,
system_set: SystemSet,
) -> &mut Self {
self.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_system_set_to_stage(stage_label, system_set)
});
self
}
/// Adds a new [State] with the given `initial` value.
/// This inserts a new `State<T>` resource and adds a new "driver" to [CoreStage::Update].
/// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use
/// your state in a different stage, consider using [Self::add_state_to_stage] or manually
/// adding [State::get_driver] to additional stages you need it in.
pub fn add_state<T>(&mut self, initial: T) -> &mut Self
where
T: Component + Debug + Clone + Eq + Hash,
{
self.add_state_to_stage(CoreStage::Update, initial)
}
/// Adds a new [State] with the given `initial` value.
/// This inserts a new `State<T>` resource and adds a new "driver" to the given stage.
/// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use
/// your state in more than one stage, consider manually adding [State::get_driver] to the
/// stages you need it in.
pub fn add_state_to_stage<T>(&mut self, stage: impl StageLabel, initial: T) -> &mut Self
where
T: Component + Debug + Clone + Eq + Hash,
{
self.insert_resource(State::new(initial))
.add_system_set_to_stage(stage, State::<T>::get_driver())
}
pub fn add_default_stages(&mut self) -> &mut Self {
self.add_stage(CoreStage::First, SystemStage::parallel())
.add_stage(
CoreStage::Startup,
Schedule::default()
.with_run_criteria(RunOnce::default())
.with_stage(StartupStage::PreStartup, SystemStage::parallel())
.with_stage(StartupStage::Startup, SystemStage::parallel())
.with_stage(StartupStage::PostStartup, SystemStage::parallel()),
)
.add_stage(CoreStage::PreUpdate, SystemStage::parallel())
.add_stage(CoreStage::Update, SystemStage::parallel())
.add_stage(CoreStage::PostUpdate, SystemStage::parallel())
.add_stage(CoreStage::Last, SystemStage::parallel())
}
/// Setup the application to manage events of type `T`.
///
/// This is done by adding a `Resource` of type `Events::<T>`,
/// and inserting a `Events::<T>::update_system` system into `CoreStage::First`.
pub fn add_event<T>(&mut self) -> &mut Self
where
T: Component,
{
self.insert_resource(Events::<T>::default())
.add_system_to_stage(CoreStage::First, Events::<T>::update_system.system())
}
/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.
///
/// A resource in Bevy represents globally unique data. Resources must be added to Bevy Apps
/// before using them. This happens with [`App::insert_resource`].
///
/// See also `init_resource` for resources that implement `Default` or [`FromResources`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
/// counter: usize,
/// }
///
/// App::new()
/// .insert_resource(MyCounter { counter: 0 });
/// ```
pub fn insert_resource<T>(&mut self, resource: T) -> &mut Self
where
T: Component,
{
self.world.insert_resource(resource);
self
}
/// Inserts a non-send resource to the app
///
/// You usually want to use `insert_resource`, but there are some special cases when a resource must
/// be non-send.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
/// counter: usize,
/// }
///
/// App::new()
/// .insert_non_send_resource(MyCounter { counter: 0 });
/// ```
pub fn insert_non_send_resource<T>(&mut self, resource: T) -> &mut Self
where
T: 'static,
{
self.world.insert_non_send(resource);
self
}
/// Initialize a resource in the current [App], if it does not exist yet
///
/// Adds a resource that implements `Default` or [`FromResources`] trait.
/// If the resource already exists, `init_resource` does nothing.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
/// counter: usize,
/// }
///
/// impl Default for MyCounter {
/// fn default() -> MyCounter {
/// MyCounter {
/// counter: 100
/// }
/// }
/// }
///
/// App::new()
/// .init_resource::<MyCounter>();
/// ```
pub fn init_resource<R>(&mut self) -> &mut Self
where
R: FromWorld + Send + Sync + 'static,
{
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
// not to modify the map. However, we would need to be borrowing resources both
// mutably and immutably, so we would need to be extremely certain this is correct
if !self.world.contains_resource::<R>() {
let resource = R::from_world(&mut self.world);
self.insert_resource(resource);
}
self
}
pub fn init_non_send_resource<R>(&mut self) -> &mut Self
where
R: FromWorld + 'static,
{
// See perf comment in init_resource
if self.world.get_non_send_resource::<R>().is_none() {
let resource = R::from_world(&mut self.world);
self.world.insert_non_send(resource);
}
self
}
/// Sets the main runner loop function for this Bevy App
///
/// Usually the main loop is handled by Bevy integrated plugins ([`WinitPlugin`]), but
/// in some cases one might wish to implement their own main loop.
///
/// This method sets the main loop function, overwriting a previous runner if any.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// fn my_runner(mut app: App) {
/// loop {
/// println!("In main loop");
/// app.update();
/// }
/// }
///
/// App::new()
/// .set_runner(my_runner);
/// ```
pub fn set_runner(&mut self, run_fn: impl Fn(App) + 'static) -> &mut Self {
self.runner = Box::new(run_fn);
self
}
/// Adds a single plugin
///
/// One of Bevy's core principles is modularity. All Bevy engine features are implemented
/// as plugins. This includes internal features like the renderer.
///
/// Bevy also provides a few sets of default plugins. See [`App::add_plugins`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// App::new().add_plugin(bevy_log::LogPlugin::default());
/// ```
pub fn add_plugin<T>(&mut self, plugin: T) -> &mut Self
where
T: Plugin,
{
debug!("added plugin: {}", plugin.name());
plugin.build(self);
self
}
/// Adds a group of plugins
///
/// Bevy plugins can be grouped into a set of plugins. Bevy provides
/// built-in PluginGroups that provide core engine functionality.
///
/// The plugin groups available by default are [`DefaultPlugins`] and [`MinimalPlugins`].
///
/// ## Example
/// ```
/// # use bevy_app::{prelude::*, PluginGroupBuilder};
/// #
/// # // Dummy created to avoid using bevy_internal, which pulls in to many dependencies.
/// # struct MinimalPlugins;
/// # impl PluginGroup for MinimalPlugins {
/// # fn build(&mut self, group: &mut PluginGroupBuilder){;}
/// # }
/// #
/// App::new()
/// .add_plugins(MinimalPlugins);
/// ```
pub fn add_plugins<T: PluginGroup>(&mut self, mut group: T) -> &mut Self {
let mut plugin_group_builder = PluginGroupBuilder::default();
group.build(&mut plugin_group_builder);
plugin_group_builder.finish(self);
self
}
/// Adds a group of plugins with an initializer method
///
/// Can be used to add a group of plugins, where the group is modified
/// before insertion into Bevy application. For example, you can add
/// extra plugins at a specific place in the plugin group, or deactivate
/// specific plugins while keeping the rest.
///
/// ## Example
/// ```
/// # use bevy_app::{prelude::*, PluginGroupBuilder};
/// #
/// # // Dummies created to avoid using bevy_internal which pulls in to many dependencies.
/// # struct DefaultPlugins;
/// # impl PluginGroup for DefaultPlugins {
/// # fn build(&mut self, group: &mut PluginGroupBuilder){
/// # group.add(bevy_log::LogPlugin::default());
/// # }
/// # }
/// #
/// # struct MyOwnPlugin;
/// # impl Plugin for MyOwnPlugin {
/// # fn build(&self, app: &mut App){;}
/// # }
/// #
/// App::new()
/// .add_plugins_with(DefaultPlugins, |group| {
/// group.add_before::<bevy_log::LogPlugin, _>(MyOwnPlugin)
/// });
/// ```
pub fn add_plugins_with<T, F>(&mut self, mut group: T, func: F) -> &mut Self
where
T: PluginGroup,
F: FnOnce(&mut PluginGroupBuilder) -> &mut PluginGroupBuilder,
{
let mut plugin_group_builder = PluginGroupBuilder::default();
group.build(&mut plugin_group_builder);
func(&mut plugin_group_builder);
plugin_group_builder.finish(self);
self
}
/// Registers a new component using the given [ComponentDescriptor]. Components do not need to
/// be manually registered. This just provides a way to override default configuration.
/// Attempting to register a component with a type that has already been used by [World]
/// will result in an error.
///
/// See [World::register_component]
pub fn register_component(&mut self, descriptor: ComponentDescriptor) -> &mut Self {
self.world.register_component(descriptor).unwrap();
self
}
#[cfg(feature = "bevy_reflect")]
pub fn register_type<T: bevy_reflect::GetTypeRegistration>(&mut self) -> &mut Self {
{
let registry = self
.world
.get_resource_mut::<bevy_reflect::TypeRegistryArc>()
.unwrap();
registry.write().register::<T>();
}
self
}
}
fn run_once(mut app: App) {
app.update();
}
/// An event that indicates the app should exit. This will fully exit the app process.

View file

@ -1,559 +0,0 @@
use crate::{
app::{App, AppExit},
plugin::Plugin,
CoreStage, PluginGroup, PluginGroupBuilder, StartupStage,
};
use bevy_ecs::{
component::{Component, ComponentDescriptor},
event::Events,
schedule::{
IntoSystemDescriptor, RunOnce, Schedule, Stage, StageLabel, State, SystemSet, SystemStage,
},
system::{IntoExclusiveSystem, IntoSystem},
world::{FromWorld, World},
};
use bevy_utils::tracing::debug;
use std::{fmt::Debug, hash::Hash};
/// Configure [App]s using the builder pattern
pub struct AppBuilder {
pub app: App,
}
impl Default for AppBuilder {
fn default() -> Self {
let mut app_builder = AppBuilder {
app: App::default(),
};
#[cfg(feature = "bevy_reflect")]
app_builder.init_resource::<bevy_reflect::TypeRegistryArc>();
app_builder
.add_default_stages()
.add_event::<AppExit>()
.add_system_to_stage(CoreStage::Last, World::clear_trackers.exclusive_system());
#[cfg(feature = "bevy_ci_testing")]
{
crate::ci_testing::setup_app(&mut app_builder);
}
app_builder
}
}
impl AppBuilder {
pub fn empty() -> AppBuilder {
AppBuilder {
app: App::default(),
}
}
/// Start the application (through main runner)
///
/// Runs the application main loop.
///
/// Usually the main loop is handled by Bevy integrated plugins (`winit`), but
/// but one can also set the runner function through [`AppBuilder::set_runner`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// App::build()
/// // all required plugin insertions, systems, etc inserted here
/// // finally, call:
/// .run();
/// ```
pub fn run(&mut self) {
let app = std::mem::take(&mut self.app);
app.run();
}
pub fn world(&mut self) -> &World {
&self.app.world
}
pub fn world_mut(&mut self) -> &mut World {
&mut self.app.world
}
pub fn set_world(&mut self, world: World) -> &mut Self {
self.app.world = world;
self
}
pub fn add_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.app.schedule.add_stage(label, stage);
self
}
pub fn add_stage_after<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app.schedule.add_stage_after(target, label, stage);
self
}
pub fn add_stage_before<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app.schedule.add_stage_before(target, label, stage);
self
}
pub fn add_startup_stage<S: Stage>(&mut self, label: impl StageLabel, stage: S) -> &mut Self {
self.app
.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage(label, stage)
});
self
}
pub fn add_startup_stage_after<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app
.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage_after(target, label, stage)
});
self
}
pub fn add_startup_stage_before<S: Stage>(
&mut self,
target: impl StageLabel,
label: impl StageLabel,
stage: S,
) -> &mut Self {
self.app
.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_stage_before(target, label, stage)
});
self
}
pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
&mut self,
label: impl StageLabel,
func: F,
) -> &mut Self {
self.app.schedule.stage(label, func);
self
}
/// Adds a system that runs every time `app.update()` is called by the runner
///
/// Systems are the main building block in the Bevy ECS app model. You can define
/// normal rust functions, and call `.system()` to make them be Bevy systems.
///
/// System functions can have parameters, through which one can query and
/// mutate Bevy ECS states.
/// See [The Bevy Book](https://bevyengine.org/learn/book/introduction/) for more information.
///
/// Systems are run in parallel, and the execution order is not deterministic.
/// If you want more fine-grained control for order, see [`AppBuilder::add_system_to_stage`].
///
/// For adding a system that runs only at app startup, see [`AppBuilder::add_startup_system`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// #
/// fn my_system(_commands: Commands) {
/// println!("My system, triggered once per frame");
/// }
///
/// App::build()
/// .add_system(my_system.system());
/// ```
pub fn add_system<Params>(&mut self, system: impl IntoSystemDescriptor<Params>) -> &mut Self {
self.add_system_to_stage(CoreStage::Update, system)
}
pub fn add_system_set(&mut self, system_set: SystemSet) -> &mut Self {
self.add_system_set_to_stage(CoreStage::Update, system_set)
}
pub fn add_system_to_stage<Params>(
&mut self,
stage_label: impl StageLabel,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.app.schedule.add_system_to_stage(stage_label, system);
self
}
pub fn add_system_set_to_stage(
&mut self,
stage_label: impl StageLabel,
system_set: SystemSet,
) -> &mut Self {
self.app
.schedule
.add_system_set_to_stage(stage_label, system_set);
self
}
/// Adds a system that is run once at application startup
///
/// Startup systems run exactly once BEFORE all other systems. These are generally used for
/// app initialization code (ex: adding entities and resources).
///
/// * For adding a system that runs for every frame, see [`AppBuilder::add_system`].
/// * For adding a system to specific stage, see [`AppBuilder::add_system_to_stage`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// #
/// fn my_startup_system(_commands: Commands) {
/// println!("My startup system");
/// }
///
/// App::build()
/// .add_startup_system(my_startup_system.system());
/// ```
pub fn add_startup_system<Params>(
&mut self,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.add_startup_system_to_stage(StartupStage::Startup, system)
}
pub fn add_startup_system_set(&mut self, system_set: SystemSet) -> &mut Self {
self.add_startup_system_set_to_stage(StartupStage::Startup, system_set)
}
pub fn add_startup_system_to_stage<Params>(
&mut self,
stage_label: impl StageLabel,
system: impl IntoSystemDescriptor<Params>,
) -> &mut Self {
self.app
.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_system_to_stage(stage_label, system)
});
self
}
pub fn add_startup_system_set_to_stage(
&mut self,
stage_label: impl StageLabel,
system_set: SystemSet,
) -> &mut Self {
self.app
.schedule
.stage(CoreStage::Startup, |schedule: &mut Schedule| {
schedule.add_system_set_to_stage(stage_label, system_set)
});
self
}
/// Adds a new [State] with the given `initial` value.
/// This inserts a new `State<T>` resource and adds a new "driver" to [CoreStage::Update].
/// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use
/// your state in a different stage, consider using [Self::add_state_to_stage] or manually
/// adding [State::get_driver] to additional stages you need it in.
pub fn add_state<T>(&mut self, initial: T) -> &mut Self
where
T: Component + Debug + Clone + Eq + Hash,
{
self.add_state_to_stage(CoreStage::Update, initial)
}
/// Adds a new [State] with the given `initial` value.
/// This inserts a new `State<T>` resource and adds a new "driver" to the given stage.
/// Each stage that uses `State<T>` for system run criteria needs a driver. If you need to use
/// your state in more than one stage, consider manually adding [State::get_driver] to the
/// stages you need it in.
pub fn add_state_to_stage<T>(&mut self, stage: impl StageLabel, initial: T) -> &mut Self
where
T: Component + Debug + Clone + Eq + Hash,
{
self.insert_resource(State::new(initial))
.add_system_set_to_stage(stage, State::<T>::get_driver())
}
pub fn add_default_stages(&mut self) -> &mut Self {
self.add_stage(CoreStage::First, SystemStage::parallel())
.add_stage(
CoreStage::Startup,
Schedule::default()
.with_run_criteria(RunOnce::default())
.with_stage(StartupStage::PreStartup, SystemStage::parallel())
.with_stage(StartupStage::Startup, SystemStage::parallel())
.with_stage(StartupStage::PostStartup, SystemStage::parallel()),
)
.add_stage(CoreStage::PreUpdate, SystemStage::parallel())
.add_stage(CoreStage::Update, SystemStage::parallel())
.add_stage(CoreStage::PostUpdate, SystemStage::parallel())
.add_stage(CoreStage::Last, SystemStage::parallel())
}
/// Setup the application to manage events of type `T`.
///
/// This is done by adding a `Resource` of type `Events::<T>`,
/// and inserting a `Events::<T>::update_system` system into `CoreStage::First`.
pub fn add_event<T>(&mut self) -> &mut Self
where
T: Component,
{
self.insert_resource(Events::<T>::default())
.add_system_to_stage(CoreStage::First, Events::<T>::update_system.system())
}
/// Inserts a resource to the current [App] and overwrites any resource previously added of the same type.
///
/// A resource in Bevy represents globally unique data. Resources must be added to Bevy Apps
/// before using them. This happens with [`AppBuilder::insert_resource`].
///
/// See also `init_resource` for resources that implement `Default` or [`FromResources`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
/// counter: usize,
/// }
///
/// App::build()
/// .insert_resource(MyCounter { counter: 0 });
/// ```
pub fn insert_resource<T>(&mut self, resource: T) -> &mut Self
where
T: Component,
{
self.app.world.insert_resource(resource);
self
}
/// Inserts a non-send resource to the app
///
/// You usually want to use `insert_resource`, but there are some special cases when a resource must
/// be non-send.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
/// counter: usize,
/// }
///
/// App::build()
/// .insert_non_send_resource(MyCounter { counter: 0 });
/// ```
pub fn insert_non_send_resource<T>(&mut self, resource: T) -> &mut Self
where
T: 'static,
{
self.app.world.insert_non_send(resource);
self
}
/// Initialize a resource in the current [App], if it does not exist yet
///
/// Adds a resource that implements `Default` or [`FromResources`] trait.
/// If the resource already exists, `init_resource` does nothing.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// struct MyCounter {
/// counter: usize,
/// }
///
/// impl Default for MyCounter {
/// fn default() -> MyCounter {
/// MyCounter {
/// counter: 100
/// }
/// }
/// }
///
/// App::build()
/// .init_resource::<MyCounter>();
/// ```
pub fn init_resource<R>(&mut self) -> &mut Self
where
R: FromWorld + Send + Sync + 'static,
{
// PERF: We could avoid double hashing here, since the `from_resources` call is guaranteed
// not to modify the map. However, we would need to be borrowing resources both
// mutably and immutably, so we would need to be extremely certain this is correct
if !self.world_mut().contains_resource::<R>() {
let resource = R::from_world(self.world_mut());
self.insert_resource(resource);
}
self
}
pub fn init_non_send_resource<R>(&mut self) -> &mut Self
where
R: FromWorld + 'static,
{
// See perf comment in init_resource
if self.app.world.get_non_send_resource::<R>().is_none() {
let resource = R::from_world(self.world_mut());
self.app.world.insert_non_send(resource);
}
self
}
/// Sets the main runner loop function for this Bevy App
///
/// Usually the main loop is handled by Bevy integrated plugins ([`WinitPlugin`]), but
/// in some cases one might wish to implement their own main loop.
///
/// This method sets the main loop function, overwriting a previous runner if any.
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// fn my_runner(mut app: App) {
/// loop {
/// println!("In main loop");
/// app.update();
/// }
/// }
///
/// App::build()
/// .set_runner(my_runner);
/// ```
pub fn set_runner(&mut self, run_fn: impl Fn(App) + 'static) -> &mut Self {
self.app.runner = Box::new(run_fn);
self
}
/// Adds a single plugin
///
/// One of Bevy's core principles is modularity. All Bevy engine features are implemented
/// as plugins. This includes internal features like the renderer.
///
/// Bevy also provides a few sets of default plugins. See [`AppBuilder::add_plugins`].
///
/// ## Example
/// ```
/// # use bevy_app::prelude::*;
/// #
/// App::build().add_plugin(bevy_log::LogPlugin::default());
/// ```
pub fn add_plugin<T>(&mut self, plugin: T) -> &mut Self
where
T: Plugin,
{
debug!("added plugin: {}", plugin.name());
plugin.build(self);
self
}
/// Adds a group of plugins
///
/// Bevy plugins can be grouped into a set of plugins. Bevy provides
/// built-in PluginGroups that provide core engine functionality.
///
/// The plugin groups available by default are [`DefaultPlugins`] and [`MinimalPlugins`].
///
/// ## Example
/// ```
/// # use bevy_app::{prelude::*, PluginGroupBuilder};
/// #
/// # // Dummy created to avoid using bevy_internal, which pulls in to many dependencies.
/// # struct MinimalPlugins;
/// # impl PluginGroup for MinimalPlugins {
/// # fn build(&mut self, group: &mut PluginGroupBuilder){;}
/// # }
/// #
/// App::build()
/// .add_plugins(MinimalPlugins);
/// ```
pub fn add_plugins<T: PluginGroup>(&mut self, mut group: T) -> &mut Self {
let mut plugin_group_builder = PluginGroupBuilder::default();
group.build(&mut plugin_group_builder);
plugin_group_builder.finish(self);
self
}
/// Adds a group of plugins with an initializer method
///
/// Can be used to add a group of plugins, where the group is modified
/// before insertion into Bevy application. For example, you can add
/// extra plugins at a specific place in the plugin group, or deactivate
/// specific plugins while keeping the rest.
///
/// ## Example
/// ```
/// # use bevy_app::{prelude::*, PluginGroupBuilder};
/// #
/// # // Dummies created to avoid using bevy_internal which pulls in to many dependencies.
/// # struct DefaultPlugins;
/// # impl PluginGroup for DefaultPlugins {
/// # fn build(&mut self, group: &mut PluginGroupBuilder){
/// # group.add(bevy_log::LogPlugin::default());
/// # }
/// # }
/// #
/// # struct MyOwnPlugin;
/// # impl Plugin for MyOwnPlugin {
/// # fn build(&self, app: &mut AppBuilder){;}
/// # }
/// #
/// App::build()
/// .add_plugins_with(DefaultPlugins, |group| {
/// group.add_before::<bevy_log::LogPlugin, _>(MyOwnPlugin)
/// });
/// ```
pub fn add_plugins_with<T, F>(&mut self, mut group: T, func: F) -> &mut Self
where
T: PluginGroup,
F: FnOnce(&mut PluginGroupBuilder) -> &mut PluginGroupBuilder,
{
let mut plugin_group_builder = PluginGroupBuilder::default();
group.build(&mut plugin_group_builder);
func(&mut plugin_group_builder);
plugin_group_builder.finish(self);
self
}
/// Registers a new component using the given [ComponentDescriptor]. Components do not need to
/// be manually registered. This just provides a way to override default configuration.
/// Attempting to register a component with a type that has already been used by [World]
/// will result in an error.
///
/// See [World::register_component]
pub fn register_component(&mut self, descriptor: ComponentDescriptor) -> &mut Self {
self.world_mut().register_component(descriptor).unwrap();
self
}
#[cfg(feature = "bevy_reflect")]
pub fn register_type<T: bevy_reflect::GetTypeRegistration>(&mut self) -> &mut Self {
{
let registry = self
.world_mut()
.get_resource_mut::<bevy_reflect::TypeRegistryArc>()
.unwrap();
registry.write().register::<T>();
}
self
}
}

View file

@ -1,6 +1,6 @@
use serde::Deserialize;
use crate::{app::AppExit, AppBuilder};
use crate::{app::AppExit, App};
use bevy_ecs::system::IntoSystem;
/// Configuration for automated testing on CI
@ -23,7 +23,7 @@ fn ci_testing_exit_after(
*current_frame += 1;
}
pub(crate) fn setup_app(app_builder: &mut AppBuilder) -> &mut AppBuilder {
pub(crate) fn setup_app(app_builder: &mut App) -> &mut App {
let filename =
std::env::var("CI_TESTING_CONFIG").unwrap_or_else(|_| "ci_testing_config.ron".to_string());
let config: CiTestingConfig = ron::from_str(

View file

@ -1,5 +1,4 @@
mod app;
mod app_builder;
mod plugin;
mod plugin_group;
mod schedule_runner;
@ -8,7 +7,6 @@ mod schedule_runner;
mod ci_testing;
pub use app::*;
pub use app_builder::*;
pub use bevy_derive::DynamicPlugin;
pub use bevy_ecs::event::*;
pub use plugin::*;
@ -17,10 +15,7 @@ pub use schedule_runner::*;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
app::App, app_builder::AppBuilder, CoreStage, DynamicPlugin, Plugin, PluginGroup,
StartupStage,
};
pub use crate::{app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage};
}
use bevy_ecs::schedule::StageLabel;

View file

@ -1,12 +1,12 @@
use crate::AppBuilder;
use crate::App;
use std::any::Any;
/// A collection of Bevy App logic and configuration
///
/// Plugins use [AppBuilder] to configure an [App](crate::App). When an [App](crate::App) registers
/// Plugins configure an [App](crate::App). When an [App](crate::App) registers
/// a plugin, the plugin's [Plugin::build] function is run.
pub trait Plugin: Any + Send + Sync {
fn build(&self, app: &mut AppBuilder);
fn build(&self, app: &mut App);
fn name(&self) -> &str {
std::any::type_name::<Self>()
}

View file

@ -1,4 +1,4 @@
use crate::{AppBuilder, Plugin};
use crate::{App, Plugin};
use bevy_utils::{tracing::debug, HashMap};
use std::any::TypeId;
@ -96,7 +96,7 @@ impl PluginGroupBuilder {
self
}
pub fn finish(self, app: &mut AppBuilder) {
pub fn finish(self, app: &mut App) {
for ty in self.order.iter() {
if let Some(entry) = self.plugins.get(ty) {
if entry.enabled {

View file

@ -1,5 +1,8 @@
use super::{App, AppBuilder};
use crate::{app::AppExit, plugin::Plugin, ManualEventReader};
use crate::{
app::{App, AppExit},
plugin::Plugin,
ManualEventReader,
};
use bevy_ecs::event::Events;
use bevy_utils::{Duration, Instant};
@ -48,9 +51,9 @@ impl ScheduleRunnerSettings {
pub struct ScheduleRunnerPlugin {}
impl Plugin for ScheduleRunnerPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
let settings = app
.world_mut()
.world
.get_resource_or_insert_with(ScheduleRunnerSettings::default)
.to_owned();
app.set_runner(move |mut app: App| {

View file

@ -2,7 +2,7 @@ use crate::{
update_asset_storage_system, Asset, AssetLoader, AssetServer, AssetStage, Handle, HandleId,
RefChange,
};
use bevy_app::{AppBuilder, EventWriter, Events};
use bevy_app::{App, EventWriter, Events};
use bevy_ecs::{
system::{IntoSystem, ResMut},
world::FromWorld,
@ -193,7 +193,7 @@ impl<T: Asset> Assets<T> {
}
}
/// [AppBuilder] extension methods for adding new asset types
/// [App] extension methods for adding new asset types
pub trait AddAsset {
fn add_asset<T>(&mut self) -> &mut Self
where
@ -206,13 +206,13 @@ pub trait AddAsset {
T: AssetLoader;
}
impl AddAsset for AppBuilder {
impl AddAsset for App {
fn add_asset<T>(&mut self) -> &mut Self
where
T: Asset,
{
let assets = {
let asset_server = self.world().get_resource::<AssetServer>().unwrap();
let asset_server = self.world.get_resource::<AssetServer>().unwrap();
asset_server.register_asset_type::<T>()
};
@ -233,7 +233,7 @@ impl AddAsset for AppBuilder {
where
T: AssetLoader + FromWorld,
{
let result = T::from_world(self.world_mut());
let result = T::from_world(&mut self.world);
self.add_asset_loader(result)
}
@ -241,7 +241,7 @@ impl AddAsset for AppBuilder {
where
T: AssetLoader,
{
self.world_mut()
self.world
.get_resource_mut::<AssetServer>()
.expect("AssetServer does not exist. Consider adding it as a resource.")
.add_loader(loader);

View file

@ -17,7 +17,7 @@ impl<T: Asset> Default for AssetCountDiagnosticsPlugin<T> {
}
impl<T: Asset> Plugin for AssetCountDiagnosticsPlugin<T> {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.system());
}

View file

@ -26,7 +26,7 @@ pub use io::*;
pub use loader::*;
pub use path::*;
use bevy_app::{prelude::Plugin, AppBuilder};
use bevy_app::{prelude::Plugin, App};
use bevy_ecs::{
schedule::{StageLabel, SystemStage},
system::IntoSystem,
@ -61,9 +61,9 @@ impl Default for AssetServerSettings {
///
/// This is useful when providing a custom `AssetIo` instance that needs to
/// delegate to the default `AssetIo` for the platform.
pub fn create_platform_default_asset_io(app: &mut AppBuilder) -> Box<dyn AssetIo> {
pub fn create_platform_default_asset_io(app: &mut App) -> Box<dyn AssetIo> {
let settings = app
.world_mut()
.world
.get_resource_or_insert_with(AssetServerSettings::default);
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))]
@ -77,10 +77,10 @@ pub fn create_platform_default_asset_io(app: &mut AppBuilder) -> Box<dyn AssetIo
}
impl Plugin for AssetPlugin {
fn build(&self, app: &mut AppBuilder) {
if app.world().get_resource::<AssetServer>().is_none() {
fn build(&self, app: &mut App) {
if app.world.get_resource::<AssetServer>().is_none() {
let task_pool = app
.world()
.world
.get_resource::<IoTaskPool>()
.expect("`IoTaskPool` resource not found.")
.0

View file

@ -20,7 +20,7 @@ use bevy_ecs::system::IntoExclusiveSystem;
pub struct AudioPlugin;
impl Plugin for AudioPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_non_send_resource::<AudioOutput<AudioSource>>()
.add_asset::<AudioSource>()
.init_resource::<Audio<AudioSource>>()

View file

@ -38,13 +38,13 @@ pub enum CoreSystem {
}
impl Plugin for CorePlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
// Setup the default bevy task pools
app.world_mut()
app.world
.get_resource::<DefaultTaskPoolOptions>()
.cloned()
.unwrap_or_else(DefaultTaskPoolOptions::default)
.create_default_pools(app.world_mut());
.create_default_pools(&mut app.world);
app.init_resource::<Time>()
.init_resource::<EntityLabels>()
@ -70,7 +70,7 @@ impl Plugin for CorePlugin {
}
}
fn register_rust_types(app: &mut AppBuilder) {
fn register_rust_types(app: &mut App) {
app.register_type::<bool>()
.register_type::<u8>()
.register_type::<u16>()
@ -90,7 +90,7 @@ fn register_rust_types(app: &mut AppBuilder) {
.register_type::<Option<String>>();
}
fn register_math_types(app: &mut AppBuilder) {
fn register_math_types(app: &mut App) {
app.register_type::<bevy_math::IVec2>()
.register_type::<bevy_math::IVec3>()
.register_type::<bevy_math::IVec4>()

View file

@ -1,4 +1,4 @@
use bevy_app::{AppBuilder, Plugin};
use bevy_app::{App, Plugin};
use bevy_ecs::{
system::{IntoExclusiveSystem, IntoSystem, ResMut},
world::World,
@ -11,7 +11,7 @@ use crate::{Diagnostic, DiagnosticId, Diagnostics};
pub struct EntityCountDiagnosticsPlugin;
impl Plugin for EntityCountDiagnosticsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.exclusive_system());
}

View file

@ -12,7 +12,7 @@ pub struct FrameTimeDiagnosticsState {
}
impl Plugin for FrameTimeDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::AppBuilder) {
fn build(&self, app: &mut bevy_app::App) {
app.add_startup_system(Self::setup_system.system())
.insert_resource(FrameTimeDiagnosticsState { frame_count: 0.0 })
.add_system(Self::diagnostic_system.system());

View file

@ -14,7 +14,7 @@ use bevy_app::prelude::*;
pub struct DiagnosticsPlugin;
impl Plugin for DiagnosticsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_resource::<Diagnostics>();
}
}

View file

@ -29,7 +29,7 @@ impl Default for LogDiagnosticsPlugin {
}
impl Plugin for LogDiagnosticsPlugin {
fn build(&self, app: &mut bevy_app::AppBuilder) {
fn build(&self, app: &mut App) {
app.insert_resource(LogDiagnosticsState {
timer: Timer::new(self.wait_duration, true),
filter: self.filter.clone(),

View file

@ -1,6 +1,6 @@
use libloading::{Library, Symbol};
use bevy_app::{AppBuilder, CreatePlugin, Plugin};
use bevy_app::{App, CreatePlugin, Plugin};
/// Dynamically links a plugin a the given path. The plugin must export a function with the
/// [`CreatePlugin`] signature named `_bevy_create_plugin`.
@ -24,7 +24,7 @@ pub trait DynamicPluginExt {
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self;
}
impl DynamicPluginExt for AppBuilder {
impl DynamicPluginExt for App {
unsafe fn load_plugin(&mut self, path: &str) -> &mut Self {
let (lib, plugin) = dynamically_load_plugin(path);
std::mem::forget(lib); // Ensure that the library is not automatically unloaded

View file

@ -68,7 +68,7 @@ enum State {
/// [`Events::update`] exactly once per update/frame.
///
/// [`Events::update_system`] is a system that does this, typically intialized automatically using
/// [`AppBuilder::add_event`]. [EventReader]s are expected to read events from this collection at
/// [`App::add_event`]. [EventReader]s are expected to read events from this collection at
/// least once per loop/frame.
/// Events will persist across a single frame boundary and so ordering of event producers and
/// consumers is not critical (although poorly-planned ordering may cause accumulating lag).
@ -115,9 +115,9 @@ enum State {
/// An alternative call pattern would be to call [Events::update] manually across frames to control
/// when events are cleared.
/// This complicates consumption and risks ever-expanding memory usage if not cleaned up,
/// but can be done by adding your event as a resource instead of using [`AppBuilder::add_event`].
/// but can be done by adding your event as a resource instead of using [`App::add_event`].
///
/// [`AppBuilder::add_event`]: https://docs.rs/bevy/*/bevy/app/struct.AppBuilder.html#method.add_event
/// [`App::add_event`]: https://docs.rs/bevy/*/bevy/app/struct.App.html#method.add_event
#[derive(Debug)]
pub struct Events<T> {
events_a: Vec<EventInstance<T>>,

View file

@ -26,7 +26,7 @@ pub trait Stage: Downcast + Send + Sync {
impl_downcast!(Stage);
/// When this resource is present in the `AppBuilder`'s `Resources`,
/// When this resource is present in the `App`'s `Resources`,
/// each `SystemStage` will log a report containing
/// pairs of systems with ambiguous execution order.
///

View file

@ -24,7 +24,7 @@ impl SystemId {
///
/// Systems are functions with all arguments implementing [SystemParam](crate::system::SystemParam).
///
/// Systems are added to an application using `AppBuilder::add_system(my_system.system())`
/// Systems are added to an application using `App::add_system(my_system.system())`
/// or similar methods, and will generally run once per pass of the main loop.
///
/// Systems are executed in parallel, in opportunistic order; data access is managed automatically.

View file

@ -1,7 +1,7 @@
mod converter;
mod gilrs_system;
use bevy_app::{AppBuilder, CoreStage, Plugin, StartupStage};
use bevy_app::{App, CoreStage, Plugin, StartupStage};
use bevy_ecs::system::IntoExclusiveSystem;
use bevy_utils::tracing::error;
use gilrs::GilrsBuilder;
@ -11,7 +11,7 @@ use gilrs_system::{gilrs_event_startup_system, gilrs_event_system};
pub struct GilrsPlugin;
impl Plugin for GilrsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
match GilrsBuilder::new()
.with_default_filters(false)
.set_update_state(false)

View file

@ -15,7 +15,7 @@ use bevy_scene::Scene;
pub struct GltfPlugin;
impl Plugin for GltfPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_asset_loader::<GltfLoader>()
.add_asset::<Gltf>()
.add_asset::<GltfNode>()

View file

@ -45,7 +45,7 @@ pub struct InputPlugin;
pub struct InputSystem;
impl Plugin for InputPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app
// keyboard
.add_event::<KeyboardInput>()

View file

@ -12,7 +12,7 @@ pub use bevy_utils::tracing::{
Level,
};
use bevy_app::{AppBuilder, Plugin};
use bevy_app::{App, Plugin};
#[cfg(feature = "tracing-chrome")]
use tracing_subscriber::fmt::{format::DefaultFields, FormattedFields};
use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter};
@ -33,7 +33,7 @@ use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter};
/// # use bevy_log::LogSettings;
/// # use bevy_utils::tracing::Level;
/// fn main() {
/// App::build()
/// App::new()
/// .insert_resource(LogSettings {
/// level: Level::DEBUG,
/// filter: "wgpu=error,bevy_render=info".to_string(),
@ -47,13 +47,13 @@ use tracing_subscriber::{prelude::*, registry::Registry, EnvFilter};
/// It has the same syntax has the field [`LogSettings::filter`], see [`EnvFilter`].
///
/// If you want to setup your own tracing collector, you should disable this
/// plugin from `DefaultPlugins` with [`AppBuilder::add_plugins_with`]:
/// plugin from `DefaultPlugins` with [`App::add_plugins_with`]:
/// ```no_run
/// # use bevy_internal::DefaultPlugins;
/// # use bevy_app::App;
/// # use bevy_log::LogPlugin;
/// fn main() {
/// App::build()
/// App::new()
/// .add_plugins_with(DefaultPlugins, |group| group.disable::<LogPlugin>())
/// .run();
/// }
@ -81,11 +81,9 @@ impl Default for LogSettings {
}
impl Plugin for LogPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
let default_filter = {
let settings = app
.world_mut()
.get_resource_or_insert_with(LogSettings::default);
let settings = app.world.get_resource_or_insert_with(LogSettings::default);
format!("{},{}", settings.level, settings.filter)
};
@ -114,7 +112,7 @@ impl Plugin for LogPlugin {
}
}))
.build();
app.world_mut().insert_non_send(guard);
app.world.insert_non_send(guard);
let subscriber = subscriber.with(chrome_layer);
bevy_utils::tracing::subscriber::set_global_default(subscriber)
.expect("Could not set global default tracing subscriber. If you've already set up a tracing subscriber, please disable LogPlugin from Bevy's DefaultPlugins");

View file

@ -29,7 +29,7 @@ use render_graph::add_pbr_graph;
pub struct PbrPlugin;
impl Plugin for PbrPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_asset::<StandardMaterial>()
.register_type::<PointLight>()
.add_system_to_stage(
@ -37,11 +37,11 @@ impl Plugin for PbrPlugin {
shader::asset_shader_defs_system::<StandardMaterial>.system(),
)
.init_resource::<AmbientLight>();
add_pbr_graph(app.world_mut());
add_pbr_graph(&mut app.world);
// add default StandardMaterial
let mut materials = app
.world_mut()
.world
.get_resource_mut::<Assets<StandardMaterial>>()
.unwrap();
materials.set_untracked(

View file

@ -102,7 +102,7 @@ impl Default for RenderPlugin {
}
impl Plugin for RenderPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
#[cfg(any(
feature = "png",
feature = "dds",
@ -228,8 +228,8 @@ impl Plugin for RenderPlugin {
);
if let Some(ref config) = self.base_render_graph_config {
crate::base::add_base_graph(config, app.world_mut());
let mut active_cameras = app.world_mut().get_resource_mut::<ActiveCameras>().unwrap();
crate::base::add_base_graph(config, &mut app.world);
let mut active_cameras = app.world.get_resource_mut::<ActiveCameras>().unwrap();
if config.add_3d_camera {
active_cameras.add(base::camera::CAMERA_3D);
}

View file

@ -25,10 +25,10 @@ pub const WIREFRAME_PIPELINE_HANDLE: HandleUntyped =
pub struct WireframePlugin;
impl Plugin for WireframePlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_resource::<WireframeConfig>()
.add_system_to_stage(crate::RenderStage::Draw, draw_wireframes_system.system());
let world = app.world_mut().cell();
let world = app.world.cell();
let mut shaders = world.get_resource_mut::<Assets<Shader>>().unwrap();
let mut pipelines = world
.get_resource_mut::<Assets<PipelineDescriptor>>()

View file

@ -26,7 +26,7 @@ use bevy_ecs::{schedule::ExclusiveSystemDescriptorCoercion, system::IntoExclusiv
pub struct ScenePlugin;
impl Plugin for ScenePlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_asset::<DynamicScene>()
.add_asset::<Scene>()
.init_asset_loader::<SceneLoader>()

View file

@ -67,7 +67,7 @@ pub const QUAD_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Mesh::TYPE_UUID, 14240461981130137526);
impl Plugin for SpritePlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_asset::<ColorMaterial>()
.add_asset::<TextureAtlas>()
.register_type::<Sprite>()
@ -83,7 +83,7 @@ impl Plugin for SpritePlugin {
);
let sprite_settings = app
.world_mut()
.world
.get_resource_or_insert_with(SpriteSettings::default)
.clone();
if sprite_settings.frustum_culling_enabled {
@ -96,14 +96,13 @@ impl Plugin for SpritePlugin {
frustum_culling::atlas_frustum_culling_system.system(),
);
}
let world = app.world_mut();
world
app.world
.register_component(ComponentDescriptor::new::<OutsideFrustum>(
StorageType::SparseSet,
))
.unwrap();
let world_cell = world.cell();
let world_cell = app.world.cell();
let mut render_graph = world_cell.get_resource_mut::<RenderGraph>().unwrap();
let mut pipelines = world_cell
.get_resource_mut::<Assets<PipelineDescriptor>>()

View file

@ -38,7 +38,7 @@ pub type DefaultTextPipeline = TextPipeline<Entity>;
pub struct TextPlugin;
impl Plugin for TextPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_asset::<Font>()
.add_asset::<FontAtlasSet>()
.init_asset_loader::<FontLoader>()

View file

@ -24,7 +24,7 @@ pub enum TransformSystem {
}
impl Plugin for TransformPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.register_type::<Children>()
.register_type::<Parent>()
.register_type::<PreviousParent>()

View file

@ -43,7 +43,7 @@ pub enum UiSystem {
}
impl Plugin for UiPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_resource::<FlexSurface>()
.register_type::<AlignContent>()
.register_type::<AlignItems>()
@ -92,6 +92,6 @@ impl Plugin for UiPlugin {
)
.add_system_to_stage(RenderStage::Draw, widget::draw_text_system.system());
crate::render::add_ui_graph(app.world_mut());
crate::render::add_ui_graph(&mut app.world);
}
}

View file

@ -8,7 +8,7 @@ use bevy_render::renderer::RenderResourceContext;
pub struct WgpuResourceDiagnosticsPlugin;
impl Plugin for WgpuResourceDiagnosticsPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_startup_system(Self::setup_system.system())
.add_system(Self::diagnostic_system.system());
}

View file

@ -104,8 +104,8 @@ impl Default for WgpuLimits {
pub struct WgpuPlugin;
impl Plugin for WgpuPlugin {
fn build(&self, app: &mut AppBuilder) {
let render_system = get_wgpu_render_system(app.world_mut());
fn build(&self, app: &mut App) {
let render_system = get_wgpu_render_system(&mut app.world);
app.add_system_to_stage(RenderStage::Render, render_system.exclusive_system())
.add_system_to_stage(
RenderStage::PostRender,

View file

@ -34,7 +34,7 @@ impl Default for WindowPlugin {
}
impl Plugin for WindowPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_event::<WindowResized>()
.add_event::<CreateWindow>()
.add_event::<WindowCreated>()
@ -52,12 +52,15 @@ impl Plugin for WindowPlugin {
.init_resource::<Windows>();
if self.add_primary_window {
let world = app.world_mut();
let window_descriptor = world
let window_descriptor = app
.world
.get_resource::<WindowDescriptor>()
.map(|descriptor| (*descriptor).clone())
.unwrap_or_else(WindowDescriptor::default);
let mut create_window_event = world.get_resource_mut::<Events<CreateWindow>>().unwrap();
let mut create_window_event = app
.world
.get_resource_mut::<Events<CreateWindow>>()
.unwrap();
create_window_event.send(CreateWindow {
id: WindowId::primary(),
descriptor: window_descriptor,

View file

@ -10,7 +10,7 @@ use bevy_input::{
pub use winit_config::*;
pub use winit_windows::*;
use bevy_app::{App, AppBuilder, AppExit, CoreStage, Events, ManualEventReader, Plugin};
use bevy_app::{App, AppExit, CoreStage, Events, ManualEventReader, Plugin};
use bevy_ecs::{system::IntoExclusiveSystem, world::World};
use bevy_math::{ivec2, Vec2};
use bevy_utils::tracing::{error, trace, warn};
@ -39,7 +39,7 @@ use winit::platform::unix::EventLoopExtUnix;
pub struct WinitPlugin;
impl Plugin for WinitPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.init_resource::<WinitWindows>()
.set_runner(winit_runner)
.add_system_to_stage(CoreStage::PostUpdate, change_window.exclusive_system());

View file

@ -7,7 +7,7 @@ use std::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(velocity_system)

View file

@ -15,7 +15,7 @@ pub struct Position(Transform);
/// This example is for performance testing purposes.
/// See https://github.com/bevyengine/bevy/pull/1492
fn main() {
App::build()
App::new()
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.insert_resource(SpriteSettings {

View file

@ -7,7 +7,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(star)
.run();

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.run();

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.run();

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(animate_sprite_system)

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(animate_translation)

View file

@ -3,7 +3,7 @@ use bevy::{asset::LoadState, prelude::*, sprite::TextureAtlasBuilder};
/// In this example we generate a new texture atlas (sprite sheet) from a folder containing
/// individual sprites
fn main() {
App::build()
App::new()
.init_resource::<RpgSpriteHandles>()
.add_plugins(DefaultPlugins)
.add_state(AppState::Setup)

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -1,7 +1,7 @@
use bevy::{pbr::AmbientLight, prelude::*};
fn main() {
App::build()
App::new()
.insert_resource(AmbientLight {
color: Color::WHITE,
brightness: 1.0 / 5.0f32,

View file

@ -5,7 +5,7 @@ use bevy::prelude::*;
/// range should generally be somewhere between 1 (no multi sampling, but cheap) to 8 (crisp but
/// expensive)
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example illustrates how to create parent->child relationships between entities how parent
/// transforms are propagated to their descendants
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -2,7 +2,7 @@ use bevy::prelude::*;
/// This example shows how to configure Physically Based Rendering (PBR) parameters.
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -224,7 +224,7 @@ fn setup(
}
fn main() {
let mut app = App::build();
let mut app = App::new();
app.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(cube_rotator_system.system())

View file

@ -13,7 +13,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
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())

View file

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

View file

@ -1,7 +1,7 @@
use bevy::{prelude::*, scene::InstanceId};
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.insert_resource(SceneInstance::default())

View file

@ -5,7 +5,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(WgpuOptions {
features: WgpuFeatures {

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
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(rotator_system.system())

View file

@ -3,7 +3,7 @@ use bevy::prelude::*;
// the `bevy_main` proc_macro generates the required android boilerplate
#[bevy_main]
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 2 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -21,7 +21,7 @@ fn print_system(input: Res<Input>) {
}
fn main() {
App::build()
App::new()
.insert_resource(Input(String::new()))
.set_runner(my_runner)
.add_system(print_system.system())

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_system(file_drag_and_drop_system.system())
.run();

View file

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

View file

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

View file

@ -10,14 +10,14 @@ use bevy::{app::ScheduleRunnerSettings, prelude::*, utils::Duration};
fn main() {
// this app runs once
App::build()
App::new()
.insert_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_system(hello_world_system.system())
.run();
// this app loops forever at 60 fps
App::build()
App::new()
.insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64(
1.0 / 60.0,
)))

View file

@ -2,7 +2,7 @@ use bevy::prelude::*;
/// This example illustrates how to use logs in bevy
fn main() {
App::build()
App::new()
// Uncomment this to override the default log settings:
// .insert_resource(bevy::log::LogSettings {
// level: bevy::log::Level::TRACE,

View file

@ -4,7 +4,7 @@ use bevy::{prelude::*, utils::Duration};
/// that provide a specific piece of functionality (generally the smaller the scope, the better).
/// This example illustrates how to create a simple plugin that prints out a message.
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
// plugins are registered as part of the "app building" process
.add_plugin(PrintMessagePlugin {
@ -23,7 +23,7 @@ pub struct PrintMessagePlugin {
impl Plugin for PrintMessagePlugin {
// this is where we set up our plugin
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
let state = PrintMessageState {
message: self.message.clone(),
timer: Timer::new(self.wait_duration, true),

View file

@ -2,7 +2,7 @@ use bevy::{app::PluginGroupBuilder, prelude::*};
/// PluginGroups are a way to group sets of plugins that should be registered together.
fn main() {
App::build()
App::new()
// Two PluginGroups that are included with bevy are DefaultPlugins and MinimalPlugins
.add_plugins(DefaultPlugins)
// Adding a plugin group adds all plugins in the group by default
@ -28,7 +28,7 @@ impl PluginGroup for HelloWorldPlugins {
pub struct PrintHelloPlugin;
impl Plugin for PrintHelloPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_system(print_hello_system.system());
}
}
@ -40,7 +40,7 @@ fn print_hello_system() {
pub struct PrintWorldPlugin;
impl Plugin for PrintWorldPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
app.add_system(print_world_system.system());
}
}

View file

@ -2,7 +2,7 @@ use bevy::{prelude::*, render::pass::ClearColor, winit::WinitConfig};
fn main() {
println!("Running first App.");
App::build()
App::new()
.insert_resource(WinitConfig {
return_from_run: true,
})
@ -11,7 +11,7 @@ fn main() {
.add_system(system1.system())
.run();
println!("Running another App.");
App::build()
App::new()
.insert_resource(WinitConfig {
return_from_run: true,
})

View file

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example illustrates how to customize the thread pool used internally (e.g. to only use a
/// certain number of threads).
fn main() {
App::build()
App::new()
.insert_resource(DefaultTaskPoolOptions::with_num_threads(4))
.add_plugins(DefaultPlugins)
.run();

View file

@ -2,7 +2,7 @@ use bevy::prelude::*;
/// This example illustrates various ways to load assets
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())

View file

@ -34,7 +34,7 @@ impl AssetLoader for CustomAssetLoader {
}
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<State>()
.add_asset::<CustomAsset>()

View file

@ -46,11 +46,11 @@ impl AssetIo for CustomAssetIo {
struct CustomAssetIoPlugin;
impl Plugin for CustomAssetIoPlugin {
fn build(&self, app: &mut AppBuilder) {
fn build(&self, app: &mut App) {
// must get a hold of the task pool in order to create the asset server
let task_pool = app
.world()
.world
.get_resource::<bevy::tasks::IoTaskPool>()
.expect("`IoTaskPool` resource not found.")
.0
@ -74,7 +74,7 @@ impl Plugin for CustomAssetIoPlugin {
}
fn main() {
App::build()
App::new()
.add_plugins_with(DefaultPlugins, |group| {
// the custom asset io plugin must be inserted in-between the
// `CorePlugin' and `AssetPlugin`. It needs to be after the

View file

@ -4,7 +4,7 @@ use bevy::prelude::*;
/// game is running. This lets you immediately see the results of your changes without restarting
/// the game. This example illustrates hot reloading mesh changes.
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.run();

View file

@ -9,7 +9,7 @@ use std::time::{Duration, Instant};
/// This example shows how to use the ECS and the AsyncComputeTaskPool
/// to spawn, poll, and complete tasks across systems and system ticks.
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup_env.system())

View file

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

View file

@ -5,7 +5,7 @@ use bevy::{
/// This example illustrates how to create a custom diagnostic
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
// The "print diagnostics" plugin is optional. It just visualizes our diagnostics in the
// console

View file

@ -4,7 +4,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
// Adds frame time diagnostics
.add_plugin(FrameTimeDiagnosticsPlugin::default())

View file

@ -3,7 +3,7 @@ use rand::Rng;
// This example illustrates how to react to component change
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(change_component.system())

View file

@ -262,7 +262,7 @@ enum MyLabels {
fn main() {
// Bevy apps are created using the builder pattern. We use the builder to add systems,
// resources, and plugins to our app
App::build()
App::new()
// Resources can be added to our app like this
.insert_resource(State { counter: 0 })
// Some systems are configured by adding their settings as a resource

View file

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example creates a new event, a system that triggers the event once per second,
/// and a system that prints a message whenever the event is received.
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_event::<MyEvent>()
.init_resource::<EventTriggerState>()

View file

@ -9,7 +9,7 @@ const LABEL: &str = "my_fixed_timestep";
struct FixedUpdateStage;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
// this system will run once every update (it should match your screen's refresh rate)
.add_system(frame_update.system())

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(rotate.system())

View file

@ -7,7 +7,7 @@ struct FixedUpdateStage;
const DELTA_TIME: f64 = 0.01;
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(generate_bodies.system())

View file

@ -68,7 +68,7 @@ fn bounce_system(
}
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(spawn_system.system())
.add_system(move_system.system())

View file

@ -1,7 +1,7 @@
use bevy::{log::LogPlugin, prelude::*};
fn main() {
App::build()
App::new()
.add_plugin(LogPlugin)
.add_startup_system(setup.system())
.add_system(log_names.system().label(LogNamesSystem))

View file

@ -13,7 +13,7 @@ fn main() {
// With these constraints in mind we make sure to place the system that removes a `Component` on
// the `CoreStage::Update' stage, and the system that reacts on the removal on the
// `CoreStage::PostUpdate` stage.
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system_to_stage(CoreStage::Update, remove_component.system())

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_startup_system(startup_system.system())
.add_system(normal_system.system())
.run();

View file

@ -3,7 +3,7 @@ use bevy::prelude::*;
/// This example illustrates how to use States to control transitioning from a Menu state to an
/// InGame state.
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<ButtonMaterials>()
.add_state(AppState::Menu)

View file

@ -2,7 +2,7 @@ use anyhow::Result;
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.insert_resource(Message("42".to_string()))
.add_system(parse_message_system.system().chain(handler_system.system()))
.run();

View file

@ -2,7 +2,7 @@ use bevy::{ecs::system::SystemParam, prelude::*};
/// This example creates a SystemParam struct that counts the number of players
fn main() {
App::build()
App::new()
.insert_resource(PlayerCount(0))
.add_startup_system(spawn.system())
.add_system(count_players.system())

View file

@ -48,7 +48,7 @@ pub enum PhysicsSystem {
/// Lastly a system with run criterion _done_ is used to exit the app.
/// ```
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<Done>()
// Note that the system sets added in this example set their run criteria explicitly.

View file

@ -1,7 +1,7 @@
use bevy::{log::info, prelude::*};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(Countdown::default())
.add_startup_system(setup_system.system())

View file

@ -13,7 +13,7 @@ enum GameState {
}
fn main() {
App::build()
App::new()
.insert_resource(Msaa { samples: 4 })
.init_resource::<Game>()
.add_plugins(DefaultPlugins)

View file

@ -8,7 +8,7 @@ use bevy::{
/// An implementation of the classic game "Breakout"
const TIME_STEP: f32 = 1.0 / 60.0;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(Scoreboard { score: 0 })
.insert_resource(ClearColor(Color::rgb(0.9, 0.9, 0.9)))

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build().add_system(hello_world_system.system()).run();
App::new().add_system(hello_world_system.system()).run();
}
fn hello_world_system() {

View file

@ -1,7 +1,7 @@
use bevy::{prelude::*, window::ReceivedCharacter};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_system(print_char_event_system.system())
.run();

View file

@ -5,7 +5,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.init_resource::<GamepadLobby>()
.add_system_to_stage(CoreStage::PreUpdate, connection_system.system())

View file

@ -4,7 +4,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_system(gamepad_events.system())
.run();

View file

@ -4,7 +4,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_system(keyboard_input_system.system())
.run();

View file

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

View file

@ -4,7 +4,7 @@ use bevy::{
};
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_system(keyboard_input_system.system())
.run();

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_system(mouse_click_system.system())
.run();

Some files were not shown because too many files have changed in this diff Show more