2#include <entt/entt.hpp>
13 explicit SceneID(
const uint32_t
id) : m_OwningSceneID(id) {}
17 uint32_t m_OwningSceneID;
29 Entity(entt::handle handle) : m_EntityHandle(handle) {}
38 template<
typename T,
typename... Args>
40 return m_EntityHandle.emplace<T>(std::forward<Args>(args)...);
50 template<
typename T,
typename... Args>
52 return m_EntityHandle.replace<T>(std::forward<Args>(args)...);
62 template<
typename T,
typename... Args>
64 return m_EntityHandle.emplace_or_replace<T>(std::forward<Args>(args)...);
73 template<
typename... T>
77 std::ostringstream oss;
82 return m_EntityHandle.get<T...>();
91 template<
typename... T>
95 std::ostringstream oss;
101 return m_EntityHandle.get<
const T...>();
111 template<
typename T,
typename... Args>
113 return m_EntityHandle.get_or_emplace<T>(std::forward<Args>(args)...);
121 template<
typename... T>
123 return m_EntityHandle.all_of<T...>();
132 template<
typename... T>
134 return m_EntityHandle.remove<T...>();
143 template<
typename... T>
145 m_EntityHandle.erase<T...>();
148 explicit operator bool()
const {
return static_cast<bool>(m_EntityHandle); }
151 return m_EntityHandle == other.m_EntityHandle;
154 return m_EntityHandle != other.m_EntityHandle;
162 return static_cast<bool>(m_EntityHandle);
189 [[nodiscard]] uint32_t
GetID()
const {
190 return entt::to_integral(m_EntityHandle.entity());
198 return entt::to_version(m_EntityHandle.entity());
222 [[nodiscard]] std::string
GetDebugData(
bool showUUID =
false)
const;
241 [[nodiscard]] std::expected<Entity, Core::CoriError<>>
GetParent()
const;
254 [[nodiscard]] std::expected<Entity, Core::CoriError<>>
FindChildByName(
const char* name)
const;
261 [[nodiscard]] std::expected<Entity, Core::CoriError<>>
FindChildByName(
const std::string_view name)
const;
268 [[nodiscard]] std::expected<Entity, Core::CoriError<>>
FindChildByName(
const std::string& name)
const;
280 [[nodiscard]] entt::entity
GetRawEntity()
const {
return m_EntityHandle.entity(); }
287 [[nodiscard]] entt::handle
GetRawHandle()
const {
return m_EntityHandle; }
298 [[nodiscard]] std::string_view
GetName()
const;
304 void SetName(
const std::string& name);
315 static void DrawHierarchyRecursive(
const Entity& entity,
const std::string& prefix,
const bool isLast);
317 entt::handle m_EntityHandle;
#define CORI_CLEAN_TYPE_NAME(tn)
#define CORI_CORE_FATAL_TAGGED(...)
Custom error class mainly used in std::expected.
Entities are the essential part of WorldSystem.
void SetActive(const bool state)
Changes the activity state of the entity.
std::expected< std::vector< Entity >, Core::CoriError<> > GetSiblings() const
Creates and returns a vector containing all entity siblings.
void UnlinkFromParent()
Unlinks the entity from its parent if it has one.
bool IsValid() const
Checks if the actual entity behind this handle is valid.
bool IsActiveGlobally() const
Checks if the entity is active locally (doesn't have InactiveGloballyFlag), just a convenience functi...
bool operator==(const Entity &other) const
void PrintHierarchy() const
Prints the full entity hierarchy tree in the console.
std::string_view GetName() const
Retrieves the name of the entity.
entt::handle GetRawHandle() const
Gets a raw entt::handle if you need to interact with entt directly.
std::expected< std::vector< Entity >, Core::CoriError<> > GetChildren() const
Creates and returns a vector containing all entity children (does not include grandchildren and so on...
T & GetOrAddComponent(Args &&... args)
Retries or adds a component to the entity.
void DestroyChildren()
Destroys all children (and they grandchildren) that the entity has.
bool operator!=(const Entity &other) const
std::expected< Entity, Core::CoriError<> > GetParent() const
Retries the parent entity of the entity if any.
std::expected< void, Core::CoriError<> > SetParent(Entity parent)
Links the entity to a parent entity.
uint32_t GetVersion() const
Gets the entity version.
bool HasComponents() const
Checks if the entity has all the specified components.
void EraseComponents()
Erases components from the entity without checking if the entity actually have them.
T & ReplaceComponent(Args &&... args)
Replaces the component with a newly created one.
T & AddComponent(Args &&... args)
Adds a component to the entity.
uint64_t GetEUID() const
Gets the EUID (entity unique ID). A combination of entity ID and version, it is unique for every enti...
std::string GetDebugData(bool showUUID=false) const
Gets the debuting string for logging.
decltype(auto) GetComponents()
Retries the references to the requested components of the entity.
bool IsActiveLocally() const
Checks if the entity is active locally (doesn't have InactiveLocallyFlag), just a convenience functio...
uint32_t GetID() const
Gets the entity ID.
uint32_t GetOwnerSceneID() const
Retries the ID of the owner scene. You can get the actual SceneHandle by providing SceneManager with ...
entt::entity GetRawEntity() const
Gets a raw entt::entity if you need to interact with entt directly.
T & AddOrReplaceComponent(Args &&... args)
Adds a component to the entity, or replaces it if the entity already has this component.
entt::handle::size_type RemoveComponents()
Removes components from the entity if entity has them.
Entity(entt::handle handle)
void SetName(const std::string &name)
Changes the entity name.
decltype(auto) GetComponents() const
Retries the references to the requested components of the entity. Const variant.
void UpdateInactivityFlagsRecursive(entt::entity parent, bool parentIsActive)
std::expected< Entity, Core::CoriError<> > FindChildByName(const char *name) const
Finds a children entity by name.
Anything connected to WorldSystem (ECS) is in this namespace.
SceneID(const uint32_t id)