Browse Source

Move example entities to scene

master
Riyyi 4 years ago
parent
commit
0b2cc9f411
  1. 22
      inferno/src/inferno/application.cpp
  2. 2
      inferno/src/inferno/application.h
  3. 37
      inferno/src/inferno/scene/scene.cpp
  4. 7
      inferno/src/inferno/scene/scene.h

22
inferno/src/inferno/application.cpp

@ -46,6 +46,7 @@ namespace Inferno {
textureManager->initialize();
m_scene = std::make_shared<Scene>();
m_scene->initialize();
Renderer2D* renderer2D = new Renderer2D();
renderer2D->initialize();
@ -58,9 +59,6 @@ namespace Inferno {
// Load assets
m_texture = TextureManager::the().load("assets/gfx/test.png");
m_texture2 = TextureManager::the().load("assets/gfx/test-inverted.png");
m_font = FontManager::the().load("assets/fnt/dejavu-sans");
}
@ -80,19 +78,6 @@ namespace Inferno {
{
dbg() << "Application startup";
Entity quad = m_scene->createEntity("Quad");
quad.add<SpriteComponent>(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture);
Entity quad2 = m_scene->createEntity("Quad 2");
auto& quad2Transform = quad2.get<TransformComponent>();
quad2Transform.translate.x = 1.1f;
quad2.add<SpriteComponent>(glm::vec4 { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture);
Entity quad3 = m_scene->createEntity("Quad 3");
auto& quad3Transform = quad3.get<TransformComponent>();
quad3Transform.translate.x = 2.2f;
quad3.add<SpriteComponent>(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
std::array<CharacterVertex, Renderer::vertexPerQuad> character;
// character.at(0).quad.textureCoordinates = { 0.0f, 0.0f }; // bottom left
@ -131,11 +116,6 @@ namespace Inferno {
character.at(2).quad.textureCoordinates = { x.y, y.y };
character.at(3).quad.textureCoordinates = { x.x, y.y };
character.at(0).quad.textureIndex = 1.0f;
character.at(1).quad.textureIndex = 1.0f;
character.at(2).quad.textureIndex = 1.0f;
character.at(3).quad.textureIndex = 1.0f;
// pos
// texcoords
//

2
inferno/src/inferno/application.h

@ -47,8 +47,6 @@ namespace Inferno {
float m_lastFrameTime = 0.0f;
//
std::shared_ptr<Texture> m_texture;
std::shared_ptr<Texture> m_texture2;
std::shared_ptr<Font> m_font;
//

37
inferno/src/inferno/scene/scene.cpp

@ -8,18 +8,11 @@
namespace Inferno {
Scene::Scene()
{
initialize();
}
Scene::~Scene()
{
destroy();
}
void Scene::initialize()
{
// Initialize
// ---------------------------------
m_registry = std::make_shared<entt::registry>();
TransformSystem* transformSystem = new TransformSystem();
@ -39,6 +32,30 @@ namespace Inferno {
RenderSystem* renderSystem = new RenderSystem();
renderSystem->initialize();
RenderSystem::the().setRegistry(m_registry);
// Load assets
// ---------------------------------
m_texture = TextureManager::the().load("assets/gfx/test.png");
m_texture2 = TextureManager::the().load("assets/gfx/test-inverted.png");
// Construct entities
// ---------------------------------
Entity quad = createEntity("Quad");
quad.add<SpriteComponent>(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture);
Entity quad2 = createEntity("Quad 2");
auto& quad2Transform = quad2.get<TransformComponent>();
quad2Transform.translate.x = 1.1f;
quad2.add<SpriteComponent>(glm::vec4 { 0.5f, 0.6f, 0.8f, 1.0f }, m_texture);
Entity quad3 = createEntity("Quad 3");
auto& quad3Transform = quad3.get<TransformComponent>();
quad3Transform.translate.x = 2.2f;
quad3.add<SpriteComponent>(glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f }, m_texture2);
dbg(Log::Info) << "Scene initialized";
}
void Scene::update(float deltaTime)

7
inferno/src/inferno/scene/scene.h

@ -11,12 +11,10 @@ namespace Inferno {
class Camera;
class Entity;
class Texture;
class Scene {
public:
Scene();
virtual ~Scene();
void initialize();
void update(float deltaTime);
void render();
@ -29,6 +27,9 @@ namespace Inferno {
glm::mat4 cameraProjectionView();
private:
std::shared_ptr<Texture> m_texture;
std::shared_ptr<Texture> m_texture2;
std::shared_ptr<entt::registry> m_registry;
};

Loading…
Cancel
Save