summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-31 05:34:28 +0200
committerHampusM <hampus@hampusmat.com>2026-08-31 05:34:28 +0200
commit6c0db8d03888edddcd811166b1297ae185f2bfbe (patch)
treecfc27e0849884d6c76476994383b8b57befbd584
parent3c252d952fb3a639b84f2c0e63157e0d26862f28 (diff)
feat(engine-ecs): add whether component is a sole to component::Info
-rw-r--r--engine-ecs-macros/src/lib.rs1
-rw-r--r--engine-ecs/src/component.rs24
-rw-r--r--engine-ecs/src/lib.rs49
-rw-r--r--engine-ecs/src/pair.rs5
4 files changed, 47 insertions, 32 deletions
diff --git a/engine-ecs-macros/src/lib.rs b/engine-ecs-macros/src/lib.rs
index da9eec3..9bc829b 100644
--- a/engine-ecs-macros/src/lib.rs
+++ b/engine-ecs-macros/src/lib.rs
@@ -260,6 +260,7 @@ pub fn sole_derive(input: TokenStream) -> TokenStream
{
#ecs_path::component::Parts::builder()
.name(<Self as Sole>::name(&self))
+ .is_sole(true)
.type_reflection(<Self as Sole>::type_reflection())
.build(<Self as Sole>::id(), self)
}
diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs
index 9220ffb..cbd45e7 100644
--- a/engine-ecs/src/component.rs
+++ b/engine-ecs/src/component.rs
@@ -294,6 +294,7 @@ pub struct Parts
{
pub id: Uid,
pub name: &'static str,
+ pub is_sole: bool,
pub type_reflection: Option<&'static TypeReflection>,
pub data: Box<dyn Any>,
pub pair_relation_metadata: Option<PairMemberMetadata>,
@@ -313,6 +314,7 @@ impl Parts
pub struct PartsBuilder
{
name: &'static str,
+ is_sole: bool,
type_reflection: Option<&'static TypeReflection>,
pair_relation_metadata: Option<PairMemberMetadata>,
pair_target_metadata: Option<PairMemberMetadata>,
@@ -328,6 +330,13 @@ impl PartsBuilder
}
#[must_use]
+ pub fn is_sole(mut self, is_sole: bool) -> Self
+ {
+ self.is_sole = is_sole;
+ self
+ }
+
+ #[must_use]
pub fn type_reflection(
mut self,
type_reflection: Option<&'static TypeReflection>,
@@ -338,20 +347,15 @@ impl PartsBuilder
}
#[must_use]
- pub fn pair_relation_metadata(
- mut self,
- metadata: Option<PairMemberMetadata>,
- ) -> Self
+ pub fn pair_relation_metadata(mut self, metadata: Option<PairMemberMetadata>)
+ -> Self
{
self.pair_relation_metadata = metadata;
self
}
#[must_use]
- pub fn pair_target_metadata(
- mut self,
- metadata: Option<PairMemberMetadata>,
- ) -> Self
+ pub fn pair_target_metadata(mut self, metadata: Option<PairMemberMetadata>) -> Self
{
self.pair_target_metadata = metadata;
self
@@ -363,6 +367,7 @@ impl PartsBuilder
Parts {
id,
name: self.name,
+ is_sole: self.is_sole,
type_reflection: self.type_reflection,
data: Box::new(data),
pair_relation_metadata: self.pair_relation_metadata,
@@ -376,6 +381,7 @@ impl PartsBuilder
Parts {
id,
name: self.name,
+ is_sole: self.is_sole,
type_reflection: self.type_reflection,
data,
pair_relation_metadata: self.pair_relation_metadata,
@@ -390,6 +396,7 @@ impl Default for PartsBuilder
{
Self {
name: "(unspecified)",
+ is_sole: false,
type_reflection: None,
pair_relation_metadata: None,
pair_target_metadata: None,
@@ -404,4 +411,5 @@ pub struct Info
pub type_reflection: Option<&'static TypeReflection>,
pub ty_id: TypeId,
pub name: &'static str,
+ pub is_sole: bool,
}
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index 0d7df79..8e8cc69 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;
use std::borrow::Cow;
use std::fmt::Debug;
use std::hint::cold_path;
@@ -54,7 +54,6 @@ use crate::query::{
TermsBuilderInterface,
MAX_TERM_CNT as QUERY_MAX_TERM_CNT,
};
-use crate::reflection::Type as TypeReflection;
use crate::sole::{Single, Sole};
use crate::system::observer::Observer;
use crate::system::{
@@ -694,22 +693,28 @@ impl World
&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,
+ comp_id.relation(),
+ ComponentInfo {
+ type_reflection: pair_relation_metadata.ty,
+ ty_id: pair_relation_metadata.ty_id,
+ name: pair_relation_metadata.name,
+ is_sole: pair_relation_metadata.is_sole,
+ },
);
}
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,
+ comp_id.target(),
+ ComponentInfo {
+ type_reflection: pair_target_metadata.ty,
+ ty_id: pair_target_metadata.ty_id,
+ name: pair_target_metadata.name,
+ is_sole: pair_target_metadata.is_sole,
+ },
);
}
@@ -717,11 +722,14 @@ impl World
}
Self::create_component_info_entity_if_missing(
- comp_id,
- comp_name,
- component_parts.type_reflection,
- comp_type_id,
component_storage,
+ comp_id,
+ ComponentInfo {
+ type_reflection: component_parts.type_reflection,
+ ty_id: comp_type_id,
+ name: comp_name,
+ is_sole: component_parts.is_sole,
+ },
);
event_submitter.submit_event(
@@ -735,11 +743,9 @@ impl World
}
fn create_component_info_entity_if_missing(
- comp_id: Uid,
- comp_name: &'static str,
- type_reflection: Option<&'static TypeReflection>,
- type_id: TypeId,
component_storage: &mut ComponentStorage,
+ comp_id: Uid,
+ comp_info: ComponentInfo,
)
{
if let Some(comp_ent_archetype) = component_storage.get_entity_archetype(comp_id)
@@ -755,12 +761,7 @@ impl World
}
}
- let comp_info_parts = ComponentInfo {
- type_reflection,
- name: comp_name,
- ty_id: type_id,
- }
- .into_parts();
+ let comp_info_parts = comp_info.into_parts();
match component_storage.add_entity_component(
comp_id,
diff --git a/engine-ecs/src/pair.rs b/engine-ecs/src/pair.rs
index 98f0257..834077c 100644
--- a/engine-ecs/src/pair.rs
+++ b/engine-ecs/src/pair.rs
@@ -46,6 +46,7 @@ impl<Relation, Target> Builder<Relation, Target>
ty: NewRelation::type_reflection(),
ty_id: TypeId::of::<NewRelation>(),
name: type_name::<NewRelation>(),
+ is_sole: false,
}),
target_metadata: self.target_metadata,
}
@@ -71,6 +72,7 @@ impl<Relation, Target> Builder<Relation, Target>
ty: NewTarget::type_reflection(),
ty_id: TypeId::of::<NewTarget>(),
name: type_name::<NewTarget>(),
+ is_sole: false,
}),
}
}
@@ -103,6 +105,7 @@ impl_multiple!(
ty: NewTarget::type_reflection(),
ty_id: TypeId::of::<NewTarget>(),
name: type_name::<NewTarget>(),
+ is_sole: false,
}),
}
}
@@ -125,6 +128,7 @@ impl_multiple!(
ty: NewRelation::type_reflection(),
ty_id: TypeId::of::<NewRelation>(),
name: type_name::<NewRelation>(),
+ is_sole: false,
}),
target_metadata: self.target_metadata,
}
@@ -770,6 +774,7 @@ pub struct MemberMetadata
pub ty: Option<&'static TypeReflection>,
pub ty_id: TypeId,
pub name: &'static str,
+ pub is_sole: bool,
}
#[macro_export]