From a4a16f4a5243ff5e65a7ccba51cf26ef898b6917 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 13 Jan 2021 14:41:36 +0100 Subject: [PATCH] Add components and scene --- inferno/src/inferno/scene/components.h | 28 ++++++++++++++++++ inferno/src/inferno/scene/scene.cpp | 40 ++++++++++++++++++++++++++ inferno/src/inferno/scene/scene.h | 28 ++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 inferno/src/inferno/scene/components.h create mode 100644 inferno/src/inferno/scene/scene.cpp create mode 100644 inferno/src/inferno/scene/scene.h diff --git a/inferno/src/inferno/scene/components.h b/inferno/src/inferno/scene/components.h new file mode 100644 index 0000000..1fb0dfb --- /dev/null +++ b/inferno/src/inferno/scene/components.h @@ -0,0 +1,28 @@ +#ifndef COMPONENTS_H +#define COMPONENTS_H + +#include // std::string + +#include "glm/ext/vector_float3.hpp" // glm::vec3 + +namespace Inferno { + + struct TagComponent { + std::string tag; + + TagComponent() = default; + TagComponent(const std::string& tag) + : tag(tag) {} + + operator const std::string&() const { return tag; } + }; + + struct TransformComponent { + glm::vec3 translate = { 0.0f, 0.0f, 0.0f }; + glm::vec3 rotate = { 0.0f, 0.0f, 0.0f } ; + glm::vec3 scale = { 1.0f, 1.0f, 1.0f }; + }; + +} + +#endif // COMPONENTS_H diff --git a/inferno/src/inferno/scene/scene.cpp b/inferno/src/inferno/scene/scene.cpp new file mode 100644 index 0000000..f821c65 --- /dev/null +++ b/inferno/src/inferno/scene/scene.cpp @@ -0,0 +1,40 @@ +#include "inferno/log.h" +#include "inferno/scene/components.h" +#include "inferno/scene/entity.h" +#include "inferno/scene/scene.h" + +namespace Inferno { + + Scene::Scene() + { + m_registry = std::make_shared(); + + Entity entity = createEntity("Test Entity"); + + dbg() << entity.get(); + + if (entity) { + dbg() << "Entity is valid"; + } + } + + Entity Scene::createEntity(const std::string& name) + { + Entity entity = Entity(m_registry); + entity.add(name.empty() ? "Unnamed Entity" : name); + entity.add(); + + return entity; + } + + Entity Scene::createEntity(entt::entity handle) + { + return Entity(m_registry, handle); + } + + Entity Scene::createEntity(uint32_t handle) + { + return Entity(m_registry, handle); + } + +} diff --git a/inferno/src/inferno/scene/scene.h b/inferno/src/inferno/scene/scene.h new file mode 100644 index 0000000..cd4398e --- /dev/null +++ b/inferno/src/inferno/scene/scene.h @@ -0,0 +1,28 @@ +#ifndef SCENE_H +#define SCENE_H + +#include // uint32_t +#include // std::shared_ptr + +#include "entt/entity/registry.hpp" // entt::entity, entt::registry + +namespace Inferno { + + class Entity; + + class Scene { + public: + Scene(); + virtual ~Scene() = default; + + Entity createEntity(const std::string& name = ""); + Entity createEntity(entt::entity handle); + Entity createEntity(uint32_t handle); + + private: + std::shared_ptr m_registry; + }; + +} + +#endif // SCENE_H