summaryrefslogtreecommitdiff
path: root/ecs/src/component/storage.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-06-16 18:24:37 +0200
committerHampusM <hampus@hampusmat.com>2024-06-16 18:24:37 +0200
commita7c9b0a9dfe5051a60763e123df47f4c16052e32 (patch)
tree826719f0ea9d95f79adfdbfd09d6ae525b83dff6 /ecs/src/component/storage.rs
parente25f4f2af6e5e522f8b6ad0ca0b84f607a73cae2 (diff)
fix(ecs): create new archetype when archetype lookup entry is empty
Diffstat (limited to 'ecs/src/component/storage.rs')
-rw-r--r--ecs/src/component/storage.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs
index f174ea9..237dd73 100644
--- a/ecs/src/component/storage.rs
+++ b/ecs/src/component/storage.rs
@@ -77,7 +77,7 @@ impl ComponentStorage
.join(", ")
);
- let archetypes_indices = self
+ let archetype_indices = self
.archetype_lookup
.entry(ArchetypeComponentsHash::new(
components
@@ -91,10 +91,16 @@ impl ComponentStorage
vec![self.archetypes.len() - 1]
});
+ if archetype_indices.is_empty() {
+ self.archetypes.push(Archetype::default());
+
+ archetype_indices.push(self.archetypes.len() - 1);
+ }
+
let archetype = self
.archetypes
.get_mut(
- archetypes_indices
+ archetype_indices
.first()
.copied()
.expect("No archetype index found"),