Skip to content

Commit 2dfe38f

Browse files
committed
Split TimePlugin out of CorePlugin
1 parent db38ebc commit 2dfe38f

File tree

10 files changed

+44
-35
lines changed

10 files changed

+44
-35
lines changed

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/src/default_plugins.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use bevy_app::{PluginGroup, PluginGroupBuilder};
33
/// This plugin group will add all the default plugins:
44
/// * [`LogPlugin`](bevy_log::LogPlugin)
55
/// * [`CorePlugin`](bevy_core::CorePlugin)
6+
/// * [`TimePlugin`](bevy_time::TimePlugin)
67
/// * [`TransformPlugin`](bevy_transform::TransformPlugin)
78
/// * [`HierarchyPlugin`](bevy_hierarchy::HierarchyPlugin)
89
/// * [`DiagnosticsPlugin`](bevy_diagnostic::DiagnosticsPlugin)
@@ -27,6 +28,7 @@ impl PluginGroup for DefaultPlugins {
2728
fn build(&mut self, group: &mut PluginGroupBuilder) {
2829
group.add(bevy_log::LogPlugin::default());
2930
group.add(bevy_core::CorePlugin::default());
31+
group.add(bevy_time::TimePlugin::default());
3032
group.add(bevy_transform::TransformPlugin::default());
3133
group.add(bevy_hierarchy::HierarchyPlugin::default());
3234
group.add(bevy_diagnostic::DiagnosticsPlugin::default());
@@ -76,6 +78,7 @@ impl PluginGroup for DefaultPlugins {
7678

7779
/// Minimal plugin group that will add the following plugins:
7880
/// * [`CorePlugin`](bevy_core::CorePlugin)
81+
/// * [`TimePlugin`](bevy_time::TimePlugin)
7982
/// * [`ScheduleRunnerPlugin`](bevy_app::ScheduleRunnerPlugin)
8083
///
8184
/// See also [`DefaultPlugins`] for a more complete set of plugins
@@ -84,6 +87,7 @@ pub struct MinimalPlugins;
8487
impl PluginGroup for MinimalPlugins {
8588
fn build(&mut self, group: &mut PluginGroupBuilder) {
8689
group.add(bevy_core::CorePlugin::default());
90+
group.add(bevy_time::TimePlugin::default());
8791
group.add(bevy_app::ScheduleRunnerPlugin::default());
8892
}
8993
}

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.8.0-dev" }
1415
bevy_ecs = { path = "../bevy_ecs", version = "0.8.0-dev", features = ["bevy_reflect"] }
1516
bevy_reflect = { path = "../bevy_reflect", version = "0.8.0-dev", features = ["bevy"] }
1617
bevy_utils = { path = "../bevy_utils", version = "0.8.0-dev" }

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().at_start().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-
time::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-
time::{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::{time::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/games/alien_cake_addict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy::{time::FixedTimestep, ecs::schedule::SystemSet, prelude::*, render::camera::Camera3d};
1+
use bevy::{ecs::schedule::SystemSet, prelude::*, render::camera::Camera3d, time::FixedTimestep};
22
use rand::Rng;
33

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

examples/games/breakout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! A simplified implementation of the classic game "Breakout"
22
33
use bevy::{
4-
time::FixedTimestep,
54
math::{const_vec2, const_vec3},
65
prelude::*,
76
sprite::collide_aabb::{collide, Collision},
7+
time::FixedTimestep,
88
};
99

1010
// Defines the amount of time that should elapse between each physics step.

examples/stress_tests/bevymark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::{
2-
time::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)