diff options
Diffstat (limited to 'ecs/src/component')
-rw-r--r-- | ecs/src/component/storage.rs | 45 | ||||
-rw-r--r-- | ecs/src/component/storage/graph.rs | 17 |
2 files changed, 28 insertions, 34 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 4a00510..0a6382b 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -192,41 +192,39 @@ impl Storage }); } - let add_edge_archetype_id = archetype_node + let add_edge_archetype_id = match archetype_node .get_or_insert_edges(component_id, ArchetypeEdges::default) .add - .unwrap_or_else(|| { + { + Some(add_edge_id) => { + if !self.graph.contains_archetype(add_edge_id) { + let (_, add_edge_comp_ids) = self + .graph + .get_node_by_id(archetype_id) + .expect("Archetype should exist") + .make_add_edge(component_id); + + self.graph.create_node(add_edge_id, &add_edge_comp_ids); + } + + add_edge_id + } + None => { let archetype_node = self .graph - .get_node_by_id_mut(archetype_id) + .get_node_by_id(archetype_id) .expect("Archetype should exist"); let (add_edge_id, add_edge_comp_ids) = archetype_node.make_add_edge(component_id); - archetype_node - .get_edges_mut(component_id) - .expect("Edges for component in archetype should exist") - .add = Some(add_edge_id); - if !self.graph.contains_archetype(add_edge_id) { self.graph.create_node(add_edge_id, &add_edge_comp_ids); } add_edge_id - }); - - { - let add_edge_archetype_node = self - .graph - .get_node_by_id_mut(add_edge_archetype_id) - .expect("Add edge archetype should exist"); - - let add_edge_archetype_edges = add_edge_archetype_node - .get_or_insert_edges(component_id, ArchetypeEdges::default); - - add_edge_archetype_edges.remove = Some(archetype_id); - } + } + }; let archetype_node = self .graph @@ -297,11 +295,6 @@ impl Storage let (remove_edge_id, remove_edge_comp_ids) = archetype_node.make_remove_edge(component_id); - archetype_node - .get_edges_mut(component_id) - .expect("Edges for component in archetype should exist") - .remove = Some(remove_edge_id); - if !self.graph.contains_archetype(remove_edge_id) { self.graph .create_node(remove_edge_id, &remove_edge_comp_ids); diff --git a/ecs/src/component/storage/graph.rs b/ecs/src/component/storage/graph.rs index 11160e7..d38223a 100644 --- a/ecs/src/component/storage/graph.rs +++ b/ecs/src/component/storage/graph.rs @@ -140,7 +140,7 @@ impl Graph } fn create_missing_subset_node_edges( - target_node: &ArchetypeNode, + target_node: &mut ArchetypeNode, subset_node: &mut ArchetypeNode, ) { @@ -153,6 +153,14 @@ impl Graph subset_node .get_or_insert_edges(uniq_comp_id, ArchetypeEdges::default) .add = Some(subset_node.make_add_edge(uniq_comp_id).0); + + if target_node.archetype().component_cnt() + == subset_node.archetype().component_cnt() + 1 + { + target_node + .get_or_insert_edges(uniq_comp_id, ArchetypeEdges::default) + .remove = Some(subset_node.archetype().id()); + } } fn create_missing_superset_node_edges( @@ -245,13 +253,6 @@ impl ArchetypeNode self.edges.iter() } - pub fn get_edges_mut(&mut self, component_id: Uid) -> Option<&mut ArchetypeEdges> - { - debug_assert_eq!(component_id.kind(), UidKind::Component); - - self.edges.get_mut(&component_id) - } - pub fn make_add_edge(&self, component_id: Uid) -> (ArchetypeId, Vec<Uid>) { let mut edge_comp_ids = self |