82 m[componentID] =
true;
98 template<
typename C>
constexpr bool isComponent = std::is_base_of<AbstractComponent, C>::value;
108 template<
typename T,
typename C>
using ifComponent =
typename std::enable_if<isComponent<C>,
T>::type;
123 static_assert(std::is_final_v<C>,
"Components must be final!");
203 template<
typename T1,
typename T2,
typename...
Ts>
214 template<
typename T1,
typename T2,
typename...
Ts>
226 template<
typename T1,
typename T2,
typename...
Ts>
233 template<
typename T1,
typename T2,
typename...
Ts>
348 static_assert(
areComponents<
Cs...>,
"All parameters in Cs must be components.");
353 template<CComponent C>
static inline constexpr bool includes = (std::is_same_v<C, Cs> || ...);
358 return (Cs::mask | ...);
369 template<
template<
typename...>
typename T>
using Apply =
T<
Cs...>;
376 template<CComponent C>
static inline constexpr bool includes =
false;
385 template<
template<
typename...>
typename T>
using Apply =
T<>;
565 if constexpr(std::is_copy_assignable_v<C>) {
566 static_cast<C&
>(component) = value.template
cref<C>();
573 if constexpr(std::is_copy_assignable_v<C>) {
574 static_cast<C&
>(component) = std::move(value).template
rref<C>();
596#define CE_EXTERN_COMPONENT_BASE(T, EXTERN) \
597 EXTERN template struct ::CeresEngine::Component<T>; \
598 EXTERN template class ::CeresEngine::TComponentType<T>; \
599 EXTERN template class ::CeresEngine::ComponentStore<T>
600#define CE_EXTERN_COMPONENT(T) CE_EXTERN_COMPONENT_BASE(T, extern);
601#define CE_EXTERN_COMPONENT_IMPL(T) CE_EXTERN_COMPONENT_BASE(T, );
605 size_t operator()(
const CeresEngine::Component<C>& component)
const {
return std::hash<C>{}(
static_cast<const C&
>(component)); }
608template<>
struct std::hash<
CeresEngine::ComponentType> {
612template<
typename C>
struct std::hash<
CeresEngine::TComponentType<C>> : std::hash<CeresEngine::ComponentType> {};
#define CE_REFLECTABLE_CLASS
Definition IReflectable.hpp:38
#define CE_FORCE_INLINE
Definition Macros.hpp:367
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
Represents a reflected property from metadata defined by the class.
Definition Class.hpp:176
A object that manages a set of components masks.
Definition Component.hpp:238
static constexpr ComponentMask emptyComponentMask
A default empty component mask used when returning an empty mask by reference.
Definition Component.hpp:245
const ComponentMask & reset(const EntityIndex index) noexcept
Removes all bits in the component mask of the given index.
Definition Component.hpp:295
std::size_t getSize() const noexcept
Definition Component.hpp:330
bool has(const EntityIndex index, const ComponentMask &mask) const noexcept
Checks if the entity at the given index contains all components in the given mask.
Definition Component.hpp:268
Vector< ComponentMask > mComponentMasks
A vector that stores the component masks indexed by an integer index.
Definition Component.hpp:241
const ComponentMask & remove(const EntityIndex index, const ComponentMask &mask) noexcept
Removes a new set of components in the given mask from the given index.
Definition Component.hpp:321
const ComponentMask & get(const EntityIndex index) const noexcept
Gets the current component mask for the given index.
Definition Component.hpp:252
const ComponentMask & add(const EntityIndex index, const ComponentMask &mask) noexcept
Adds a new set of components in the given mask to the given index.
Definition Component.hpp:305
const ComponentMask & set(const EntityIndex index, const ComponentMask &mask) noexcept
Sets a mask for the given index.
Definition Component.hpp:278
A type that describes and provides type-erased operations on a component.
Definition Component.hpp:456
ComponentType & operator=(const ComponentType &)=delete
virtual const Class * getAccessorClass() const noexcept=0
Returns the component accessor meta class.
virtual void emitComponentRemoved(const Entity &entity) const =0
static const TComponentType< C > & get() noexcept
The type instance for a component of the C.
Definition Component.hpp:587
const ComponentMask componentMask
Definition Component.hpp:462
virtual void setAny(AbstractComponent &component, const Box &any) const noexcept=0
friend bool operator!=(const ComponentType &lhs, const ComponentType &rhs) noexcept
Compares two ComponentType instances for inequality.
Definition Component.hpp:517
ComponentType & operator=(ComponentType &&)=delete
ComponentType(const ComponentType &)=delete
ComponentType(const ComponentID componentID)
Definition Component.hpp:465
virtual Type getType() const noexcept=0
Returns the meta type of the component.
const ComponentID componentID
The component type ID.
Definition Component.hpp:460
static ComponentID nextComponentID
The next component ID to be statically allocated by the compiler.
Definition Component.hpp:480
virtual Type getAccessorType() const noexcept=0
Returns the component accessor meta type.
virtual const Class * getClass() const noexcept=0
Returns the meta class of the component.
ComponentType(ComponentType &&)=delete
virtual void emitComponentAdded(const Entity &entity) const =0
virtual Box getAny(AbstractComponent &component) const noexcept=0
The base entity class.
Definition Entity.hpp:41
An implementation of the ComponentType interface that implements type-erased operations for component...
Definition Component.hpp:529
void setAny(AbstractComponent &component, const Box &value) const noexcept final
Definition Component.hpp:564
void emitComponentAdded(const Entity &entity) const final
Box getAny(AbstractComponent &component) const noexcept final
Definition Component.hpp:558
static ComponentID getComponentID() noexcept
Definition Component.hpp:539
TComponentType()
Creates a new instance of a component type object for the given C component type.
Definition Component.hpp:535
Type getAccessorType() const noexcept final
Returns the component accessor meta type.
Definition Component.hpp:555
Type getType() const noexcept final
Returns the meta type of the component.
Definition Component.hpp:549
void setAny(AbstractComponent &component, Box &&value) const noexcept final
Definition Component.hpp:572
Box getAny(const AbstractComponent &component) const noexcept final
Definition Component.hpp:561
void emitComponentRemoved(const Entity &entity) const final
const Class * getClass() const noexcept final
Returns the meta class of the component.
Definition Component.hpp:546
const Class * getAccessorClass() const noexcept final
Returns the component accessor meta class.
Definition Component.hpp:552
Tuple is a fixed-size collection of heterogeneous values.
Definition Tuple.hpp:15
Represents a reflected C++ type. Can be used to get metadata from a C++ type.
Definition Type.hpp:32
const Class * getClass() const noexcept
Gets the Class instance associated with the type.
Definition Component.hpp:117
Definition Concepts.hpp:43
Definition Application.hpp:19
constexpr bool isComponent
A trait that checks if the type C is a component.
Definition Component.hpp:98
typename std::enable_if< areComponents< Cs... >, T >::type ifComponents
If the types Cs are all components (as defined by areComponents<Cs>), this type is aliased to T.
Definition Component.hpp:114
typename std::enable_if< isComponent< C >, T >::type ifComponent
If the type C is a component (as defined by isComponent<C>), this type is aliased to T.
Definition Component.hpp:108
ComponentMask buildComponentMask()
Definition Component.hpp:340
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr void checkComponent()
A trait that checks if the type C is a valid component type.
Definition Component.hpp:121
constexpr bool areComponents
A trait that checks if the types Cs are all components.
Definition Component.hpp:102
std::bitset< 128 > ComponentMask
A bitset that represents a components mask (i.e. a set of components)
Definition Component.hpp:35
sfl::small_vector< T, N, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > SmallVector
SmallVector is a sequence container similar to Vector.
Definition SmallVector.hpp:31
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
unsigned int ComponentID
A numeric type that represents a component.
Definition Component.hpp:32
UInt32 EntityIndex
Definition EntityID.hpp:22
A abstract class that provides a trait that allows checking for component implementations.
Definition Component.hpp:39
virtual ~AbstractComponent()=default
Defaulted virtual destructor.
virtual const ComponentType & getComponentType() const noexcept=0
Gets the component type.
An abstract type that represents a generic component listener.
Definition Component.hpp:390
virtual ~AbstractComponentListener()=default
Destroys the AbstractComponentListener instance.
virtual ComponentMask mask() const noexcept=0
The component criteria a entity must match for consideration of a callback.
virtual void componentsAdded(const Entity &entity) noexcept=0
A notification dispatched by the SystemManager to a system.
virtual void componentsRemoved(const Entity &entity) noexcept=0
A notification dispatched by the SystemManager to a system.
virtual void entityDirtied(const Entity &entity, const EntityChangeSet &changeSet) noexcept
A notification dispatched by the SystemManager to a system.
Definition Component.hpp:417
An accessor class that implements high-level access to an entity that has the given component.
Definition Component.hpp:175
Tuple< const T1 &, const T2 &, const Ts &... > get(const T1 C::*ptr1, const T2 C::*ptr2, const Ts C::*... ptrs) const
Accesses an element from an existing Component.
const Entity & entity
Definition Component.hpp:177
TC C
Definition Component.hpp:184
auto get(T C::*ptr)
Accesses an element from an existing Component.
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > get(T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptrs)
Accesses an element from an existing Component.
const T & get(const T C::*ptr) const
Accesses an element from an existing Component.
Accessor(const Entity &entity)
Definition Component.hpp:181
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > mutate(MutatorFunc &&func, T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptr)
auto mutate(T C::*ptr)
Accesses an element from an existing Component.
const T & read(const T C::*ptr) const
Accesses an element from an existing Component.
decltype(auto) mutate(MutatorFunc &&func, T C::*ptr)
Accesses an element from an existing Component.
Tuple< const T1 &, const T2 &, const Ts &... > read(const T1 C::*ptr1, const T2 C::*ptr2, const Ts C::*... ptrs) const
TODO Write docs.
Tuple< ComponentFieldMutator< T1, C >, ComponentFieldMutator< T2, C >, ComponentFieldMutator< Ts, C >... > mutate(T1 C::*ptr1, T2 C::*ptr2, Ts C::*... ptrs)
TODO Write docs.
A structure that encodes a change to a single component field.
Definition Component.hpp:442
const ClassProperty * property
The component field whose value has been changed.
Definition Component.hpp:444
A structure that encodes a set of changes done to a component.
Definition Component.hpp:448
SmallVector< ComponentChange, 10 > changes
A set of changes done to a component.
Definition Component.hpp:451
Definition Forward.hpp:28
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
const ComponentType & getComponentType() const noexcept final
Gets the component type.
Definition Component.hpp:90
static ComponentID getComponentID() noexcept
Definition Component.hpp:592
static const ComponentType & componentType
Gets the component type.
Definition Component.hpp:87
The ComponentListener is a EntityManager listener type that gets notified whenever an entity matching...
Definition Component.hpp:436
ComponentMask mask() const noexcept final
The component criteria a entity must match for consideration of a callback.
Definition Component.hpp:438
static ComponentMask getComponentMask() noexcept
A trait that contains the minimum component mask for that includes all components in the set.
Definition Component.hpp:380
T<> Apply
Definition Component.hpp:385
Definition Component.hpp:346
static ComponentMask getComponentMask() noexcept
A trait that contains the minimum component mask for that includes all components in the set.
Definition Component.hpp:357
static constexpr bool includes
Checks if all Cs are valid component types.
Definition Component.hpp:353
T< Cs... > Apply
Applies all components Cs into the template type T as T<Cs...>.
Definition Component.hpp:369
Definition Entity.hpp:452