diff options
author | HampusM <hampus@hampusmat.com> | 2024-12-09 14:05:33 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-12-09 14:05:33 +0100 |
commit | dcc40c9205e5f4cf484523f97eb12a561d7b2b22 (patch) | |
tree | 2908b6ca3b2fa390a45b383b91edf7a72c42ef4b /ecs/src/actions.rs | |
parent | 158e36bf6bfcbc2ed0ffc670788ed8c0abd3f282 (diff) |
refactor(ecs): use phases for system ordering
Diffstat (limited to 'ecs/src/actions.rs')
-rw-r--r-- | ecs/src/actions.rs | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index f7b00d3..35e9569 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -20,36 +20,45 @@ pub struct Actions<'world> impl<'world> Actions<'world> { - /// Adds a spawning a new entity to the action queue. + /// Queues up a entity to spawn at the end of the current tick. pub fn spawn<Comps: ComponentSequence>(&mut self, components: Comps) { - self.action_queue.push(Action::Spawn(components.into_vec())); + self.action_queue.push(Action::Spawn( + components.into_vec(), + EventIds { ids: Comps::added_event_ids() }, + )); } - /// Adds component(s) to a entity. + /// Queues up adding component(s) to a entity at the end of the current tick. pub fn add_components<Comps>(&mut self, entity_uid: Uid, components: Comps) where Comps: ComponentSequence, { debug_assert_eq!(entity_uid.kind(), UidKind::Entity); - self.action_queue - .push(Action::AddComponents(entity_uid, components.into_vec())); + self.action_queue.push(Action::AddComponents( + entity_uid, + components.into_vec(), + EventIds { ids: Comps::added_event_ids() }, + )); } - /// Removes component(s) from a entity. + /// Queues up removing component(s) from a entity at the end of the current tick. pub fn remove_components<Comps>(&mut self, entity_uid: Uid) where Comps: ComponentSequence, { debug_assert_eq!(entity_uid.kind(), UidKind::Entity); - self.action_queue - .push(Action::RemoveComponents(entity_uid, Comps::metadata())); + self.action_queue.push(Action::RemoveComponents( + entity_uid, + Comps::metadata(), + EventIds { ids: Comps::removed_event_ids() }, + )); } - /// Adds stopping the loop in [`Engine::event_loop`] at the next opportune time to the - /// action queue. + /// Stops the [`World`]. The world will finish the current tick and that tick will be + /// the last. pub fn stop(&mut self) { self.action_queue.push(Action::Stop); @@ -135,12 +144,18 @@ impl<'weak_ref> Ref<'weak_ref> } } +#[derive(Debug)] +pub(crate) struct EventIds +{ + pub(crate) ids: Vec<Uid>, +} + /// A action for a [`System`] to perform. #[derive(Debug)] pub(crate) enum Action { - Spawn(Vec<Box<dyn Component>>), - AddComponents(Uid, Vec<Box<dyn Component>>), - RemoveComponents(Uid, Vec<ComponentMetadata>), + Spawn(Vec<Box<dyn Component>>, EventIds), + AddComponents(Uid, Vec<Box<dyn Component>>, EventIds), + RemoveComponents(Uid, Vec<ComponentMetadata>, EventIds), Stop, } |