From 49e6b0fc9d34a97dfbe22a4807f8e47c38265ffa Mon Sep 17 00:00:00 2001 From: Wybe Westra Date: Tue, 17 Sep 2024 12:32:03 +0200 Subject: [PATCH 1/4] Added `HeadlessPlugins` (#15203) --- crates/bevy_internal/src/default_plugins.rs | 71 +++++++++++++++++++-- crates/bevy_internal/src/prelude.rs | 3 +- examples/app/headless.rs | 15 +++-- 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index 7aadcb50fbf6a..ce9f020354b60 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -71,7 +71,64 @@ plugin_group! { /// /// [`DefaultPlugins`] contains all the plugins typically required to build /// a *Bevy* application which includes a *window* and presentation components. - /// For *headless* cases – without a *window* or presentation, see [`MinimalPlugins`]. + /// For *headless* cases – without a *window* or presentation, see [`HeadlessPlugins`]. + /// For the absolute minimum number of plugins for running a *Bevy* application, see [`MinimalPlugins`]. +} + +plugin_group! { + /// This plugin group will add all the default plugins for a headless (no *window* or rendering) *Bevy* application: + pub struct HeadlessPlugins { + bevy_app:::PanicHandlerPlugin, + bevy_log:::LogPlugin, + bevy_core:::TaskPoolPlugin, + bevy_core:::TypeRegistrationPlugin, + bevy_core:::FrameCountPlugin, + bevy_time:::TimePlugin, + bevy_transform:::TransformPlugin, + bevy_hierarchy:::HierarchyPlugin, + bevy_diagnostic:::DiagnosticsPlugin, + bevy_input:::InputPlugin, + bevy_a11y:::AccessibilityPlugin, + bevy_app:::ScheduleRunnerPlugin, + #[custom(cfg(not(target_arch = "wasm32")))] + bevy_app:::TerminalCtrlCHandlerPlugin, + #[cfg(feature = "bevy_asset")] + bevy_asset:::AssetPlugin, + #[cfg(feature = "bevy_scene")] + bevy_scene:::ScenePlugin, + #[cfg(feature = "bevy_audio")] + bevy_audio:::AudioPlugin, + #[cfg(feature = "bevy_gilrs")] + bevy_gilrs:::GilrsPlugin, + #[cfg(feature = "bevy_animation")] + bevy_animation:::AnimationPlugin, + #[cfg(feature = "bevy_state")] + bevy_state::app:::StatesPlugin, + #[cfg(feature = "bevy_dev_tools")] + bevy_dev_tools:::DevToolsPlugin, + #[cfg(feature = "bevy_ci_testing")] + bevy_dev_tools::ci_testing:::CiTestingPlugin, + #[doc(hidden)] + :IgnoreAmbiguitiesPlugin, + } + /// This group of plugins is intended for use for *headless* programs, for example: dedicated game servers. + /// See the [*Bevy* *headless* example](https://github.com/bevyengine/bevy/blob/main/examples/app/headless.rs) + /// + /// [`HeadlessPlugins`] obeys *Cargo* *feature* flags. Users may exert control over this plugin group + /// by disabling `default-features` in their `Cargo.toml` and enabling only those features + /// that they wish to use. + /// + /// [`HeadlessPlugins`] contains all the plugins typically required to build + /// a *Bevy* application. In contrast with [`DefaultPlugins`], it leaves out *window* and presentation components. + /// This allows applications built using this plugin group to run on devices that do not have a screen or rendering + /// capabilities. + /// It includes a [schedule runner (`ScheduleRunnerPlugin`)](crate::app::ScheduleRunnerPlugin) + /// to provide functionality that would otherwise be driven by a windowed application's + /// *event loop* or *message loop*. + /// + /// Windowed applications that wish to use a reduced set of plugins should consider the + /// [`DefaultPlugins`] plugin group which can be controlled with *Cargo* *feature* flags. + /// For the absolute minimum number of plugins for running a *Bevy* application, see [`MinimalPlugins`]. } #[derive(Default)] @@ -110,12 +167,12 @@ plugin_group! { #[cfg(feature = "bevy_ci_testing")] bevy_dev_tools::ci_testing:::CiTestingPlugin, } - /// This group of plugins is intended for use for minimal, *headless* programs – - /// see the [*Bevy* *headless* example](https://github.com/bevyengine/bevy/blob/main/examples/app/headless.rs) - /// – and includes a [schedule runner (`ScheduleRunnerPlugin`)](crate::app::ScheduleRunnerPlugin) + /// This plugin group represents the absolute minimum, bare-bones, bevy application. + /// Use this if you want to have absolute control over the plugins used. + /// If you are looking to make a *headless* application - without a *window* or rendering, + /// it is usually best to use [`HeadlessPlugins`]. + /// + /// It includes a [schedule runner (`ScheduleRunnerPlugin`)](crate::app::ScheduleRunnerPlugin) /// to provide functionality that would otherwise be driven by a windowed application's /// *event loop* or *message loop*. - /// - /// Windowed applications that wish to use a reduced set of plugins should consider the - /// [`DefaultPlugins`] plugin group which can be controlled with *Cargo* *feature* flags. } diff --git a/crates/bevy_internal/src/prelude.rs b/crates/bevy_internal/src/prelude.rs index 812a674ed93ee..bec80694fd490 100644 --- a/crates/bevy_internal/src/prelude.rs +++ b/crates/bevy_internal/src/prelude.rs @@ -2,7 +2,8 @@ pub use crate::{ app::prelude::*, core::prelude::*, ecs::prelude::*, hierarchy::prelude::*, input::prelude::*, log::prelude::*, math::prelude::*, reflect::prelude::*, time::prelude::*, - transform::prelude::*, utils::prelude::*, window::prelude::*, DefaultPlugins, MinimalPlugins, + transform::prelude::*, utils::prelude::*, window::prelude::*, DefaultPlugins, HeadlessPlugins, + MinimalPlugins, }; pub use bevy_derive::{bevy_main, Deref, DerefMut}; diff --git a/examples/app/headless.rs b/examples/app/headless.rs index 329a28bf6ea4b..c6ee157b37fd2 100644 --- a/examples/app/headless.rs +++ b/examples/app/headless.rs @@ -8,21 +8,26 @@ //! # replace "*" with the most recent version of bevy //! ``` -use bevy::{app::ScheduleRunnerPlugin, prelude::*, utils::Duration}; +use bevy::{app::ScheduleRunnerPlugin, log::LogPlugin, prelude::*, utils::Duration}; fn main() { // This app runs once App::new() - .add_plugins(MinimalPlugins.set(ScheduleRunnerPlugin::run_once())) + .add_plugins(HeadlessPlugins.set(ScheduleRunnerPlugin::run_once())) .add_systems(Update, hello_world_system) .run(); // This app loops forever at 60 fps App::new() .add_plugins( - MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64( - 1.0 / 60.0, - ))), + HeadlessPlugins + .set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64( + 1.0 / 60.0, + ))) + // The log and ctrl+c plugin can only be registered once globally, + // which means we need to disable it here, because it was already registered with the + // app that runs once. + .disable::(), ) .add_systems(Update, counter) .run(); From 153816faacb48078c0c6fb7f63c341cd979315fd Mon Sep 17 00:00:00 2001 From: Wybe Westra Date: Tue, 17 Sep 2024 18:28:10 +0200 Subject: [PATCH 2/4] Removed input, audio and dev tools plugins from HeadlessPlugins. --- crates/bevy_dev_tools/src/ci_testing/mod.rs | 5 +++-- crates/bevy_internal/src/default_plugins.rs | 7 ------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/bevy_dev_tools/src/ci_testing/mod.rs b/crates/bevy_dev_tools/src/ci_testing/mod.rs index d6d5c6d4bed63..14b5a1fd5a9b6 100644 --- a/crates/bevy_dev_tools/src/ci_testing/mod.rs +++ b/crates/bevy_dev_tools/src/ci_testing/mod.rs @@ -17,8 +17,9 @@ use std::time::Duration; /// (`ci_testing_config.ron` by default) and executes its specified actions. For a reference of the /// allowed configuration, see [`CiTestingConfig`]. /// -/// This plugin is included within `DefaultPlugins` and `MinimalPlugins` when the `bevy_ci_testing` -/// feature is enabled. It is recommended to only used this plugin during testing (manual or +/// This plugin is included within `DefaultPlugins`, `HeadlessPlugins` and `MinimalPlugins` +/// when the `bevy_ci_testing`feature is enabled. +/// It is recommended to only used this plugin during testing (manual or /// automatic), and disable it during regular development and for production builds. #[derive(Default)] pub struct CiTestingPlugin; diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index ce9f020354b60..b3b8703806c23 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -87,7 +87,6 @@ plugin_group! { bevy_transform:::TransformPlugin, bevy_hierarchy:::HierarchyPlugin, bevy_diagnostic:::DiagnosticsPlugin, - bevy_input:::InputPlugin, bevy_a11y:::AccessibilityPlugin, bevy_app:::ScheduleRunnerPlugin, #[custom(cfg(not(target_arch = "wasm32")))] @@ -96,16 +95,10 @@ plugin_group! { bevy_asset:::AssetPlugin, #[cfg(feature = "bevy_scene")] bevy_scene:::ScenePlugin, - #[cfg(feature = "bevy_audio")] - bevy_audio:::AudioPlugin, - #[cfg(feature = "bevy_gilrs")] - bevy_gilrs:::GilrsPlugin, #[cfg(feature = "bevy_animation")] bevy_animation:::AnimationPlugin, #[cfg(feature = "bevy_state")] bevy_state::app:::StatesPlugin, - #[cfg(feature = "bevy_dev_tools")] - bevy_dev_tools:::DevToolsPlugin, #[cfg(feature = "bevy_ci_testing")] bevy_dev_tools::ci_testing:::CiTestingPlugin, #[doc(hidden)] From 03ba859c441e8181c13b58f585887586ab5485ae Mon Sep 17 00:00:00 2001 From: Wybe Westra Date: Tue, 17 Sep 2024 18:46:09 +0200 Subject: [PATCH 3/4] Change comment wording --- crates/bevy_internal/src/default_plugins.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index b3b8703806c23..db4f0c696822d 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -72,7 +72,7 @@ plugin_group! { /// [`DefaultPlugins`] contains all the plugins typically required to build /// a *Bevy* application which includes a *window* and presentation components. /// For *headless* cases – without a *window* or presentation, see [`HeadlessPlugins`]. - /// For the absolute minimum number of plugins for running a *Bevy* application, see [`MinimalPlugins`]. + /// For the absolute minimum number of plugins needed to run a Bevy application, see [`MinimalPlugins`]. } plugin_group! { @@ -121,7 +121,7 @@ plugin_group! { /// /// Windowed applications that wish to use a reduced set of plugins should consider the /// [`DefaultPlugins`] plugin group which can be controlled with *Cargo* *feature* flags. - /// For the absolute minimum number of plugins for running a *Bevy* application, see [`MinimalPlugins`]. + /// For the absolute minimum number of plugins needed to run a Bevy application, see [`MinimalPlugins`]. } #[derive(Default)] From bd6203bade3758dd83f6fb86929bdf9daa747146 Mon Sep 17 00:00:00 2001 From: Wybe Westra Date: Thu, 19 Sep 2024 18:12:00 +0200 Subject: [PATCH 4/4] Removed accesibility plugin from headless plugin group --- crates/bevy_dev_tools/src/ci_testing/mod.rs | 2 +- crates/bevy_internal/src/default_plugins.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/bevy_dev_tools/src/ci_testing/mod.rs b/crates/bevy_dev_tools/src/ci_testing/mod.rs index 14b5a1fd5a9b6..39b9bee6da7e6 100644 --- a/crates/bevy_dev_tools/src/ci_testing/mod.rs +++ b/crates/bevy_dev_tools/src/ci_testing/mod.rs @@ -18,7 +18,7 @@ use std::time::Duration; /// allowed configuration, see [`CiTestingConfig`]. /// /// This plugin is included within `DefaultPlugins`, `HeadlessPlugins` and `MinimalPlugins` -/// when the `bevy_ci_testing`feature is enabled. +/// when the `bevy_ci_testing` feature is enabled. /// It is recommended to only used this plugin during testing (manual or /// automatic), and disable it during regular development and for production builds. #[derive(Default)] diff --git a/crates/bevy_internal/src/default_plugins.rs b/crates/bevy_internal/src/default_plugins.rs index db4f0c696822d..74008dafafcc8 100644 --- a/crates/bevy_internal/src/default_plugins.rs +++ b/crates/bevy_internal/src/default_plugins.rs @@ -87,7 +87,6 @@ plugin_group! { bevy_transform:::TransformPlugin, bevy_hierarchy:::HierarchyPlugin, bevy_diagnostic:::DiagnosticsPlugin, - bevy_a11y:::AccessibilityPlugin, bevy_app:::ScheduleRunnerPlugin, #[custom(cfg(not(target_arch = "wasm32")))] bevy_app:::TerminalCtrlCHandlerPlugin,