Skip to content

Commit

Permalink
feat: render everything
Browse files Browse the repository at this point in the history
  • Loading branch information
developer239 committed Dec 3, 2023
1 parent 0ca826c commit b546ff9
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/apps/day3/src/strategies/ECSStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,27 @@ class MinimalLoopStrategy : public Core::IStrategy {
// Entities & Components

// Puzzle related entities
auto inputData = ParseInput("assets/input-example-1.txt");
auto inputData = ParseInput("assets/input.txt");
auto partsAndSymbols = FindPartsAndSymbols(inputData);

int maxWidth = 0;
for (const auto& line : inputData) {
maxWidth = std::max(maxWidth, static_cast<int>(line.length()));
}
int maxHeight = inputData.size();

// Calculate a uniform scale factor for both width and height
float uniformScale = std::min(
static_cast<float>(window.GetWidth()) / maxWidth,
static_cast<float>(window.GetHeight()) / maxHeight
);
// Fixed cell size
const float cellSize = 50.0f;

// Initialize grid system
ECS::Registry::Instance().AddSystem<RenderGridSystem>(
uniformScale,
uniformScale
cellSize,
cellSize
);

// Create entities for parts
for (const auto& part : partsAndSymbols.parts) {
ECS::Entity partEntity = ECS::Registry::Instance().CreateEntity();
ECS::Registry::Instance().TagEntity(partEntity, "EnginePart");

// Calculate the scaled position and size, round to the nearest integer
int scaledX = std::lround(part.column * uniformScale);
int scaledY = std::lround(part.row * uniformScale);
int scaledWidth = std::lround(part.number.length() * uniformScale);
int scaledHeight =
std::lround(uniformScale); // Height is based on a single character
int scaledX = part.column * cellSize;
int scaledY = part.row * cellSize;
int scaledWidth = part.number.length() * cellSize;
int scaledHeight = cellSize;

ECS::Registry::Instance().AddComponent<RigidBodyComponent>(
partEntity,
Expand Down Expand Up @@ -107,11 +96,9 @@ class MinimalLoopStrategy : public Core::IStrategy {
ECS::Entity symbolEntity = ECS::Registry::Instance().CreateEntity();
ECS::Registry::Instance().TagEntity(symbolEntity, "Symbol");

// Calculate the scaled position and size, round to the nearest integer
int scaledX = std::lround(symbol.column * uniformScale);
int scaledY = std::lround(symbol.row * uniformScale);
int scaledSize =
std::lround(uniformScale); // Assuming square size for symbols
int scaledX = symbol.column * cellSize;
int scaledY = symbol.row * cellSize;
int scaledSize = cellSize; // Assuming square size for symbols

ECS::Registry::Instance().AddComponent<RigidBodyComponent>(
symbolEntity,
Expand Down Expand Up @@ -142,8 +129,8 @@ class MinimalLoopStrategy : public Core::IStrategy {
ECS::Registry::Instance().AddComponent<CameraComponent>(
cameraEntity.value(),
Vec2(0, 0),
window.GetWidth() + 100,
window.GetHeight() + 100
window.GetWidth(),
window.GetHeight()
);
}

Expand Down

0 comments on commit b546ff9

Please sign in to comment.