Browse Source

Add components and scene

master
Riyyi 4 years ago
parent
commit
a4a16f4a52
  1. 28
      inferno/src/inferno/scene/components.h
  2. 40
      inferno/src/inferno/scene/scene.cpp
  3. 28
      inferno/src/inferno/scene/scene.h

28
inferno/src/inferno/scene/components.h

@ -0,0 +1,28 @@
#ifndef COMPONENTS_H
#define COMPONENTS_H
#include <string> // 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

40
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<entt::registry>();
Entity entity = createEntity("Test Entity");
dbg() << entity.get<TagComponent>();
if (entity) {
dbg() << "Entity is valid";
}
}
Entity Scene::createEntity(const std::string& name)
{
Entity entity = Entity(m_registry);
entity.add<TagComponent>(name.empty() ? "Unnamed Entity" : name);
entity.add<TransformComponent>();
return entity;
}
Entity Scene::createEntity(entt::entity handle)
{
return Entity(m_registry, handle);
}
Entity Scene::createEntity(uint32_t handle)
{
return Entity(m_registry, handle);
}
}

28
inferno/src/inferno/scene/scene.h

@ -0,0 +1,28 @@
#ifndef SCENE_H
#define SCENE_H
#include <cstdint> // uint32_t
#include <memory> // 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<entt::registry> m_registry;
};
}
#endif // SCENE_H
Loading…
Cancel
Save