From 4313b5b0bfa79f4eaed25b65c5a7154c16074208 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 28 Jul 2024 19:46:01 +0200 Subject: refactor(ecs): move ArchetypeComponentsHash to archetype::Id --- ecs/src/archetype.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 ecs/src/archetype.rs (limited to 'ecs/src/archetype.rs') 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) -> Self + { + let mut hasher = DefaultHasher::new(); + + for component_id in component_ids { + component_id.hash(&mut hasher); + } + + let hash = hasher.finish(); + + Self { hash } + } +} -- cgit v1.2.3-18-g5258