From 7fe8e9ea15fac647fe8655ee096a9aa5703a97c6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 6 Jun 2026 18:55:07 +0200 Subject: feat(engine-ecs): remove Uid kinds --- engine-ecs/src/component/storage.rs | 29 +++++++++----------- engine-ecs/src/component/storage/archetype.rs | 39 +++++++-------------------- engine-ecs/src/component/storage/graph.rs | 7 +---- 3 files changed, 23 insertions(+), 52 deletions(-) (limited to 'engine-ecs/src/component') diff --git a/engine-ecs/src/component/storage.rs b/engine-ecs/src/component/storage.rs index d4457bb..e77cfa3 100644 --- a/engine-ecs/src/component/storage.rs +++ b/engine-ecs/src/component/storage.rs @@ -17,7 +17,7 @@ use crate::component::storage::graph::{ ArchetypeEdges, Graph, }; -use crate::uid::{Kind as UidKind, Uid}; +use crate::uid::Uid; use crate::util::{BorrowedOrOwned, Either, StreamingIterator, VecExt}; pub mod archetype; @@ -35,21 +35,18 @@ impl ArchetypeSearchTerms<'_> { fn excluded_contains(&self, comp_id: Uid) -> bool { - let comp_id_kind = comp_id.kind(); - debug_assert!( - comp_id_kind == UidKind::Component - || (comp_id_kind == UidKind::Pair - && comp_id.target_component() != Uid::wildcard()) + !comp_id.is_pair() + || (comp_id.is_pair() && comp_id.target() != Uid::wildcard()) ); let is_found = self.excluded_components.binary_search(&comp_id).is_ok(); - if !is_found && comp_id_kind == UidKind::Pair { + if !is_found && comp_id.is_pair() { return self.excluded_components.iter().any(|excluded_comp_id| { - excluded_comp_id.kind() == UidKind::Pair + excluded_comp_id.is_pair() && excluded_comp_id.has_same_relation_as(comp_id) - && excluded_comp_id.target_component() == Uid::wildcard() + && excluded_comp_id.target() == Uid::wildcard() }); } @@ -107,8 +104,8 @@ impl Storage .push(ImaginaryArchetype { id: ArchetypeId::new(search_terms.required_components.iter().filter( |required_comp_id| { - required_comp_id.kind() != UidKind::Pair - || required_comp_id.target_component() != Uid::wildcard() + !required_comp_id.is_pair() + || required_comp_id.target() != Uid::wildcard() }, )), component_ids: search_terms @@ -116,8 +113,8 @@ impl Storage .iter() .copied() .filter(|required_comp_id| { - required_comp_id.kind() != UidKind::Pair - || required_comp_id.target_component() != Uid::wildcard() + !required_comp_id.is_pair() + || required_comp_id.target() != Uid::wildcard() }) .collect(), }); @@ -147,7 +144,7 @@ impl Storage pub fn create_entity(&mut self, uid: Uid) -> Result<(), EntityAlreadyExistsError> { - debug_assert_eq!(uid.kind(), UidKind::Entity); + debug_assert!(!uid.is_pair()); if self.entity_archetype_lookup.contains_key(&uid) { return Err(EntityAlreadyExistsError); @@ -768,14 +765,14 @@ mod tests { use crate::component::storage::archetype::Id as ArchetypeId; use crate::component::storage::Storage; - use crate::uid::{Kind as UidKind, Uid}; + use crate::uid::Uid; #[test] fn create_entity_works() { let mut new_storage = Storage::default(); - let uid = Uid::new_unique(UidKind::Entity); + let uid = Uid::new_unique(); new_storage.create_entity(uid).expect("Expected Ok"); diff --git a/engine-ecs/src/component/storage/archetype.rs b/engine-ecs/src/component/storage/archetype.rs index a7fe7ed..c5cce10 100644 --- a/engine-ecs/src/component/storage/archetype.rs +++ b/engine-ecs/src/component/storage/archetype.rs @@ -8,7 +8,7 @@ use std::slice::Iter as SliceIter; use hashbrown::HashMap; use crate::lock::Lock; -use crate::uid::{Kind as UidKind, Uid}; +use crate::uid::Uid; use crate::util::{Either, HashMapExt}; #[derive(Debug)] @@ -77,8 +77,6 @@ impl Archetype pub fn remove_entity(&mut self, entity_uid: Uid) -> Option { - //debug_assert_eq!(entity_uid.kind(), UidKind::Entity); - let entity_index = self.entity_index_lookup.remove(&entity_uid)?; if self.entities.len() == 1 { @@ -124,14 +122,7 @@ impl Archetype component_id: Uid, ) -> MatchingComponentIter<'_> { - assert!( - component_id.kind() == UidKind::Component - || component_id.kind() == UidKind::Pair - ); - - if component_id.kind() == UidKind::Pair - && component_id.target_component() == Uid::wildcard() - { + if component_id.is_pair() && component_id.target() == Uid::wildcard() { return MatchingComponentIter { inner: Either::A( self.component_ids @@ -140,7 +131,7 @@ impl Archetype .zip(std::iter::repeat_n(component_id, self.component_ids.len())) .filter( (|((_, other_comp_id), component_id)| { - other_comp_id.kind() == UidKind::Pair + other_comp_id.is_pair() && other_comp_id.has_same_relation_as(*component_id) }) as MatchingComponentIterFilterFn, @@ -162,9 +153,8 @@ impl Archetype pub fn get_index_for_component(&self, component_id: Uid) -> Option { assert!( - component_id.kind() == UidKind::Component - || (component_id.kind() == UidKind::Pair - && component_id.target_component() != Uid::wildcard()) + !component_id.is_pair() + || (component_id.is_pair() && component_id.target() != Uid::wildcard()) ); self.component_index_lookup.get(&component_id).copied() @@ -182,17 +172,9 @@ impl Archetype pub fn contains_matching_component(&self, component_id: Uid) -> bool { - let component_id_kind = component_id.kind(); - - debug_assert!( - component_id_kind == UidKind::Component || component_id_kind == UidKind::Pair - ); - - if component_id.kind() == UidKind::Pair - && component_id.target_component() == Uid::wildcard() - { + if component_id.is_pair() && component_id.target() == Uid::wildcard() { return self.component_ids.iter().any(|other_comp_id| { - other_comp_id.kind() == UidKind::Pair + other_comp_id.is_pair() && other_comp_id.has_same_relation_as(component_id) }); } @@ -202,12 +184,9 @@ impl Archetype pub fn contains_component_with_exact_id(&self, component_id: Uid) -> bool { - let component_id_kind = component_id.kind(); - debug_assert!( - component_id_kind == UidKind::Component - || (component_id_kind == UidKind::Pair - && component_id.target_component() != Uid::wildcard()) + !component_id.is_pair() + || (component_id.is_pair() && component_id.target() != Uid::wildcard()) ); self.component_index_lookup.contains_key(&component_id) diff --git a/engine-ecs/src/component/storage/graph.rs b/engine-ecs/src/component/storage/graph.rs index 76200f9..add25e4 100644 --- a/engine-ecs/src/component/storage/graph.rs +++ b/engine-ecs/src/component/storage/graph.rs @@ -3,7 +3,7 @@ use std::vec::IntoIter as VecIntoIter; use hashbrown::{HashMap, HashSet}; use crate::component::storage::archetype::{Archetype, Id as ArchetypeId}; -use crate::uid::{Kind as UidKind, Uid}; +use crate::uid::Uid; use crate::util::{BorrowedOrOwned, StreamingIterator}; #[derive(Debug, Default)] @@ -250,11 +250,6 @@ impl ArchetypeNode insert_fn: impl FnOnce() -> ArchetypeEdges, ) -> &mut ArchetypeEdges { - debug_assert!(matches!( - component_id.kind(), - UidKind::Component | UidKind::Pair - )); - self.edges.entry(component_id).or_insert_with(insert_fn) } -- cgit v1.2.3-18-g5258