diff options
Diffstat (limited to 'ecs/src/archetype.rs')
-rw-r--r-- | ecs/src/archetype.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ecs/src/archetype.rs b/ecs/src/archetype.rs new file mode 100644 index 0000000..a33de66 --- /dev/null +++ b/ecs/src/archetype.rs @@ -0,0 +1,27 @@ +use std::hash::{DefaultHasher, Hash, Hasher}; + +use crate::component::Id as ComponentId; + +/// Archetype ID. +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct Id +{ + hash: u64, +} + +impl Id +{ + /// Returns the ID of a archetype with the given components. + pub fn new(component_ids: impl IntoIterator<Item = ComponentId>) -> Self + { + let mut hasher = DefaultHasher::new(); + + for component_id in component_ids { + component_id.hash(&mut hasher); + } + + let hash = hasher.finish(); + + Self { hash } + } +} |