summaryrefslogtreecommitdiff
path: root/ecs/src/archetype.rs
diff options
context:
space:
mode:
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();