diff options
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 3c517dd..6725d81 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use crate::actions::Action; use crate::component::storage::Storage as ComponentStorage; use crate::component::{Component, Id as ComponentId, Sequence as ComponentSequence}; -use crate::entity::Uid as EntityUid; +use crate::entity::{Uid as EntityUid, CREATE_STATIC_ENTITIES}; use crate::event::component::{ create_added_id as create_component_added_event_id, create_removed_id as create_component_removed_event_id, @@ -42,6 +42,9 @@ pub mod system; pub mod tuple; pub mod type_name; +#[doc(hidden)] +pub mod private; + mod archetype; mod util; @@ -75,7 +78,6 @@ impl World /// /// # Panics /// Will panic if mutable internal lock cannot be acquired. - #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] pub fn create_entity<Comps>(&mut self, components: Comps) -> EntityUid where Comps: ComponentSequence + TupleReduce<TypeTransformComponentsToAddedEvents>, @@ -83,6 +85,17 @@ impl World { let entity_uid = EntityUid::new_unique(); + self.create_entity_with_uid(components, entity_uid); + + entity_uid + } + + #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] + pub fn create_entity_with_uid<Comps>(&self, components: Comps, entity_uid: EntityUid) + where + Comps: ComponentSequence + TupleReduce<TypeTransformComponentsToAddedEvents>, + Comps::Out: EventSequence, + { #[allow(unused_variables)] if let Err(err) = self .data @@ -94,14 +107,12 @@ impl World #[cfg(feature = "debug")] tracing::error!("Failed to create entity: {err}"); - return entity_uid; + return; }; for component_added_event_id in <Comps::Out as EventSequence>::ids().iter() { self.emit_event_by_id(*component_added_event_id); } - - entity_uid } /// Adds a globally shared singleton value. @@ -279,6 +290,10 @@ impl World /// Will panic if a internal lock cannot be acquired. pub fn event_loop<EventSeq: EventSequence>(&self) { + for create_static_entity in CREATE_STATIC_ENTITIES { + create_static_entity(self); + } + self.emit(StartEvent); let event_seq = EventSeq::ids(); |