fix: entity works

This commit is contained in:
2025-10-22 16:14:20 +02:00
parent 4798c52e51
commit 37d35f990d
5 changed files with 26 additions and 12 deletions

View File

@ -1,14 +1,13 @@
#pragma once
#include <entt/entt.hpp>
#include <memory>
#include "engine/export.h"
namespace Engine {
class Entity;
class Scene {
private:
class ENGINE_API Scene {
friend class Entity;
public:
Scene() = default;
@ -19,25 +18,32 @@ private:
friend class Renderer;
};
class Entity {
class ENGINE_API Entity {
public:
Entity() = default;
Entity(entt::entity entity, Scene* scene) : m_entity(entity), m_scene(scene) {}
Entity(const Entity& other) = default;
template<typename Type, typename... Args>
inline auto AddComponent(Args &&...args) {
auto AddComponent(Args &&...args) {
assert(this->m_entity != entt::null && "Entity is empty");
assert(this->m_scene != nullptr && "Scene has not been assigned to the entity");
return m_scene->m_registry.emplace<Type>(m_entity, std::forward<Args>(args)...);
}
template<typename Type>
[[nodiscard]] inline auto GetComponent() {
[[nodiscard]] auto GetComponent() const {
assert(this->m_entity != entt::null && "Entity is empty");
assert(this->m_scene != nullptr && "Scene has not been assigned to the entity");
return m_scene->m_registry.get<Type>(m_entity);
}
template<typename Type>
[[nodiscard]] bool HasComponent() const {
return m_scene->m_registry.all_of<Type>(m_entity);
}
private:
entt::entity m_entity { 0 };
entt::entity m_entity { entt::null };
Scene *m_scene = nullptr;
};