Make bevy_time optionally depend on bevy_reflect (#13263)
# Objective Fixes #13246.
This commit is contained in:
parent
173db7726f
commit
de7ff295e1
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
|||||||
keywords = ["bevy"]
|
keywords = ["bevy"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["bevy_reflect"]
|
||||||
serialize = ["serde"]
|
serialize = ["serde"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -20,7 +20,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev", features = [
|
|||||||
] }
|
] }
|
||||||
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
||||||
"bevy",
|
"bevy",
|
||||||
] }
|
], optional = true }
|
||||||
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
|
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
|
||||||
|
|
||||||
# other
|
# other
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use bevy_app::FixedMain;
|
use bevy_app::FixedMain;
|
||||||
use bevy_ecs::world::World;
|
use bevy_ecs::world::World;
|
||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::Reflect;
|
||||||
use bevy_utils::Duration;
|
use bevy_utils::Duration;
|
||||||
|
|
||||||
@ -63,7 +64,8 @@ use crate::{time::Time, virt::Virtual};
|
|||||||
/// [`FixedUpdate`](bevy_app::FixedUpdate), even if it is still during the same
|
/// [`FixedUpdate`](bevy_app::FixedUpdate), even if it is still during the same
|
||||||
/// frame. Any [`overstep()`](Time::overstep) present in the accumulator will be
|
/// frame. Any [`overstep()`](Time::overstep) present in the accumulator will be
|
||||||
/// processed according to the new [`timestep()`](Time::timestep) value.
|
/// processed according to the new [`timestep()`](Time::timestep) value.
|
||||||
#[derive(Debug, Copy, Clone, Reflect)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||||
pub struct Fixed {
|
pub struct Fixed {
|
||||||
timestep: Duration,
|
timestep: Duration,
|
||||||
overstep: Duration,
|
overstep: Duration,
|
||||||
|
|||||||
@ -51,13 +51,18 @@ impl Plugin for TimePlugin {
|
|||||||
.init_resource::<Time<Real>>()
|
.init_resource::<Time<Real>>()
|
||||||
.init_resource::<Time<Virtual>>()
|
.init_resource::<Time<Virtual>>()
|
||||||
.init_resource::<Time<Fixed>>()
|
.init_resource::<Time<Fixed>>()
|
||||||
.init_resource::<TimeUpdateStrategy>()
|
.init_resource::<TimeUpdateStrategy>();
|
||||||
.register_type::<Time>()
|
|
||||||
.register_type::<Time<Real>>()
|
#[cfg(feature = "bevy_reflect")]
|
||||||
.register_type::<Time<Virtual>>()
|
{
|
||||||
.register_type::<Time<Fixed>>()
|
app.register_type::<Time>()
|
||||||
.register_type::<Timer>()
|
.register_type::<Time<Real>>()
|
||||||
.add_systems(First, time_system.in_set(TimeSystem))
|
.register_type::<Time<Virtual>>()
|
||||||
|
.register_type::<Time<Fixed>>()
|
||||||
|
.register_type::<Timer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.add_systems(First, time_system.in_set(TimeSystem))
|
||||||
.add_systems(RunFixedMainLoop, run_fixed_main_schedule);
|
.add_systems(RunFixedMainLoop, run_fixed_main_schedule);
|
||||||
|
|
||||||
// ensure the events are not dropped until `FixedMain` systems can observe them
|
// ensure the events are not dropped until `FixedMain` systems can observe them
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::Reflect;
|
||||||
use bevy_utils::{Duration, Instant};
|
use bevy_utils::{Duration, Instant};
|
||||||
|
|
||||||
@ -28,7 +29,8 @@ use crate::time::Time;
|
|||||||
/// [`Instant`]s for [`startup()`](Time::startup),
|
/// [`Instant`]s for [`startup()`](Time::startup),
|
||||||
/// [`first_update()`](Time::first_update) and
|
/// [`first_update()`](Time::first_update) and
|
||||||
/// [`last_update()`](Time::last_update) are recorded and accessible.
|
/// [`last_update()`](Time::last_update) are recorded and accessible.
|
||||||
#[derive(Debug, Copy, Clone, Reflect)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||||
pub struct Real {
|
pub struct Real {
|
||||||
startup: Instant,
|
startup: Instant,
|
||||||
first_update: Option<Instant>,
|
first_update: Option<Instant>,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::{prelude::*, Reflect};
|
use bevy_reflect::{prelude::*, Reflect};
|
||||||
use bevy_utils::Duration;
|
use bevy_utils::Duration;
|
||||||
|
|
||||||
@ -22,9 +23,9 @@ use bevy_utils::Duration;
|
|||||||
/// assert!(stopwatch.paused());
|
/// assert!(stopwatch.paused());
|
||||||
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
|
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Reflect)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[reflect(Default)]
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default))]
|
||||||
pub struct Stopwatch {
|
pub struct Stopwatch {
|
||||||
elapsed: Duration,
|
elapsed: Duration,
|
||||||
paused: bool,
|
paused: bool,
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use bevy_ecs::{reflect::ReflectResource, system::Resource};
|
#[cfg(feature = "bevy_reflect")]
|
||||||
|
use bevy_ecs::reflect::ReflectResource;
|
||||||
|
use bevy_ecs::system::Resource;
|
||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
use bevy_utils::Duration;
|
use bevy_utils::Duration;
|
||||||
|
|
||||||
@ -183,8 +186,8 @@ use bevy_utils::Duration;
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Resource, Debug, Copy, Clone, Reflect)]
|
#[derive(Resource, Debug, Copy, Clone)]
|
||||||
#[reflect(Resource, Default)]
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Resource, Default))]
|
||||||
pub struct Time<T: Default = ()> {
|
pub struct Time<T: Default = ()> {
|
||||||
context: T,
|
context: T,
|
||||||
wrap_period: Duration,
|
wrap_period: Duration,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use crate::Stopwatch;
|
use crate::Stopwatch;
|
||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::prelude::*;
|
use bevy_reflect::prelude::*;
|
||||||
use bevy_utils::Duration;
|
use bevy_utils::Duration;
|
||||||
|
|
||||||
@ -9,9 +10,9 @@ use bevy_utils::Duration;
|
|||||||
/// exceeded, and can still be reset at any given point.
|
/// exceeded, and can still be reset at any given point.
|
||||||
///
|
///
|
||||||
/// Paused timers will not have elapsed time increased.
|
/// Paused timers will not have elapsed time increased.
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Reflect)]
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[reflect(Default)]
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default))]
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
stopwatch: Stopwatch,
|
stopwatch: Stopwatch,
|
||||||
duration: Duration,
|
duration: Duration,
|
||||||
@ -425,9 +426,9 @@ impl Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Specifies [`Timer`] behavior.
|
/// Specifies [`Timer`] behavior.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default, Reflect)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default)]
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[reflect(Default)]
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default))]
|
||||||
pub enum TimerMode {
|
pub enum TimerMode {
|
||||||
/// Run once and stop.
|
/// Run once and stop.
|
||||||
#[default]
|
#[default]
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::Reflect;
|
use bevy_reflect::Reflect;
|
||||||
use bevy_utils::{tracing::debug, Duration};
|
use bevy_utils::{tracing::debug, Duration};
|
||||||
|
|
||||||
@ -67,7 +68,8 @@ use crate::{real::Real, time::Time};
|
|||||||
/// time. You should also consider how stable your FPS is, as the limit will
|
/// time. You should also consider how stable your FPS is, as the limit will
|
||||||
/// also dictate how big of an FPS drop you can accept without losing time and
|
/// also dictate how big of an FPS drop you can accept without losing time and
|
||||||
/// falling behind real time.
|
/// falling behind real time.
|
||||||
#[derive(Debug, Copy, Clone, Reflect)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||||
pub struct Virtual {
|
pub struct Virtual {
|
||||||
max_delta: Duration,
|
max_delta: Duration,
|
||||||
paused: bool,
|
paused: bool,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user