light/modules/engine/include/engine/scene/entity.hpp

61 lines
1 KiB
C++
Raw Normal View History

2022-03-08 21:19:19 +03:30
#pragma once
2025-07-05 13:28:41 +03:30
#include <engine/scene/components/uuid.hpp>
#include <engine/scene/scene.hpp>
2022-03-08 21:19:19 +03:30
#include <entt/entt.hpp>
namespace Light {
class Entity
{
public:
2025-07-06 16:52:50 +03:30
Entity(entt::entity handle = entt::null, Scene *scene = nullptr);
template<typename t, typename... Args>
2025-07-06 14:02:50 +03:30
auto add_component(Args &&...args) -> t &
2022-03-08 21:19:19 +03:30
{
return m_scene->m_registry.emplace<t>(m_handle, std::forward<Args>(args)...);
2022-03-08 21:19:19 +03:30
}
template<typename t>
2025-07-06 14:02:50 +03:30
auto get_component() -> t &
2022-03-08 21:19:19 +03:30
{
return m_scene->m_registry.get<t>(m_handle);
2022-03-08 21:19:19 +03:30
}
template<typename t>
2025-07-06 14:02:50 +03:30
auto has_component() -> bool
2022-03-08 21:19:19 +03:30
{
return m_scene->m_registry.any_of<t>(m_handle);
2022-03-08 21:19:19 +03:30
}
template<typename t>
2025-07-06 14:02:50 +03:30
void remove_component()
2022-03-08 21:19:19 +03:30
{
m_scene->m_registry.remove<t>(m_handle);
2022-03-08 21:19:19 +03:30
}
2025-07-06 14:02:50 +03:30
auto get_uuid() -> uint64_t
2025-07-05 13:28:41 +03:30
{
2025-07-06 14:02:50 +03:30
return get_component<UUIDComponent>().uuid;
2025-07-05 13:28:41 +03:30
}
2022-03-08 21:19:19 +03:30
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto is_valid() const -> bool
2025-07-05 13:28:41 +03:30
{
return m_handle != entt::null && m_scene != nullptr;
2025-07-05 13:28:41 +03:30
}
2022-03-08 21:19:19 +03:30
2025-07-05 13:28:41 +03:30
operator uint32_t()
{
return (uint32_t)m_handle;
2025-07-05 13:28:41 +03:30
}
2025-07-05 16:07:51 +03:30
private:
entt::entity m_handle;
2025-07-06 14:02:50 +03:30
2025-07-05 16:07:51 +03:30
Scene *m_scene;
2022-03-08 21:19:19 +03:30
};
2025-07-05 13:28:41 +03:30
} // namespace Light