#[macro_export]
macro_rules! component {
($(#[$outer:meta])* $vis: vis $name: ident( $obj: ident ): $ty: ty $(=> [$($metadata: ty),*])?, $($rest:tt)*) => {
#[allow(dead_code)]
$(#[$outer])*
$vis fn $name($obj: $crate::Entity) -> $crate::Component<$ty> {
use $crate::entity::EntityKind;
use $crate::relation::RelationExt;
static COMPONENT_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> = $crate::component_vtable!($name: $ty $(=> [$($metadata),*])?);
$crate::Component::static_init(&COMPONENT_ID, EntityKind::COMPONENT, VTABLE).of($obj)
}
$crate::component!{ $($rest)* }
};
($(#[$outer:meta])* $vis: vis $name: ident: $ty: ty $(=> [$($metadata: ty),*])?, $($rest:tt)*) => {
$(#[$outer])*
$vis fn $name() -> $crate::Component<$ty> {
use $crate::entity::EntityKind;
static COMPONENT_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> = $crate::component_vtable!($name: $ty $(=> [$($metadata),*])?);
$crate::Component::static_init(&COMPONENT_ID, EntityKind::COMPONENT, VTABLE)
}
$crate::component!{ $($rest)* }
};
($(#[$outer:meta])* $vis: vis $name: ident, $($rest:tt)*) => {
$(#[$outer])*
$vis fn $name() -> $crate::Entity {
static ENTITY_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
$crate::Entity::static_init(&ENTITY_ID, $crate::entity::EntityKind::empty())
}
$crate::component!{ $($rest)* }
};
() => {}
}
#[macro_export]
macro_rules! component_vtable {
($name:tt: $ty: ty $(=> [$($metadata: ty),*])?) => {
{
fn meta(_desc: $crate::component::ComponentDesc) -> $crate::buffer::ComponentBuffer {
let mut _buffer = $crate::buffer::ComponentBuffer::new();
<$crate::metadata::Name as $crate::metadata::Metadata<$ty>>::attach(_desc, &mut _buffer);
<$crate::Component<$ty> as $crate::metadata::Metadata<$ty>>::attach(_desc, &mut _buffer);
$(
$(
<$metadata as $crate::metadata::Metadata::<$ty>>::attach(_desc, &mut _buffer);
)*
)*
_buffer
}
static VTABLE: $crate::vtable::ComponentVTable<$ty> =
$crate::vtable::ComponentVTable::new(stringify!($name), $crate::vtable::LazyComponentBuffer::new(meta));
&VTABLE
}
};
}
#[cfg(feature = "puffin")]
macro_rules! profile_function {
($($tt: tt)*) => (
puffin::profile_function!($($tt)*);
)
}
#[cfg(not(feature = "puffin"))]
macro_rules! profile_function {
($($tt: tt)*) => {};
}
#[cfg(feature = "puffin")]
macro_rules! profile_scope {
($($tt: tt)*) => (
puffin::profile_scope!($($tt)*);
)
}
#[cfg(not(feature = "puffin"))]
macro_rules! profile_scope {
($($tt: tt)*) => {};
}