32 template<CComponent...
Components>
class EntityObject;
85 bool valid() const noexcept;
97 template<typename Block> [[nodiscard]]
Entity copy(Block&& block) const;
101 void destroy() const;
116 template<
CComponent C, typename... Args> inline C& add(Args&&... args) const noexcept(
std::is_nothrow_constructible_v<C, Args...>);
126 template<
CComponent C, typename Block, typename... Args>
127 inline C& addWith(Block&& block, Args&&... args) const noexcept(
std::is_nothrow_constructible_v<C, Args...>);
135 template<
CComponent C, typename... Args> inline C& set(Args&&... args) const noexcept(
std::is_nothrow_constructible_v<C, Args...>);
143 template<
CComponent C> inline
void remove() const noexcept(
std::is_nothrow_destructible_v<C>);
155 template<
CComponent C> [[nodiscard]] inline C& get() const noexcept;
175 template<
CComponent C> [[nodiscard]] inline C& getOr() const noexcept(
std::is_nothrow_constructible_v<C>);
195 template<
CComponent C> [[nodiscard]] inline C* getIf() const noexcept;
226 bool empty() const noexcept;
233 template<typename E> [[nodiscard]] inline
bool is() const noexcept;
238 template<typename E> [[nodiscard]] inline E as() const;
243 template<typename... Cs> [[nodiscard]] inline
EntityObject<Cs...> having() const;
250 template<typename E> [[nodiscard]] inline E being() const noexcept;
263 template<typename P> [[nodiscard]] P getParent() const noexcept;
277 template<typename T> [[nodiscard]]
Generator<T> getChildren() const noexcept;
300 template<
CEntityEvent E, typename... Args> inline
void emit(Args&&... args) const;
322 template<
CEntityAction A, typename... Args> [[nodiscard]] inline
bool canAct(Args&&... args) const;
329 template<
CEntityAction A, typename... Args> inline decltype(auto) act(Args&&... args) const;
371 [[nodiscard]] inline explicit operator
bool() const noexcept;
409 friend
bool operator==(const
Entity& a,
std::nullptr_t b) noexcept;
415 friend
bool operator!=(const
Entity& a,
std::nullptr_t b) noexcept;
421 friend
std::ostream& operator<<(
std::ostream& os, const
Entity& entity);
426 [[nodiscard]]
Entity operator[](const
EntityIndex childIndex)
const {
return getChildren()[childIndex]; }
431 for(
Entity entity : getChildren()) {
432 if(entity.getName() == childName) {
633 explicit AccessHelper(
EntityObject& entity) : Components::Accessor(entity)... {}
638 decltype(
auto) operator->() && {
return this; }
736 sizeof(
typename E::Type) ==
sizeof(
E);
747 template<
typename O,
typename T =
void>
using ifEntityObject =
typename std::enable_if<isEntityObject<O>,
T>::type;
763 template<CEntityObject EO>
static inline constexpr bool includes = (std::is_same_v<EO, EOs> || ...);
774 template<CEntityObject EO>
static inline constexpr bool includes =
false;
782 template<
typename E>
static constexpr E entity_cast(
const Entity& entity) {
return entity.
as<
E>(); }
784#define CE_ENTITY_OBJECT_HASH(T) \
785 template<> struct std::hash<T> : public std::hash<CeresEngine::Entity> {}
789#include "Component.inl"
#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
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
A type that describes and provides type-erased operations on a component.
Definition Component.hpp:456
The base entity class.
Definition Entity.hpp:41
friend E unsafeCastEntityObject(EntityManager &entityManager, EntityID entityID) noexcept
EntityID getEntityID() const noexcept
EntityID entityID
The entity ID.
Definition Entity.hpp:49
E as() const
Converts the entity handle type into a E entity object.
EntityManager * entityManager
The owning entity manager.
Definition Entity.hpp:46
Entity operator[](const StringView childName) const
Definition Entity.hpp:430
Definition EntityManager.hpp:49
A type-safe entity type.
Definition Entity.hpp:538
EntityObject(const EntityObject &other) noexcept=default
Creates a new entity by copying another.
EntityObject & operator=(const EntityObject &other) noexcept=default
Assing the contents of the entity by copying the contents of another.
EntityObject(EntityManager &entityManager, EntityID entityID)
Creates a new entity object attached to a entity manager.
EntityObject(std::nullptr_t) noexcept
Creates a new empty entity.
static constexpr bool includes
Checks if all Components are valid component types.
Definition Entity.hpp:553
friend std::ostream & operator<<(std::ostream &os, const EntityObject< ACs... > &entity)
Compares two entities for equality.
EntityObject()=default
Creates a new entity object.
bool compareHash(UInt64 &hash) const
Definition Entity.hpp:648
static EntityObject make(Entity entity)
Makes the entity an entity object by adding any missing component and casting it.
UInt64 getHash() const
Computes a hash that uniquely represents the entity object.
Definition Entity.hpp:646
static const _MaskObject mask
Definition Entity.hpp:560
A generator represents a coroutine type that produces a sequence of values of type T,...
Definition Generator.hpp:50
Tuple is a fixed-size collection of heterogeneous values.
Definition Tuple.hpp:15
Connection class.
Definition Event.hpp:44
Definition Component.hpp:117
Definition Entity.hpp:750
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
constexpr void checkEntityObject()
A trait that checks if the type E is a valid entity object type.
Definition Entity.hpp:754
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr bool areEntityObjects
A trait that checks if the types Es are all entity objects.
Definition Entity.hpp:740
constexpr bool areComponents
A trait that checks if the types Cs are all components.
Definition Component.hpp:102
constexpr bool isEntityObject
A trait that checks if the type E is a entity object.
Definition Entity.hpp:735
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
typename std::enable_if< isEntityObject< O >, T >::type ifEntityObject
If the type E is a entity object (as defined by isEntityObject<S>), this type is aliased to T.
Definition Entity.hpp:747
auto parent(const Entity &parent)
Sets the entity parent.
Definition Helpers.hpp:52
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
UInt32 EntityIndex
Definition EntityID.hpp:22
A abstract class that provides a trait that allows checking for component implementations.
Definition Component.hpp:39
An event that gets dispatched when a new component of type C gets added to an entity.
Definition Entity.hpp:493
A structure that encodes a set of changes done to a component.
Definition Component.hpp:448
Definition Forward.hpp:28
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
An event that gets dispatched when a component of type C gets removed from an entity.
Definition Entity.hpp:498
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
A structure that encodes a change to an entity field.
Definition Entity.hpp:443
ComponentChangeSet change
A structure that describes a set of changes to an entity component field.
Definition Entity.hpp:449
const ComponentType * componentType
The component.
Definition Entity.hpp:445
Definition Entity.hpp:452
SmallVector< EntityChange, 3 > changes
Definition Entity.hpp:453
An event that gets dispatched when an entity has been created.
Definition Entity.hpp:457
An event that gets dispatched when an entity has been destroyed.
Definition Entity.hpp:460
An event that gets dispatched whenever the entity is marked as dirty.
Definition Entity.hpp:501
EntityDirty(const EntityChangeSet &changeSet)
Definition Entity.hpp:504
EntityChangeSet changeSet
Definition Entity.hpp:502
A template class that wraps a event.
Definition Event.hpp:43
Definition EntityID.hpp:25
An event that gets dispatched when an entity name is changed.
Definition Entity.hpp:477
StringView newName
The entity new name entity.
Definition Entity.hpp:479
StringView oldName
The entity old name entity.
Definition Entity.hpp:482
EntityNameChanged(const StringView newName, const StringView oldName)
Creates a new EntityNameChanged event.
Definition Entity.hpp:487
A trait that contains the minimum necessary component mask for an entity to be an entity object of th...
Definition Entity.hpp:557
Definition Entity.hpp:756
static constexpr bool includes
Checks if all EOs are valid entity object types.
Definition Entity.hpp:763
static const ComponentMask mask
A trait that contains the minimum component mask for that includes all components for entity objects ...
Definition Entity.hpp:767
Definition Entity.hpp:722
static constexpr bool isEntityObjectType
A trait that checks if the type E is a entity object.
Definition Entity.hpp:724
An event that gets dispatched when an entity parent is changed.
Definition Entity.hpp:463
EntityParentChanged(const Entity newParent, const Entity oldParent)
Creates a new EntityParentChanged event.
Definition Entity.hpp:473
Entity newParent
The entity new parent entity.
Definition Entity.hpp:465
Entity oldParent
The entity old parent entity.
Definition Entity.hpp:468