#ifndef ENTITY_H #define ENTITY_H #include // uint32_t, size_t #include // std::shared_ptr, std::weak_ptr #include // std::forward #include "entt/entity/registry.hpp" // ent::entity, entt::registry #include "inferno/assertions.h" namespace Inferno { class Entity { public: Entity(const std::shared_ptr& registry); Entity(const std::shared_ptr& registry, entt::entity handle); Entity(const std::shared_ptr& registry, uint32_t handle); void expired() const; void valid() const; template [[nodiscard]] bool has() const { valid(); return m_registry.lock()->has(m_entity); } template [[nodiscard]] bool any() const { valid(); return m_registry.lock()->any(m_entity); } template T& add(P&&... parameters) const { valid(); return m_registry.lock()->emplace_or_replace(m_entity, std::forward

(parameters)...); }; template size_t remove() const { valid(); return m_registry.lock()->remove_if_exists(m_entity); } template T& get(P&&... parameters) const { valid(); return m_registry.lock()->get_or_emplace(m_entity, std::forward

(parameters)...); } // Casts inline operator bool() const { return m_entity != entt::null; } inline operator entt::entity() const { return m_entity; } inline operator uint32_t() const { return static_cast(m_entity); } // Functor() inline uint32_t operator ()() const { return static_cast(m_entity); } private: entt::entity m_entity = entt::null; std::weak_ptr m_registry; }; // ---------------------------------------- const LogStream& operator<<(const LogStream& stream, entt::entity handle); } #endif // ENTITY_H