Skip to content

Commit 29a3d0e

Browse files
committed
Split TimePlugin out of CorePlugin
1 parent c2edeb4 commit 29a3d0e

File tree

14 files changed

+51
-38
lines changed

14 files changed

+51
-38
lines changed

crates/bevy_core/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.6.0", features = ["bevy_reflect"
1717
bevy_math = { path = "../bevy_math", version = "0.6.0" }
1818
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] }
1919
bevy_tasks = { path = "../bevy_tasks", version = "0.6.0" }
20-
bevy_time = { path = "../bevy_time", version = "0.6.0" }
2120
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }
2221

2322
# other

crates/bevy_core/src/lib.rs

+3-29
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,14 @@ pub mod prelude {
1717
}
1818

1919
use bevy_app::prelude::*;
20-
use bevy_ecs::{
21-
entity::Entity,
22-
schedule::{ExclusiveSystemDescriptorCoercion, SystemLabel},
23-
system::{IntoExclusiveSystem, ResMut},
24-
};
25-
use bevy_time::{FixedTimesteps, Time, Timer};
20+
use bevy_ecs::entity::Entity;
2621
use bevy_utils::HashSet;
2722
use std::ops::Range;
2823

2924
/// Adds core functionality to Apps.
3025
#[derive(Default)]
3126
pub struct CorePlugin;
3227

33-
/// A `SystemLabel` enum for ordering systems relative to core Bevy systems.
34-
#[derive(Debug, PartialEq, Eq, Clone, Hash, SystemLabel)]
35-
pub enum CoreSystem {
36-
/// Updates the elapsed time. Any system that interacts with [Time] component should run after
37-
/// this.
38-
Time,
39-
}
40-
4128
impl Plugin for CorePlugin {
4229
fn build(&self, app: &mut App) {
4330
// Setup the default bevy task pools
@@ -47,30 +34,17 @@ impl Plugin for CorePlugin {
4734
.unwrap_or_default()
4835
.create_default_pools(&mut app.world);
4936

50-
app.init_resource::<Time>()
51-
.init_resource::<FixedTimesteps>()
52-
.register_type::<HashSet<String>>()
37+
app.register_type::<HashSet<String>>()
5338
.register_type::<Option<String>>()
5439
.register_type::<Entity>()
5540
.register_type::<Name>()
56-
.register_type::<Range<f32>>()
57-
.register_type::<Timer>()
58-
// time system is added as an "exclusive system" to ensure it runs before other systems
59-
// in CoreStage::First
60-
.add_system_to_stage(
61-
CoreStage::First,
62-
time_system.exclusive_system().label(CoreSystem::Time),
63-
);
41+
.register_type::<Range<f32>>();
6442

6543
register_rust_types(app);
6644
register_math_types(app);
6745
}
6846
}
6947

70-
fn time_system(mut time: ResMut<Time>) {
71-
time.update();
72-
}
73-
7448
fn register_rust_types(app: &mut App) {
7549
app.register_type::<bool>()
7650
.register_type::<u8>()

crates/bevy_internal/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ bevy_transform = { path = "../bevy_transform", version = "0.6.0" }
6565
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }
6666
bevy_window = { path = "../bevy_window", version = "0.6.0" }
6767
bevy_tasks = { path = "../bevy_tasks", version = "0.6.0" }
68+
bevy_time = { path = "../bevy_time", version = "0.6.0" }
6869
# bevy (optional)
6970
bevy_audio = { path = "../bevy_audio", optional = true, version = "0.6.0" }
7071
bevy_core_pipeline = { path = "../bevy_core_pipeline", optional = true, version = "0.6.0" }

crates/bevy_internal/src/default_plugins.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl PluginGroup for DefaultPlugins {
2626
fn build(&mut self, group: &mut PluginGroupBuilder) {
2727
group.add(bevy_log::LogPlugin::default());
2828
group.add(bevy_core::CorePlugin::default());
29+
group.add(bevy_time::TimePlugin::default());
2930
group.add(bevy_transform::TransformPlugin::default());
3031
group.add(bevy_diagnostic::DiagnosticsPlugin::default());
3132
group.add(bevy_input::InputPlugin::default());
@@ -69,6 +70,7 @@ impl PluginGroup for DefaultPlugins {
6970

7071
/// Minimal plugin group that will add the following plugins:
7172
/// * [`CorePlugin`](bevy_core::CorePlugin)
73+
/// * [`TimePlugin`](bevy_time::TimePlugin)
7274
/// * [`ScheduleRunnerPlugin`](bevy_app::ScheduleRunnerPlugin)
7375
///
7476
/// See also [`DefaultPlugins`] for a more complete set of plugins
@@ -77,6 +79,7 @@ pub struct MinimalPlugins;
7779
impl PluginGroup for MinimalPlugins {
7880
fn build(&mut self, group: &mut PluginGroupBuilder) {
7981
group.add(bevy_core::CorePlugin::default());
82+
group.add(bevy_time::TimePlugin::default());
8083
group.add(bevy_app::ScheduleRunnerPlugin::default());
8184
}
8285
}

crates/bevy_internal/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod asset {
1818
}
1919

2020
pub mod core {
21-
//! Contains core plugins and utilities for time.
21+
//! Contains core plugins.
2222
pub use bevy_core::*;
2323
}
2424

@@ -65,6 +65,11 @@ pub mod tasks {
6565
pub use bevy_tasks::*;
6666
}
6767

68+
pub mod time {
69+
//! Contains time utilities.
70+
pub use bevy_time::*;
71+
}
72+
6873
pub mod transform {
6974
//! Local and global transforms (e.g. translation, scale, rotation).
7075
pub use bevy_transform::*;

crates/bevy_internal/src/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[doc(hidden)]
22
pub use crate::{
33
app::prelude::*, asset::prelude::*, core::prelude::*, ecs::prelude::*, input::prelude::*,
4-
log::prelude::*, math::prelude::*, reflect::prelude::*, scene::prelude::*,
4+
log::prelude::*, math::prelude::*, reflect::prelude::*, scene::prelude::*, time::prelude::*,
55
transform::prelude::*, utils::prelude::*, window::prelude::*, DefaultPlugins, MinimalPlugins,
66
};
77

crates/bevy_time/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ keywords = ["bevy"]
1111

1212
[dependencies]
1313
# bevy
14+
bevy_app = { path = "../bevy_app", version = "0.6.0", features = ["bevy_reflect"] }
1415
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0", features = ["bevy_reflect"] }
1516
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] }
1617
bevy_utils = { path = "../bevy_utils", version = "0.6.0" }

crates/bevy_time/src/lib.rs

+30
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,33 @@ pub mod prelude {
1414
#[doc(hidden)]
1515
pub use crate::{Time, Timer};
1616
}
17+
18+
use bevy_app::prelude::*;
19+
use bevy_ecs::prelude::*;
20+
21+
/// Adds time functionality to Apps.
22+
#[derive(Default)]
23+
pub struct TimePlugin;
24+
25+
#[derive(Debug, PartialEq, Eq, Clone, Hash, SystemLabel)]
26+
/// Updates the elapsed time. Any system that interacts with [Time] component should run after
27+
/// this.
28+
pub struct TimeSystem;
29+
30+
impl Plugin for TimePlugin {
31+
fn build(&self, app: &mut App) {
32+
app.init_resource::<Time>()
33+
.init_resource::<FixedTimesteps>()
34+
.register_type::<Timer>()
35+
// time system is added as an "exclusive system" to ensure it runs before other systems
36+
// in CoreStage::First
37+
.add_system_to_stage(
38+
CoreStage::First,
39+
time_system.exclusive_system().label(TimeSystem),
40+
);
41+
}
42+
}
43+
44+
fn time_system(mut time: ResMut<Time>) {
45+
time.update();
46+
}

examples/2d/rotation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::{
2-
core::FixedTimestep,
32
math::{const_vec2, Vec3Swizzles},
43
prelude::*,
4+
time::FixedTimestep,
55
};
66

77
const TIME_STEP: f32 = 1.0 / 60.0;

examples/ecs/fixed_timestep.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::{
2-
core::{FixedTimestep, FixedTimesteps},
32
prelude::*,
3+
time::{FixedTimestep, FixedTimesteps},
44
};
55

66
const LABEL: &str = "my_fixed_timestep";

examples/ecs/iter_combinations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy::{core::FixedTimestep, pbr::AmbientLight, prelude::*, render::camera::Camera};
1+
use bevy::{pbr::AmbientLight, prelude::*, render::camera::Camera, time::FixedTimestep};
22
use rand::{thread_rng, Rng};
33

44
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]

examples/game/alien_cake_addict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bevy::{
2-
core::FixedTimestep, ecs::schedule::SystemSet, prelude::*, render::camera::CameraPlugin,
2+
ecs::schedule::SystemSet, prelude::*, render::camera::CameraPlugin, time::FixedTimestep,
33
};
44
use rand::Rng;
55

examples/game/breakout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::{
2-
core::FixedTimestep,
32
prelude::*,
43
sprite::collide_aabb::{collide, Collision},
4+
time::FixedTimestep,
55
};
66

77
/// An implementation of the classic game "Breakout"

examples/tools/bevymark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::{
2-
core::FixedTimestep,
32
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
43
prelude::*,
4+
time::FixedTimestep,
55
window::PresentMode,
66
};
77
use rand::{thread_rng, Rng};

0 commit comments

Comments
 (0)