Skip to content

Commit

Permalink
fix: camera initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
developer239 committed Dec 3, 2023
1 parent d8c4c28 commit 0ca826c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/apps/day3/src/strategies/ECSStrategy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <optional>

#include "core/AssetStore.h"
#include "core/IStrategy.h"
#include "core/Window.h"
Expand All @@ -19,7 +21,7 @@

class MinimalLoopStrategy : public Core::IStrategy {
public:
ECS::Entity cameraEntity = ECS::Registry::Instance().CreateEntity();
std::optional<ECS::Entity> cameraEntity;

void Init(Core::Window& window, Core::Renderer& renderer) override {
Core::AssetStore::Instance().AddFont("pico8", "assets/fonts/arial.ttf", 24);
Expand All @@ -45,14 +47,6 @@ class MinimalLoopStrategy : public Core::IStrategy {

// Entities & Components

// Camera
ECS::Registry::Instance().AddComponent<CameraComponent>(
cameraEntity,
Vec2(0, 0),
window.GetWidth() + 100,
window.GetHeight() + 100
);

// Puzzle related entities
auto inputData = ParseInput("assets/input-example-1.txt");
auto partsAndSymbols = FindPartsAndSymbols(inputData);
Expand Down Expand Up @@ -142,6 +136,15 @@ class MinimalLoopStrategy : public Core::IStrategy {
Vec2(bboxOffset, bboxOffset)
);
}

// Camera
cameraEntity = ECS::Registry::Instance().CreateEntity();
ECS::Registry::Instance().AddComponent<CameraComponent>(
cameraEntity.value(),
Vec2(0, 0),
window.GetWidth() + 100,
window.GetHeight() + 100
);
}

void HandleEvent(SDL_Event& event) override {
Expand Down Expand Up @@ -170,10 +173,10 @@ class MinimalLoopStrategy : public Core::IStrategy {
);
ECS::Registry::Instance().GetSystem<RenderRigidBodiesSystem>().Render(
renderer,
cameraEntity
cameraEntity.value()
);
ECS::Registry::Instance().GetSystem<RenderTextSystem>().Render(renderer, cameraEntity);
ECS::Registry::Instance().GetSystem<RenderTextSystem>().Render(renderer, cameraEntity.value());

ECS::Registry::Instance().GetSystem<RenderCollidersSystem>().Render(renderer, cameraEntity);
ECS::Registry::Instance().GetSystem<RenderCollidersSystem>().Render(renderer, cameraEntity.value());
}
};

0 comments on commit 0ca826c

Please sign in to comment.