From 633c226bdd1458dfdce54098bcd7d2fda1b1f22e Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Thu, 26 May 2022 00:27:18 +0000 Subject: [PATCH] Split time functionality into bevy_time (#4187) # Objective Reduce the catch-all grab-bag of functionality in bevy_core by minimally splitting off time functionality into bevy_time. Functionality like that provided by #3002 would increase the complexity of bevy_time, so this is a good candidate for pulling into its own unit. A step in addressing #2931 and splitting bevy_core into more specific locations. ## Solution Pull the time module of bevy_core into a new crate, bevy_time. # Migration guide - Time related types (e.g. `Time`, `Timer`, `Stopwatch`, `FixedTimestep`, etc.) should be imported from `bevy::time::*` rather than `bevy::core::*`. - If you were adding `CorePlugin` manually, you'll also want to add `TimePlugin` from `bevy::time`. - The `bevy::core::CorePlugin::Time` system label is replaced with `bevy::time::TimeSystem`. Co-authored-by: Carter Anderson --- crates/bevy_animation/Cargo.toml | 1 + crates/bevy_animation/src/lib.rs | 3 +- crates/bevy_core/src/lib.rs | 31 ++----------- crates/bevy_core/src/time/mod.rs | 10 ---- crates/bevy_diagnostic/Cargo.toml | 2 +- .../src/frame_time_diagnostics_plugin.rs | 2 +- .../src/log_diagnostics_plugin.rs | 2 +- crates/bevy_internal/Cargo.toml | 1 + crates/bevy_internal/src/default_plugins.rs | 4 ++ crates/bevy_internal/src/lib.rs | 7 ++- crates/bevy_internal/src/prelude.rs | 3 +- crates/bevy_time/Cargo.toml | 17 +++++++ .../time => bevy_time/src}/fixed_timestep.rs | 0 crates/bevy_time/src/lib.rs | 46 +++++++++++++++++++ .../src/time => bevy_time/src}/stopwatch.rs | 20 ++++---- .../src/time => bevy_time/src}/time.rs | 11 ++--- .../src/time => bevy_time/src}/timer.rs | 34 +++++++------- examples/2d/rotation.rs | 2 +- examples/ecs/fixed_timestep.rs | 2 +- examples/ecs/iter_combinations.rs | 2 +- examples/games/alien_cake_addict.rs | 2 +- examples/games/breakout.rs | 2 +- examples/stress_tests/bevymark.rs | 2 +- tools/publish.sh | 1 + 24 files changed, 123 insertions(+), 84 deletions(-) delete mode 100644 crates/bevy_core/src/time/mod.rs create mode 100644 crates/bevy_time/Cargo.toml rename crates/{bevy_core/src/time => bevy_time/src}/fixed_timestep.rs (100%) create mode 100644 crates/bevy_time/src/lib.rs rename crates/{bevy_core/src/time => bevy_time/src}/stopwatch.rs (94%) rename crates/{bevy_core/src/time => bevy_time/src}/time.rs (96%) rename crates/{bevy_core/src/time => bevy_time/src}/timer.rs (97%) diff --git a/crates/bevy_animation/Cargo.toml b/crates/bevy_animation/Cargo.toml index fdb9bd164ce6b6..2ef00a7c53c6c4 100644 --- a/crates/bevy_animation/Cargo.toml +++ b/crates/bevy_animation/Cargo.toml @@ -15,6 +15,7 @@ bevy_asset = { path = "../bevy_asset", version = "0.8.0-dev" } bevy_core = { path = "../bevy_core", version = "0.8.0-dev" } bevy_math = { path = "../bevy_math", version = "0.8.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] } +bevy_time = { path = "../bevy_time", version = "0.8.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.8.0-dev" } bevy_transform = { path = "../bevy_transform", version = "0.8.0-dev" } diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index c894207dcd71e2..b65debcaf3c57a 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -6,7 +6,7 @@ use std::ops::Deref; use bevy_app::{App, CoreStage, Plugin}; use bevy_asset::{AddAsset, Assets, Handle}; -use bevy_core::{Name, Time}; +use bevy_core::Name; use bevy_ecs::{ change_detection::DetectChanges, entity::Entity, @@ -18,6 +18,7 @@ use bevy_ecs::{ use bevy_hierarchy::{Children, HierarchySystem}; use bevy_math::{Quat, Vec3}; use bevy_reflect::{Reflect, TypeUuid}; +use bevy_time::Time; use bevy_transform::{prelude::Transform, TransformSystem}; use bevy_utils::{tracing::warn, HashMap}; diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 44b2be465b9cf3..b06302296e1ad5 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -3,25 +3,19 @@ mod name; mod task_pool_options; -mod time; pub use bytemuck::{bytes_of, cast_slice, Pod, Zeroable}; pub use name::*; pub use task_pool_options::*; -pub use time::*; pub mod prelude { //! The Bevy Core Prelude. #[doc(hidden)] - pub use crate::{DefaultTaskPoolOptions, Name, Time, Timer}; + pub use crate::{DefaultTaskPoolOptions, Name}; } use bevy_app::prelude::*; -use bevy_ecs::{ - entity::Entity, - schedule::{ExclusiveSystemDescriptorCoercion, SystemLabel}, - system::IntoExclusiveSystem, -}; +use bevy_ecs::entity::Entity; use bevy_utils::HashSet; use std::ops::Range; @@ -29,14 +23,6 @@ use std::ops::Range; #[derive(Default)] pub struct CorePlugin; -/// A `SystemLabel` enum for ordering systems relative to core Bevy systems. -#[derive(Debug, PartialEq, Eq, Clone, Hash, SystemLabel)] -pub enum CoreSystem { - /// Updates the elapsed time. Any system that interacts with [Time] component should run after - /// this. - Time, -} - impl Plugin for CorePlugin { fn build(&self, app: &mut App) { // Setup the default bevy task pools @@ -46,20 +32,11 @@ impl Plugin for CorePlugin { .unwrap_or_default() .create_default_pools(&mut app.world); - app.init_resource::