Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Hide fixed_update behind a feature flag #14911

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ keywords = ["bevy"]
[features]
trace = []
bevy_debug_stepping = []
default = ["bevy_reflect"]
default = ["bevy_reflect", "fixed_time"]
bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"]
reflect_functions = [
"bevy_reflect",
"bevy_reflect/functions",
"bevy_ecs/reflect_functions",
]
fixed_time = []

[dependencies]
# bevy
Expand Down
10 changes: 7 additions & 3 deletions crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ pub use terminal_ctrl_c_handler::*;

#[allow(missing_docs)]
pub mod prelude {
#[cfg(feature = "fixed_time")]
pub use crate::main_schedule::{
FixedFirst, FixedLast, FixedPostUpdate, FixedPreUpdate, FixedUpdate, RunFixedMainLoop,
RunFixedMainLoopSystem,
};
#[doc(hidden)]
pub use crate::{
app::{App, AppExit},
main_schedule::{
First, FixedFirst, FixedLast, FixedPostUpdate, FixedPreUpdate, FixedUpdate, Last, Main,
PostStartup, PostUpdate, PreStartup, PreUpdate, RunFixedMainLoop,
RunFixedMainLoopSystem, SpawnScene, Startup, Update,
First, Last, Main, PostStartup, PostUpdate, PreStartup, PreUpdate, SpawnScene, Startup,
Update,
},
sub_app::SubApp,
Plugin, PluginGroup,
Expand Down
60 changes: 37 additions & 23 deletions crates/bevy_app/src/main_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::{App, Plugin};
#[cfg(feature = "fixed_time")]
use bevy_ecs::schedule::IntoSystemSetConfigs;
use bevy_ecs::{
schedule::{
ExecutorKind, InternedScheduleLabel, IntoSystemSetConfigs, Schedule, ScheduleLabel,
SystemSet,
},
schedule::{ExecutorKind, InternedScheduleLabel, Schedule, ScheduleLabel, SystemSet},
system::{Local, Resource},
world::{Mut, World},
};

/// The schedule that contains the app logic that is evaluated each tick of [`App::update()`].
///
/// By default, it will run the following schedules in the given order:
Expand Down Expand Up @@ -85,20 +83,23 @@ pub struct PreUpdate;
/// [`RunFixedMainLoop`] will *not* be parallelized between each other.
///
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RunFixedMainLoop;

/// Runs first in the [`FixedMain`] schedule.
///
/// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedFirst;

/// The schedule that contains logic that must run before [`FixedUpdate`].
///
/// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedPreUpdate;

Expand All @@ -114,6 +115,7 @@ pub struct FixedPreUpdate;
/// See the [`Update`] schedule for examples of systems that *should not* use this schedule.
/// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedUpdate;

Expand All @@ -122,13 +124,15 @@ pub struct FixedUpdate;
///
/// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedPostUpdate;

/// The schedule that runs last in [`FixedMain`]
///
/// See the [`FixedMain`] schedule for details on how fixed updates work.
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedLast;

Expand All @@ -141,6 +145,7 @@ pub struct FixedLast;
/// See [this example](https://github.com/bevyengine/bevy/blob/latest/examples/time/time.rs).
///
/// See the [`Main`] schedule for some details about how schedules are run.
#[cfg(feature = "fixed_time")]
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct FixedMain;

Expand Down Expand Up @@ -196,6 +201,7 @@ impl Default for MainScheduleOrder {
labels: vec![
First.intern(),
PreUpdate.intern(),
#[cfg(feature = "fixed_time")]
RunFixedMainLoop.intern(),
Update.intern(),
SpawnScene.intern(),
Expand Down Expand Up @@ -285,28 +291,31 @@ impl Plugin for MainSchedulePlugin {
// simple "facilitator" schedules benefit from simpler single threaded scheduling
let mut main_schedule = Schedule::new(Main);
main_schedule.set_executor_kind(ExecutorKind::SingleThreaded);
let mut fixed_main_schedule = Schedule::new(FixedMain);
fixed_main_schedule.set_executor_kind(ExecutorKind::SingleThreaded);
let mut fixed_main_loop_schedule = Schedule::new(RunFixedMainLoop);
fixed_main_loop_schedule.set_executor_kind(ExecutorKind::SingleThreaded);

app.add_schedule(main_schedule)
.add_schedule(fixed_main_schedule)
.add_schedule(fixed_main_loop_schedule)
.init_resource::<MainScheduleOrder>()
.init_resource::<FixedMainScheduleOrder>()
.add_systems(Main, Main::run_main)
.add_systems(FixedMain, FixedMain::run_fixed_main)
.configure_sets(
RunFixedMainLoop,
(
RunFixedMainLoopSystem::BeforeFixedMainLoop,
RunFixedMainLoopSystem::FixedMainLoop,
RunFixedMainLoopSystem::AfterFixedMainLoop,
)
.chain(),
);
.add_systems(Main, Main::run_main);

#[cfg(feature = "fixed_time")]
{
let mut fixed_main_schedule = Schedule::new(FixedMain);
fixed_main_schedule.set_executor_kind(ExecutorKind::SingleThreaded);
let mut fixed_main_loop_schedule = Schedule::new(RunFixedMainLoop);
fixed_main_loop_schedule.set_executor_kind(ExecutorKind::SingleThreaded);
app.add_schedule(fixed_main_schedule)
.add_schedule(fixed_main_loop_schedule)
.init_resource::<FixedMainScheduleOrder>()
.add_systems(FixedMain, FixedMain::run_fixed_main)
.configure_sets(
RunFixedMainLoop,
(
RunFixedMainLoopSystem::BeforeFixedMainLoop,
RunFixedMainLoopSystem::FixedMainLoop,
RunFixedMainLoopSystem::AfterFixedMainLoop,
)
.chain(),
);
}
#[cfg(feature = "bevy_debug_stepping")]
{
use bevy_ecs::schedule::{IntoSystemConfigs, Stepping};
Expand All @@ -317,12 +326,14 @@ impl Plugin for MainSchedulePlugin {

/// Defines the schedules to be run for the [`FixedMain`] schedule, including
/// their order.
#[cfg(feature = "fixed_time")]
#[derive(Resource, Debug)]
pub struct FixedMainScheduleOrder {
/// The labels to run for the [`FixedMain`] schedule (in the order they will be run).
pub labels: Vec<InternedScheduleLabel>,
}

#[cfg(feature = "fixed_time")]
impl Default for FixedMainScheduleOrder {
fn default() -> Self {
Self {
Expand All @@ -337,6 +348,7 @@ impl Default for FixedMainScheduleOrder {
}
}

#[cfg(feature = "fixed_time")]
impl FixedMainScheduleOrder {
/// Adds the given `schedule` after the `after` schedule
pub fn insert_after(&mut self, after: impl ScheduleLabel, schedule: impl ScheduleLabel) {
Expand All @@ -359,6 +371,7 @@ impl FixedMainScheduleOrder {
}
}

#[cfg(feature = "fixed_time")]
impl FixedMain {
/// A system that runs the fixed timestep's "main schedule"
pub fn run_fixed_main(world: &mut World) {
Expand All @@ -381,6 +394,7 @@ impl FixedMain {
///
/// Note that in contrast to most other Bevy schedules, systems added directly to
/// [`RunFixedMainLoop`] will *not* be parallelized between each other.
#[cfg(feature = "fixed_time")]
#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone, SystemSet)]
pub enum RunFixedMainLoopSystem {
/// Runs before the fixed update logic.
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_gizmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = ["fixed_time"]
webgl = []
webgpu = []
fixed_time = ["bevy_app/fixed_time"]
alice-i-cecile marked this conversation as resolved.
Show resolved Hide resolved
bevy_render = ["dep:bevy_render", "bevy_core_pipeline"]

[dependencies]
Expand Down
78 changes: 50 additions & 28 deletions crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ pub mod prelude {
pub use crate::light::{LightGizmoColor, LightGizmoConfigGroup, ShowLightGizmo};
}

#[cfg(not(feature = "fixed_time"))]
use bevy_app::First;
use bevy_app::{App, Last, Plugin};
#[cfg(feature = "fixed_time")]
use bevy_app::{FixedFirst, FixedLast, RunFixedMainLoop};
use bevy_asset::{Asset, AssetApp, Assets, Handle};
use bevy_color::LinearRgba;
#[cfg(feature = "bevy_render")]
use bevy_ecs::component::Component;
#[cfg(feature = "bevy_render")]
use bevy_ecs::{
query::ROQueryItem,
Expand All @@ -77,12 +86,6 @@ use bevy_ecs::{
Commands, SystemParamItem,
},
};

use bevy_app::{App, FixedFirst, FixedLast, Last, Plugin, RunFixedMainLoop};
use bevy_asset::{Asset, AssetApp, Assets, Handle};
use bevy_color::LinearRgba;
#[cfg(feature = "bevy_render")]
use bevy_ecs::component::Component;
use bevy_ecs::{
schedule::{IntoSystemConfigs, SystemSet},
system::{Res, ResMut, Resource},
Expand Down Expand Up @@ -241,28 +244,47 @@ impl AppGizmoBuilder for App {
handles.list.insert(TypeId::of::<Config>(), None);
handles.strip.insert(TypeId::of::<Config>(), None);

self.init_resource::<GizmoStorage<Config, ()>>()
.init_resource::<GizmoStorage<Config, Fixed>>()
.init_resource::<GizmoStorage<Config, Swap<Fixed>>>()
.add_systems(
RunFixedMainLoop,
start_gizmo_context::<Config, Fixed>
.in_set(bevy_app::RunFixedMainLoopSystem::BeforeFixedMainLoop),
)
.add_systems(FixedFirst, clear_gizmo_context::<Config, Fixed>)
.add_systems(FixedLast, collect_requested_gizmos::<Config, Fixed>)
.add_systems(
RunFixedMainLoop,
end_gizmo_context::<Config, Fixed>
.in_set(bevy_app::RunFixedMainLoopSystem::AfterFixedMainLoop),
)
.add_systems(
Last,
(
propagate_gizmos::<Config, Fixed>.before(UpdateGizmoMeshes),
update_gizmo_meshes::<Config>.in_set(UpdateGizmoMeshes),
),
);
#[cfg(feature = "fixed_time")]
{
self.init_resource::<GizmoStorage<Config, ()>>()
Lubba-64 marked this conversation as resolved.
Show resolved Hide resolved
.init_resource::<GizmoStorage<Config, Fixed>>()
.init_resource::<GizmoStorage<Config, Swap<Fixed>>>()
.add_systems(
RunFixedMainLoop,
start_gizmo_context::<Config, Fixed>
.in_set(bevy_app::RunFixedMainLoopSystem::BeforeFixedMainLoop),
)
.add_systems(FixedFirst, clear_gizmo_context::<Config, Fixed>)
.add_systems(FixedLast, collect_requested_gizmos::<Config, Fixed>)
.add_systems(
RunFixedMainLoop,
end_gizmo_context::<Config, Fixed>
.in_set(bevy_app::RunFixedMainLoopSystem::AfterFixedMainLoop),
)
.add_systems(
Last,
(
propagate_gizmos::<Config, Fixed>.before(UpdateGizmoMeshes),
update_gizmo_meshes::<Config>.in_set(UpdateGizmoMeshes),
),
);
}
#[cfg(not(feature = "fixed_time"))]
{
self.init_resource::<GizmoStorage<Config, ()>>()
.init_resource::<GizmoStorage<Config, ()>>()
.init_resource::<GizmoStorage<Config, Fixed>>()
.init_resource::<GizmoStorage<Config, Swap<Fixed>>>()
.add_systems(First, clear_gizmo_context::<Config, Fixed>)
.add_systems(
Last,
(
collect_requested_gizmos::<Config, Fixed>,
propagate_gizmos::<Config, Fixed>.before(UpdateGizmoMeshes),
update_gizmo_meshes::<Config>.in_set(UpdateGizmoMeshes),
),
);
}

self
}
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = ["bevy_reflect"]
default = ["bevy_reflect", "fixed_time"]
serialize = ["serde"]
fixed_time = ["bevy_app/fixed_time"]

[dependencies]
# bevy
Expand Down
Loading