diff options
Diffstat (limited to 'engine-ecs/src/lib.rs')
| -rw-r--r-- | engine-ecs/src/lib.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs index 46f4592..6656440 100644 --- a/engine-ecs/src/lib.rs +++ b/engine-ecs/src/lib.rs @@ -6,6 +6,7 @@ use std::fmt::Debug; use std::hint::cold_path; use std::rc::Rc; use std::sync::atomic::{AtomicBool, Ordering}; +use std::time::Duration; use crate::actions::Action; use crate::component::storage::archetype::EntityComponent as ArchetypeEntityComponent; @@ -51,7 +52,7 @@ use crate::query::{ MAX_TERM_CNT as QUERY_MAX_TERM_CNT, }; use crate::reflection::Type as TypeReflection; -use crate::sole::Sole; +use crate::sole::{Single, Sole}; use crate::system::observer::Observer; use crate::system::{ Callbacks, @@ -73,6 +74,7 @@ pub mod phase; pub mod query; pub mod sole; pub mod system; +pub mod time; pub mod tuple; pub mod uid; pub mod util; @@ -106,6 +108,11 @@ impl World error_handler: err_handler_panic, }; + let _ = world.add_sole(time::Time { + delta_time: Duration::default(), + tick_begin: None, + }); + crate::phase::spawn_standard_phases(&mut world); crate::error::set_panic_hook(); @@ -308,6 +315,11 @@ impl World Some(EntityHandle::new(archetype, entity, self)) } + pub fn get_sole<SoleT: Sole>(&self) -> Single<'_, SoleT> + { + Single::<SoleT>::new(self) + } + pub fn event_submitter(&self) -> EventSubmitter<'_> { EventSubmitter::new(&self.data.new_events) @@ -322,6 +334,16 @@ impl World return StepResult::Stop; } + { + let mut time = self.get_sole::<time::Time>(); + + let Ok(time) = time.get_mut() else { + unreachable!(); + }; + + time::update(&mut *time); + } + if self .is_first_tick .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) |
