diff options
author | HampusM <hampus@hampusmat.com> | 2024-07-28 19:46:01 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-07-28 19:46:36 +0200 |
commit | 4313b5b0bfa79f4eaed25b65c5a7154c16074208 (patch) | |
tree | 0a68dd567a2bcf1e64f68b59d6b92a0dd33d7c63 /ecs/src/archetype.rs | |
parent | 3cdef8ac2a96a91c9ab62a7ca49c128516c44efa (diff) |
refactor(ecs): move ArchetypeComponentsHash to archetype::Id
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 } + } +} |