summaryrefslogtreecommitdiff
path: root/ecs/src/component/storage.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/component/storage.rs')
-rw-r--r--ecs/src/component/storage.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs
index 1db9227..70981a3 100644
--- a/ecs/src/component/storage.rs
+++ b/ecs/src/component/storage.rs
@@ -65,13 +65,17 @@ impl Storage
.map(|component| component.id()),
))
.or_insert_with(|| {
- self.archetypes.push(Archetype::default());
+ self.archetypes.push(Archetype::new(
+ components.iter().map(|component| component.id()),
+ ));
vec![self.archetypes.len() - 1]
});
if archetype_indices.is_empty() {
- self.archetypes.push(Archetype::default());
+ self.archetypes.push(Archetype::new(
+ components.iter().map(|component| component.id()),
+ ));
archetype_indices.push(self.archetypes.len() - 1);
}
@@ -86,10 +90,6 @@ impl Storage
)
.expect("Archetype is gone");
- archetype
- .component_ids
- .extend(components.iter().map(|component| component.id()));
-
archetype.components.push(
components
.into_iter()
@@ -147,13 +147,24 @@ impl TypeName for Storage
}
}
-#[derive(Debug, Default)]
+#[derive(Debug)]
pub struct Archetype
{
component_ids: HashSet<ComponentId>,
pub components: Vec<Vec<EntityComponent>>,
}
+impl Archetype
+{
+ fn new(component_ids: impl IntoIterator<Item = ComponentId>) -> Self
+ {
+ Self {
+ component_ids: component_ids.into_iter().collect(),
+ components: Vec::new(),
+ }
+ }
+}
+
#[derive(Debug)]
pub struct ArchetypeRefIter<'component_storage>
{