feat: scene + entity class
This commit is contained in:
@ -5,9 +5,8 @@ set(SOURCES
|
||||
src/IO/file_manager.cpp
|
||||
src/renderer/debug.cpp
|
||||
|
||||
src/window/window.cpp
|
||||
|
||||
src/scene/scene.cpp
|
||||
src/window/window.cpp
|
||||
|
||||
src/components/batch.cpp
|
||||
src/renderer/mesh.cpp
|
||||
|
||||
@ -1,18 +1,30 @@
|
||||
#ifndef ENGINE_SCENE_H_
|
||||
#define ENGINE_SCENE_H_
|
||||
#pragma once
|
||||
|
||||
#include <entt/entt.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Engine {
|
||||
|
||||
class Scene;
|
||||
class Entity;
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
friend class Entity;
|
||||
public:
|
||||
Scene() = default;
|
||||
|
||||
Entity CreateEntity();
|
||||
private:
|
||||
entt::registry m_registry;
|
||||
friend class Renderer;
|
||||
};
|
||||
|
||||
class Entity {
|
||||
friend class Scene;
|
||||
private:
|
||||
Entity(entt::entity entity, Scene* scene) : m_entity(entity), m_scene(scene) {}
|
||||
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) {
|
||||
assert(this->m_scene != nullptr && "Scene has not been assigned to the entity");
|
||||
@ -25,22 +37,8 @@ public:
|
||||
return m_scene->m_registry.get<Type>(m_entity);
|
||||
}
|
||||
private:
|
||||
entt::entity m_entity;
|
||||
Scene *m_scene;
|
||||
};
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
friend class Entity;
|
||||
public:
|
||||
Scene();
|
||||
|
||||
std::unique_ptr<Entity> CreateEntity();
|
||||
private:
|
||||
entt::registry m_registry;
|
||||
friend class Renderer;
|
||||
entt::entity m_entity { 0 };
|
||||
Scene *m_scene = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Engine
|
||||
|
||||
#endif // ENGINE_SCENE_H_
|
||||
@ -2,10 +2,8 @@
|
||||
|
||||
namespace Engine {
|
||||
|
||||
Scene::Scene() = default;
|
||||
|
||||
std::unique_ptr<Entity> Scene::CreateEntity() {
|
||||
return std::unique_ptr<Entity>(new Entity(m_registry.create(), this));
|
||||
Entity Scene::CreateEntity() {
|
||||
return { m_registry.create(), this };
|
||||
}
|
||||
|
||||
} // namespace Engine
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user