summaryrefslogtreecommitdiff
path: root/engine-ecs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs')
-rw-r--r--engine-ecs/src/entity.rs9
-rw-r--r--engine-ecs/src/tuple.rs24
2 files changed, 27 insertions, 6 deletions
diff --git a/engine-ecs/src/entity.rs b/engine-ecs/src/entity.rs
index 4e0ca52..ba85956 100644
--- a/engine-ecs/src/entity.rs
+++ b/engine-ecs/src/entity.rs
@@ -322,7 +322,14 @@ macro_rules! declare_entity {
$(#[$attr])*
$visibility static $ident: $crate::entity::Declaration =
$crate::entity::Declaration::new(|world| {
- world.spawn_with_uid(*$ident, $components);
+ use $crate::tuple::Tuple;
+
+ world.spawn_with_uid(
+ *$ident,
+ ($components).with_elem($crate::entity::Name {
+ name: concat!(module_path!(), stringify!($ident)).into()
+ })
+ );
});
)+
}
diff --git a/engine-ecs/src/tuple.rs b/engine-ecs/src/tuple.rs
index def25a0..15e1719 100644
--- a/engine-ecs/src/tuple.rs
+++ b/engine-ecs/src/tuple.rs
@@ -1,4 +1,4 @@
-use std::any::TypeId;
+use std::{any::TypeId, convert::Infallible};
use paste::paste;
use seq_macro::seq;
@@ -11,9 +11,9 @@ pub trait Tuple: sealed::Sealed
/// `(String, i32, u8)::WithElementAtEnd<Path> = (String, i32, u8, Path)`
///
/// # Important note
- /// If `Self` has 16 elements, this will be `()`. The reason for this is that the
- /// `Tuple` trait is only implemented for tuples with up to and including 16 elements.
- type WithElementAtEnd<NewElem>: Tuple;
+ /// If `Self` has 16 elements, this will be [`Infallible`]. The reason for this is
+ /// that the `Tuple` trait is only implemented for tuples with 0-16 elements.
+ type WithElementAtEnd<NewElem>;
/// `Self` without the last element.
///
@@ -26,6 +26,8 @@ pub trait Tuple: sealed::Sealed
/// Self with all elements wrapped in [`Option`].
type InOptions: Tuple;
+ fn with_elem<NewElem>(self, new_elem: NewElem) -> Self::WithElementAtEnd<NewElem>;
+
/// Pops the last element from this tuple, returning the new tuple and the popped
/// element.
fn pop_last(self) -> (Self::WithoutLastElement, Self::LastElement);
@@ -126,6 +128,11 @@ macro_rules! impl_tuple_traits {
type InOptions = (#(Option<Elem~I>,)*);
+ fn with_elem<NewElem>(self, new_elem: NewElem) -> Self::WithElementAtEnd<NewElem>
+ {
+ (#(self.I,)* new_elem,)
+ }
+
fn pop_last(self) -> (Self::WithoutLastElement, Self::LastElement)
{
(
@@ -186,7 +193,7 @@ seq!(N in 0..16 {
seq!(I in 0..16 {
impl<#(Elem~I,)*> Tuple for (#(Elem~I,)*)
{
- type WithElementAtEnd<NewElem> = ();
+ type WithElementAtEnd<NewElem> = Infallible;
type WithoutLastElement = all_except_last!(start #(Elem~I)*);
@@ -194,6 +201,13 @@ seq!(I in 0..16 {
type InOptions = (#(Option<Elem~I>,)*);
+ fn with_elem<NewElem>(self, _: NewElem) -> Self::WithElementAtEnd<NewElem>
+ {
+ const {
+ panic!("Cannot add element to tuple with 16 elements");
+ };
+ }
+
fn pop_last(self) -> (Self::WithoutLastElement, Self::LastElement)
{
(