summaryrefslogtreecommitdiff
path: root/ecs/src/archetype.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-01 12:36:35 +0200
committerHampusM <hampus@hampusmat.com>2024-08-01 12:36:35 +0200
commit70c7d745f918dd23343599963a619539f4f880cb (patch)
tree076779b4364649fcea76ce07a6cd1d6b8d6956f2 /ecs/src/archetype.rs
parenta5c45dab18399461aff5dc13c471ea6c5ec80c34 (diff)
refactor(ecs): add & use component metadata struct
Diffstat (limited to 'ecs/src/archetype.rs')
-rw-r--r--ecs/src/archetype.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/ecs/src/archetype.rs b/ecs/src/archetype.rs
index a33de66..808d006 100644
--- a/ecs/src/archetype.rs
+++ b/ecs/src/archetype.rs
@@ -1,6 +1,10 @@
use std::hash::{DefaultHasher, Hash, Hasher};
-use crate::component::Id as ComponentId;
+use crate::component::{
+ Id as ComponentId,
+ IsOptional as ComponentIsOptional,
+ Metadata as ComponentMetadata,
+};
/// Archetype ID.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
@@ -11,8 +15,25 @@ pub struct Id
impl Id
{
+ pub fn from_components_metadata(
+ components_metadata: impl IntoIterator<Item = ComponentMetadata>,
+ ) -> Self
+ {
+ Self::new(
+ components_metadata
+ .into_iter()
+ .filter_map(|component_metadata| {
+ if component_metadata.is_optional == ComponentIsOptional::Yes {
+ return None;
+ }
+
+ Some(component_metadata.id)
+ }),
+ )
+ }
+
/// Returns the ID of a archetype with the given components.
- pub fn new(component_ids: impl IntoIterator<Item = ComponentId>) -> Self
+ fn new(component_ids: impl IntoIterator<Item = ComponentId>) -> Self
{
let mut hasher = DefaultHasher::new();