Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ To draw a window with standard functionality enabled, use:
use bevy::prelude::*;

fn main() {
App::new()
App::default()
.add_plugins(DefaultPlugins)
.run();
}
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/bevy_ecs/scheduling/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn build_schedule(criterion: &mut Criterion) {
// Basic benchmark without constraints.
group.bench_function(format!("{graph_size}_schedule_no_constraints"), |bencher| {
bencher.iter(|| {
let mut app = App::new();
let mut app = App::default();
for _ in 0..graph_size {
app.add_systems(Update, empty_system);
}
Expand All @@ -92,7 +92,7 @@ pub fn build_schedule(criterion: &mut Criterion) {
// Benchmark with constraints.
group.bench_function(format!("{graph_size}_schedule"), |bencher| {
bencher.iter(|| {
let mut app = App::new();
let mut app = App::default();
app.add_systems(Update, empty_system.in_set(DummySet));

// Build a fully-connected dependency graph describing the One True Ordering.
Expand Down
80 changes: 40 additions & 40 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(crate) enum AppError {
/// # use bevy_ecs::prelude::*;
/// #
/// fn main() {
/// App::new()
/// App::default()
/// .add_systems(Update, hello_world_system)
/// .run();
/// }
Expand Down Expand Up @@ -142,7 +142,7 @@ impl App {
pub fn empty() -> App {
Self {
sub_apps: SubApps {
main: SubApp::new(),
main: SubApp::default(),
sub_apps: HashMap::default(),
},
runner: Box::new(run_once),
Expand Down Expand Up @@ -214,7 +214,7 @@ impl App {
/// }
/// }
///
/// App::new()
/// App::default()
/// .set_runner(my_runner);
/// ```
pub fn set_runner(&mut self, f: impl FnOnce(App) -> AppExit + 'static) -> &mut Self {
Expand Down Expand Up @@ -293,7 +293,7 @@ impl App {
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// #
/// # let mut app = App::new();
/// # let mut app = App::default();
/// # fn system_a() {}
/// # fn system_b() {}
/// # fn system_c() {}
Expand Down Expand Up @@ -355,7 +355,7 @@ impl App {
/// #
/// # #[derive(BufferedEvent)]
/// # struct MyEvent;
/// # let mut app = App::new();
/// # let mut app = App::default();
/// #
/// app.add_event::<MyEvent>();
/// ```
Expand Down Expand Up @@ -383,7 +383,7 @@ impl App {
/// counter: usize,
/// }
///
/// App::new()
/// App::default()
/// .insert_resource(MyCounter { counter: 0 });
/// ```
pub fn insert_resource<R: Resource>(&mut self, resource: R) -> &mut Self {
Expand Down Expand Up @@ -417,7 +417,7 @@ impl App {
/// }
/// }
///
/// App::new()
/// App::default()
/// .init_resource::<MyCounter>();
/// ```
pub fn init_resource<R: Resource + FromWorld>(&mut self) -> &mut Self {
Expand All @@ -441,7 +441,7 @@ impl App {
/// counter: usize,
/// }
///
/// App::new()
/// App::default()
/// .insert_non_send_resource(MyCounter { counter: 0 });
/// ```
pub fn insert_non_send_resource<R: 'static>(&mut self, resource: R) -> &mut Self {
Expand Down Expand Up @@ -524,7 +524,7 @@ impl App {
/// # impl Plugin for ImagePlugin {
/// # fn build(&self, app: &mut App) {}
/// # }
/// # let mut app = App::new();
/// # let mut app = App::default();
/// # app.add_plugins(ImagePlugin::default());
/// let default_sampler = app.get_added_plugins::<ImagePlugin>()[0].default_sampler;
/// ```
Expand Down Expand Up @@ -562,9 +562,9 @@ impl App {
/// # impl Plugin for LogPlugin {
/// # fn build(&self, app: &mut App) {}
/// # }
/// App::new()
/// App::default()
/// .add_plugins(MinimalPlugins);
/// App::new()
/// App::default()
/// .add_plugins((MinimalPlugins, LogPlugin));
/// ```
///
Expand Down Expand Up @@ -615,7 +615,7 @@ impl App {
/// use bevy_app::App;
/// use bevy_reflect::{ReflectSerialize, ReflectDeserialize};
///
/// App::new()
/// App::default()
/// .register_type::<Option<String>>()
/// .register_type_data::<Option<String>, ReflectSerialize>()
/// .register_type_data::<Option<String>, ReflectDeserialize>();
Expand Down Expand Up @@ -662,7 +662,7 @@ impl App {
/// a + b
/// }
///
/// App::new().register_function(add);
/// App::default().register_function(add);
/// ```
///
/// Functions cannot be registered more than once.
Expand All @@ -674,7 +674,7 @@ impl App {
/// a + b
/// }
///
/// App::new()
/// App::default()
/// .register_function(add)
/// // Panic! A function has already been registered with the name "my_function"
/// .register_function(add);
Expand All @@ -686,7 +686,7 @@ impl App {
/// use bevy_app::App;
///
/// // Panic! Anonymous functions cannot be registered using `register_function`
/// App::new().register_function(|a: i32, b: i32| a + b);
/// App::default().register_function(|a: i32, b: i32| a + b);
/// ```
///
/// [`register_function_with_name`]: Self::register_function_with_name
Expand Down Expand Up @@ -738,7 +738,7 @@ impl App {
///
/// let div = |a: i32, b: i32| a / b;
///
/// App::new()
/// App::default()
/// // Registering an anonymous function with a unique name
/// .register_function_with_name("my_crate::add", |a: i32, b: i32| {
/// a + b
Expand All @@ -760,7 +760,7 @@ impl App {
/// fn one() {}
/// fn two() {}
///
/// App::new()
/// App::default()
/// .register_function_with_name("my_function", one)
/// // Panic! A function has already been registered with the name "my_function"
/// .register_function_with_name("my_function", two);
Expand Down Expand Up @@ -818,7 +818,7 @@ impl App {
/// #[derive(Component, Default, PartialEq, Eq, Debug)]
/// struct C(u32);
///
/// # let mut app = App::new();
/// # let mut app = App::default();
/// # app.add_plugins(MinimalPlugins).add_systems(Startup, setup);
/// // Register B as required by A and C as required by B.
/// app.register_required_components::<A, B>();
Expand Down Expand Up @@ -878,7 +878,7 @@ impl App {
/// #[derive(Component, Default, PartialEq, Eq, Debug)]
/// struct C(u32);
///
/// # let mut app = App::new();
/// # let mut app = App::default();
/// # app.add_plugins(MinimalPlugins).add_systems(Startup, setup);
/// // Register B and C as required by A and C as required by B.
/// // A requiring C directly will overwrite the indirect requirement through B.
Expand Down Expand Up @@ -943,7 +943,7 @@ impl App {
/// #[derive(Component, Default, PartialEq, Eq, Debug)]
/// struct C(u32);
///
/// # let mut app = App::new();
/// # let mut app = App::default();
/// # app.add_plugins(MinimalPlugins).add_systems(Startup, setup);
/// // Register B as required by A and C as required by B.
/// app.register_required_components::<A, B>();
Expand Down Expand Up @@ -1005,7 +1005,7 @@ impl App {
/// #[derive(Component, Default, PartialEq, Eq, Debug)]
/// struct C(u32);
///
/// # let mut app = App::new();
/// # let mut app = App::default();
/// # app.add_plugins(MinimalPlugins).add_systems(Startup, setup);
/// // Register B and C as required by A and C as required by B.
/// // A requiring C directly will overwrite the indirect requirement through B.
Expand Down Expand Up @@ -1205,7 +1205,7 @@ impl App {
/// fn system_1(_: Query<&mut A>) {}
/// fn system_2(_: Query<&A>) {}
///
/// let mut app = App::new();
/// let mut app = App::default();
/// app.configure_schedules(ScheduleBuildSettings {
/// ambiguity_detection: LogLevel::Error,
/// ..default()
Expand Down Expand Up @@ -1243,7 +1243,7 @@ impl App {
/// fn system_1(_: ResMut<R>) {}
/// fn system_2(_: Res<R>) {}
///
/// let mut app = App::new();
/// let mut app = App::default();
/// app.configure_schedules(ScheduleBuildSettings {
/// ambiguity_detection: LogLevel::Error,
/// ..default()
Expand Down Expand Up @@ -1316,7 +1316,7 @@ impl App {
/// # use bevy_ecs::prelude::*;
/// # use bevy_utils::default;
/// #
/// # let mut app = App::new();
/// # let mut app = App::default();
/// #
/// # #[derive(Event)]
/// # struct Party {
Expand Down Expand Up @@ -1368,7 +1368,7 @@ impl App {
/// # use bevy_app::*;
/// # use bevy_ecs::error::warn;
/// # fn MyPlugins(_: &mut App) {}
/// App::new()
/// App::default()
/// .set_error_handler(warn)
/// .add_plugins(MyPlugins)
/// .run();
Expand Down Expand Up @@ -1528,23 +1528,23 @@ mod tests {

#[test]
fn can_add_two_plugins() {
App::new().add_plugins((PluginA, PluginB));
App::default().add_plugins((PluginA, PluginB));
}

#[test]
#[should_panic]
fn cant_add_twice_the_same_plugin() {
App::new().add_plugins((PluginA, PluginA));
App::default().add_plugins((PluginA, PluginA));
}

#[test]
fn can_add_twice_the_same_plugin_with_different_type_param() {
App::new().add_plugins((PluginC(0), PluginC(true)));
App::default().add_plugins((PluginC(0), PluginC(true)));
}

#[test]
fn can_add_twice_the_same_plugin_not_unique() {
App::new().add_plugins((PluginD, PluginD));
App::default().add_plugins((PluginD, PluginD));
}

#[test]
Expand All @@ -1560,7 +1560,7 @@ mod tests {
app.add_plugins(InnerPlugin).run();
}
}
App::new().add_plugins(PluginRun);
App::default().add_plugins(PluginRun);
}

#[derive(ScheduleLabel, Hash, Clone, PartialEq, Eq, Debug)]
Expand All @@ -1579,7 +1579,7 @@ mod tests {

#[test]
fn add_systems_should_create_schedule_if_it_does_not_exist() {
let mut app = App::new();
let mut app = App::default();
app.add_systems(EnterMainMenu, (foo, bar));

app.world_mut().run_schedule(EnterMainMenu);
Expand All @@ -1589,7 +1589,7 @@ mod tests {
#[test]
#[should_panic]
fn test_is_plugin_added_works_during_finish() {
let mut app = App::new();
let mut app = App::default();
app.add_plugins(PluginA);
app.add_plugins(PluginE);
app.finish();
Expand Down Expand Up @@ -1702,7 +1702,7 @@ mod tests {
#[derive(Component, Copy, Clone)]
struct Foo;

let mut app = App::new();
let mut app = App::default();
app.world_mut().spawn_batch(core::iter::repeat_n(Foo, 5));

fn despawn_one_foo(mut commands: Commands, foos: Query<Entity, With<Foo>>) {
Expand Down Expand Up @@ -1736,13 +1736,13 @@ mod tests {
#[derive(Resource)]
struct Foo(usize);

let mut app = App::new();
let mut app = App::default();
app.world_mut().insert_resource(Foo(0));
app.add_systems(Update, |mut foo: ResMut<Foo>| {
foo.0 += 1;
});

let mut sub_app = SubApp::new();
let mut sub_app = SubApp::default();
sub_app.set_extract(|main_world, _sub_world| {
assert!(main_world.get_resource_ref::<Foo>().unwrap().is_changed());
});
Expand All @@ -1762,7 +1762,7 @@ mod tests {
exits.write(AppExit::from_code(73));
}

let exit = App::new().add_systems(Update, raise_exits).run();
let exit = App::default().add_systems(Update, raise_exits).run();

assert_eq!(exit, AppExit::from_code(4));
}
Expand Down Expand Up @@ -1795,7 +1795,7 @@ mod tests {
}

// Should not panic due to missing resource
App::new()
App::default()
.set_runner(my_runner)
.add_systems(PreUpdate, my_system)
.run();
Expand Down Expand Up @@ -1830,7 +1830,7 @@ mod tests {
}
}

App::new()
App::default()
.init_non_send_resource::<NonSendTestResource>()
.init_resource::<TestResource>();
}
Expand All @@ -1848,14 +1848,14 @@ mod tests {
}
}

App::new().add_plugins(Foo);
App::default().add_plugins(Foo);
}
#[test]
fn events_should_be_updated_once_per_update() {
#[derive(BufferedEvent, Clone)]
struct TestEvent;

let mut app = App::new();
let mut app = App::default();
app.add_event::<TestEvent>();

// Starts empty
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_app/src/main_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub enum RunFixedMainLoopSystems {
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// App::new()
/// App::default()
/// .add_systems(
/// RunFixedMainLoop,
/// update_camera_rotation.in_set(RunFixedMainLoopSystems::BeforeFixedMainLoop))
Expand All @@ -444,7 +444,7 @@ pub enum RunFixedMainLoopSystems {
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// App::new()
/// App::default()
/// .add_systems(FixedUpdate, update_physics)
/// .add_systems(
/// RunFixedMainLoop,
Expand Down Expand Up @@ -473,7 +473,7 @@ pub enum RunFixedMainLoopSystems {
/// ```
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// App::new()
/// App::default()
/// .add_systems(FixedUpdate, update_physics)
/// .add_systems(
/// RunFixedMainLoop,
Expand Down
Loading
Loading