summaryrefslogtreecommitdiff
path: root/ecs/src/component
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-03-18 14:35:11 +0100
committerHampusM <hampus@hampusmat.com>2025-03-18 14:35:11 +0100
commitc1cf1b779e66e985774dad29867a57733947b0e8 (patch)
treefdee6b1aeb24b8f5fdb645dbd2e422ef3cba719f /ecs/src/component
parent7a7d3a350b22b5555c27debff6fee4fc6100fa38 (diff)
refactor(ecs): remove Component::self_id method
Diffstat (limited to 'ecs/src/component')
-rw-r--r--ecs/src/component/storage.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs
index f2306b7..5b7b101 100644
--- a/ecs/src/component/storage.rs
+++ b/ecs/src/component/storage.rs
@@ -138,9 +138,11 @@ impl Storage
pub fn add_entity_component(
&mut self,
entity_uid: Uid,
- component: Box<dyn Component>,
+ component: (Uid, Box<dyn Component>),
) -> Result<(), Error>
{
+ let (component_id, component) = component;
+
debug_assert!(
!component.self_is_optional(),
"Adding a optional component to a entity is not supported"
@@ -159,16 +161,16 @@ impl Storage
if archetype_node
.archetype()
- .has_component_with_id(component.self_id())
+ .has_component_with_id(component_id)
{
return Err(Error::ComponentAlreadyInEntity {
entity: entity_uid,
- component: component.self_id(),
+ component: component_id,
});
}
let add_edge_archetype_id = archetype_node
- .get_or_insert_edges(component.self_id(), ArchetypeEdges::default)
+ .get_or_insert_edges(component_id, ArchetypeEdges::default)
.add
.unwrap_or_else(|| {
let archetype_node = self
@@ -177,10 +179,10 @@ impl Storage
.expect("Archetype should exist");
let (add_edge_id, add_edge_comp_ids) =
- archetype_node.make_add_edge(component.self_id());
+ archetype_node.make_add_edge(component_id);
archetype_node
- .get_edges_mut(component.self_id())
+ .get_edges_mut(component_id)
.expect("Edges for component in archetype should exist")
.add = Some(add_edge_id);
@@ -198,7 +200,7 @@ impl Storage
.expect("Add edge archetype should exist");
let add_edge_archetype_edges = add_edge_archetype_node
- .get_or_insert_edges(component.self_id(), ArchetypeEdges::default);
+ .get_or_insert_edges(component_id, ArchetypeEdges::default);
add_edge_archetype_edges.remove = Some(archetype_id);
}
@@ -220,10 +222,13 @@ impl Storage
.archetype_mut();
let component_index = add_edge_archetype
- .get_index_for_component(component.self_id())
+ .get_index_for_component(component_id)
.expect("Archetype should have index for component");
- entity.components.insert(component_index, component.into());
+ entity.components.insert(
+ component_index,
+ EntityComponent::new(component_id, component),
+ );
add_edge_archetype.push_entity(entity);