diff options
Diffstat (limited to 'ecs/src/archetype.rs')
-rw-r--r-- | ecs/src/archetype.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/ecs/src/archetype.rs b/ecs/src/archetype.rs index d2ee36a..354d206 100644 --- a/ecs/src/archetype.rs +++ b/ecs/src/archetype.rs @@ -4,7 +4,6 @@ use crate::component::{ IsOptional as ComponentIsOptional, Metadata as ComponentMetadata, }; -use crate::uid::Uid; /// Archetype ID. #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] @@ -19,10 +18,9 @@ impl Id components_metadata: &impl AsRef<[ComponentMetadata]>, ) -> Self { - debug_assert!( - components_metadata.as_ref().len() > 0, - "Cannot create a archetype ID from a empty component metadata list" - ); + if components_metadata.as_ref().len() == 0 { + return Self { hash: 0 }; + } debug_assert!( components_metadata @@ -31,7 +29,7 @@ impl Id "Cannot create archetype ID from a unsorted component metadata list" ); - Self::new( + let component_ids = components_metadata .as_ref() .iter() @@ -41,13 +39,8 @@ impl Id } Some(component_metadata.id) - }), - ) - } + }); - /// Returns the ID of a archetype with the given components. - fn new(component_ids: impl IntoIterator<Item = Uid>) -> Self - { let mut hasher = DefaultHasher::new(); for component_id in component_ids { @@ -56,6 +49,11 @@ impl Id let hash = hasher.finish(); + assert_ne!( + hash, 0, + "Archetype ID 0 is reserved for a archetype with zero components" + ); + Self { hash } } } |