From 68912982d8f909569e932d5373485b435c71d6b2 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 26 Sep 2026 18:42:46 +0200 Subject: fix(engine-ecs): remove bad entity & component existance checks in Actions fns --- engine-ecs/src/actions.rs | 64 +++++------------------------------------------ 1 file changed, 6 insertions(+), 58 deletions(-) (limited to 'engine-ecs/src') diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs index d079a85..cbf996f 100644 --- a/engine-ecs/src/actions.rs +++ b/engine-ecs/src/actions.rs @@ -14,7 +14,7 @@ use crate::{ActionQueue, World}; pub struct Actions<'world> { action_queue: &'world ActionQueue, - world: Option<&'world World>, + world: &'world World, } impl Actions<'_> @@ -82,12 +82,7 @@ impl Actions<'_> { debug_assert!(!entity_uid.is_pair()); - let Some(world) = self.world else { - self.action_queue.push(Action::Despawn(entity_uid)); - return; - }; - - let Some(ent) = world.get_entity(entity_uid) else { + let Some(ent) = self.world.get_entity(entity_uid) else { tracing::warn!("Cannot entity that doesn't exist"); return; }; @@ -98,7 +93,7 @@ impl Actions<'_> continue; } - world.event_submitter().submit_event( + self.world.event_submitter().submit_event( &Pair::builder() .relation::() .target_id(comp_id) @@ -151,26 +146,7 @@ impl Actions<'_> return; } - let Some(world) = self.world else { - self.action_queue.push(Action::RemoveComponents( - entity_uid, - component_ids.collect(), - )); - return; - }; - - let Some(ent) = world.get_entity(entity_uid) else { - tracing::warn!("Cannot remove components from entity that doesn't exist"); - return; - }; - - let component_ids = component_ids - .filter(|comp_id| ent.has_component(*comp_id)) - .collect::>(); - - if component_ids.is_empty() { - return; - } + let component_ids = component_ids.collect::>(); // TODO: Submit all events with a single function call to reduce overhead for comp_id in &component_ids { @@ -178,7 +154,7 @@ impl Actions<'_> continue; } - world.event_submitter().submit_event( + self.world.event_submitter().submit_event( &Pair::builder() .relation::() .target_id(*comp_id) @@ -214,13 +190,6 @@ impl Actions<'_> debug_assert!(!entity_id.is_pair()); debug_assert!(!new_target_id.is_pair()); - if let Some(world) = self.world { - if world.get_entity(entity_id).is_none() { - tracing::error!("Entity does not exist"); - return; - } - } - let pair_id = pair.id(); self.action_queue.push(Action::SetPair { @@ -251,13 +220,6 @@ impl Actions<'_> { debug_assert!(!entity_id.is_pair()); - if let Some(world) = self.world { - if world.get_entity(entity_id).is_none() { - tracing::error!("Entity does not exist"); - return; - } - } - let pair_id = pair.id(); self.action_queue.push(Action::SetPair { @@ -288,13 +250,6 @@ impl Actions<'_> debug_assert!(!entity_id.is_pair()); debug_assert!(!new_relation_id.is_pair()); - if let Some(world) = self.world { - if world.get_entity(entity_id).is_none() { - tracing::error!("Entity does not exist"); - return; - } - } - let pair_id = pair.id(); self.action_queue.push(Action::SetPair { @@ -325,13 +280,6 @@ impl Actions<'_> { debug_assert!(!entity_id.is_pair()); - if let Some(world) = self.world { - if world.get_entity(entity_id).is_none() { - tracing::error!("Entity does not exist"); - return; - } - } - let pair_id = pair.id(); self.action_queue.push(Action::SetPair { @@ -361,7 +309,7 @@ impl<'world> SystemParam<'world> for Actions<'world> { Self { action_queue: &world.data.action_queue, - world: Some(world), + world, } } } -- cgit v1.2.3-18-g5258