/****************************************************************************** * File - entity.h * Author - Joey Pollack * Date - 2022/05/23 (y/m/d) * Mod Date - 2022/05/23 (y/m/d) * Description - Provides functionality to work with world entities ******************************************************************************/ #ifndef LUNARIUM_ENTITY_H_ #define LUNARIUM_ENTITY_H_ #include #include #include #include namespace lunarium { class Entity { public: Entity(World& w); Entity(World& w, LUUID uuid, entt::entity handle = entt::null); // These component methods are based on methods from the Hazel engine, written by Cherno // https://github.com/TheCherno/Hazel/blob/dev/Hazel/src/Hazel/Scene/Entity.h template T& AddComponent(Args&&... args) { if (HasComponent()) { Logger::Error(LogCategory::GAME_SYSTEM, "Entity already has component!"); return GetComponent(); } T& component = mWorld.GetEntityRegistry()->emplace(mHandle, std::forward(args)...); return component; } template T& GetComponent() { if (!HasComponent()) { Logger::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); } return mWorld.GetEntityRegistry()->get(mHandle); } template bool HasComponent() { return mWorld.GetEntityRegistry()->all_of(mHandle); } template void RemoveComponent() { if (!HasComponent()) { Logger::Error(LogCategory::GAME_SYSTEM, "Entity does not have component!"); } mWorld.GetEntityRegistry()->remove(mHandle); } LUUID GetUUID() const; private: LUUID mUUID; entt::entity mHandle; World& mWorld; // The world the entity is contained within //entt::registry* mpRegistry; private: void Init(); }; } #endif // LUNARIUM_ENTITY_H_