22
33/// Common run conditions
44pub mod common_conditions;
5- pub mod fixed_timestep;
5+ mod fixed;
6+ mod real;
67mod stopwatch;
78#[ allow( clippy:: module_inception) ]
89mod time;
910mod timer;
11+ mod virt;
1012
11- use fixed_timestep:: FixedTime ;
1213pub use stopwatch:: * ;
1314pub use time:: * ;
1415pub use timer:: * ;
@@ -20,13 +21,17 @@ use crossbeam_channel::{Receiver, Sender};
2021pub mod prelude {
2122 //! The Bevy Time Prelude.
2223 #[ doc( hidden) ]
23- pub use crate :: { fixed_timestep :: FixedTime , Time , Timer , TimerMode } ;
24+ pub use crate :: { Time , Timer , TimerMode } ;
2425}
2526
2627use bevy_app:: { prelude:: * , RunFixedUpdateLoop } ;
2728use bevy_ecs:: prelude:: * ;
2829
29- use crate :: fixed_timestep:: run_fixed_update_schedule;
30+ use crate :: fixed:: run_fixed_update_schedule;
31+ use crate :: fixed:: Fixed ;
32+ use crate :: real:: Real ;
33+ use crate :: virt:: virtual_time_system;
34+ use crate :: virt:: Virtual ;
3035
3136/// Adds time functionality to Apps.
3237#[ derive( Default ) ]
@@ -40,12 +45,20 @@ pub struct TimeSystem;
4045impl Plugin for TimePlugin {
4146 fn build ( & self , app : & mut App ) {
4247 app. init_resource :: < Time > ( )
48+ . init_resource :: < Time < Real > > ( )
49+ . init_resource :: < Time < Virtual > > ( )
50+ . init_resource :: < Time < Fixed > > ( )
4351 . init_resource :: < TimeUpdateStrategy > ( )
44- . register_type :: < Timer > ( )
4552 . register_type :: < Time > ( )
53+ . register_type :: < Time < Real > > ( )
54+ . register_type :: < Time < Virtual > > ( )
55+ . register_type :: < Time < Fixed > > ( )
56+ . register_type :: < Timer > ( )
4657 . register_type :: < Stopwatch > ( )
47- . init_resource :: < FixedTime > ( )
48- . add_systems ( First , time_system. in_set ( TimeSystem ) )
58+ . add_systems (
59+ First ,
60+ ( time_system, virtual_time_system. after ( time_system) ) . in_set ( TimeSystem ) ,
61+ )
4962 . add_systems ( RunFixedUpdateLoop , run_fixed_update_schedule) ;
5063
5164 #[ cfg( feature = "bevy_ci_testing" ) ]
@@ -96,7 +109,7 @@ pub fn create_time_channels() -> (TimeSender, TimeReceiver) {
96109/// The system used to update the [`Time`] used by app logic. If there is a render world the time is sent from
97110/// there to this system through channels. Otherwise the time is updated in this system.
98111fn time_system (
99- mut time : ResMut < Time > ,
112+ mut time : ResMut < Time < Real > > ,
100113 update_strategy : Res < TimeUpdateStrategy > ,
101114 time_recv : Option < Res < TimeReceiver > > ,
102115 mut has_received_time : Local < bool > ,
@@ -119,9 +132,6 @@ fn time_system(
119132 match update_strategy. as_ref ( ) {
120133 TimeUpdateStrategy :: Automatic => time. update_with_instant ( new_time) ,
121134 TimeUpdateStrategy :: ManualInstant ( instant) => time. update_with_instant ( * instant) ,
122- TimeUpdateStrategy :: ManualDuration ( duration) => {
123- let last_update = time. last_update ( ) . unwrap_or_else ( || time. startup ( ) ) ;
124- time. update_with_instant ( last_update + * duration) ;
125- }
135+ TimeUpdateStrategy :: ManualDuration ( duration) => time. update_with_duration ( * duration) ,
126136 }
127137}
0 commit comments