From 7d578700747928fca0f0f1a4fae2c0cde0fe74f6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 3 Aug 2026 14:28:41 +0200 Subject: feat(engine-ecs): create component info ents for components from pairs --- engine-ecs/src/lib.rs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'engine-ecs/src/lib.rs') diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs index 039661a..fcb9a8d 100644 --- a/engine-ecs/src/lib.rs +++ b/engine-ecs/src/lib.rs @@ -1,6 +1,6 @@ #![deny(clippy::all, clippy::pedantic)] -use std::any::{Any, TypeId}; +use std::any::{Any, TypeId, type_name}; use std::borrow::Cow; use std::fmt::Debug; use std::hint::cold_path; @@ -660,6 +660,26 @@ impl World } if comp_id.is_pair() { + if let Some(pair_relation_metadata) = &component_parts.pair_relation_metadata { + Self::create_component_info_entity_if_missing( + comp_id.relation(), + pair_relation_metadata.name, + pair_relation_metadata.ty, + pair_relation_metadata.ty_id, + component_storage, + ); + } + + if let Some(pair_target_metadata) = &component_parts.pair_target_metadata { + Self::create_component_info_entity_if_missing( + comp_id.target(), + pair_target_metadata.name, + pair_target_metadata.ty, + pair_target_metadata.ty_id, + component_storage, + ); + } + continue; } @@ -702,12 +722,7 @@ impl World } } - let ComponentParts { - id: comp_info_id, - name: comp_info_name, - type_reflection: _, - data: comp_info_data, - } = ComponentInfo { + let comp_info_parts = ComponentInfo { type_reflection, name: comp_name, ty_id: type_id, @@ -715,9 +730,12 @@ impl World .into_parts(); if let Err(err) = component_storage - .add_entity_component(comp_id, (comp_info_id, comp_info_name, comp_info_data)) + .add_entity_component(comp_id, (comp_info_parts.id, comp_info_parts.name, comp_info_parts.data)) { - tracing::error!("Failed to add component {comp_info_name} to entity: {err}"); + tracing::error!( + component = %type_name::(), + "Failed to add component to entity: {err}" + ); } } -- cgit v1.2.3-18-g5258