From 20176cf54a86b8f3b98c929c7cbf51fd17a081ca Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 4 May 2025 11:06:53 -0400 Subject: [PATCH] GUECS refactor part 1. --- guecs.cpp | 58 ++++++++++++++-------------- guecs.hpp | 110 +++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 108 insertions(+), 60 deletions(-) diff --git a/guecs.cpp b/guecs.cpp index 4737691..feec9f2 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -155,70 +155,70 @@ namespace guecs { for(auto& [name, cell] : $parser.cells) { auto ent = init_entity(name); - $world.set(ent, cell); + set(ent, cell); } } - DinkyECS::Entity UI::init_entity(const string& name) { - auto entity = $world.entity(); + Entity UI::init_entity(const string& name) { + auto ent = entity(); // this lets you look up an entity by name - $name_ents.insert_or_assign(name, entity); + $name_ents.insert_or_assign(name, ent); // this makes it easier to get the name during querying - $world.set(entity, {name}); - return entity; + set(ent, {name}); + return ent; } - DinkyECS::Entity UI::entity(const string& name) { + Entity UI::entity(const string& name) { dbc::check($name_ents.contains(name), fmt::format("GUECS entity {} does not exist. Mispelled cell name?", name)); return $name_ents.at(name); } - DinkyECS::Entity UI::entity(const string& name, int id) { + Entity UI::entity(const string& name, int id) { return entity(fmt::format("{}{}", name, id)); } void UI::init() { - if($world.has_the()) { - auto& bg = $world.get_the(); + if(has_the()) { + auto& bg = get_the(); bg.init(); } - $world.query([](auto, auto& bg) { + query([](auto, auto& bg) { bg.init(); }); - $world.query([](auto, auto& cell, auto& rect) { + query([](auto, auto& cell, auto& rect) { rect.init(cell); }); - $world.query([](auto, auto& cell, auto& shader) { + query([](auto, auto& cell, auto& shader) { shader.init(cell); }); - $world.query([](auto, auto& bg, auto &meter) { + query([](auto, auto& bg, auto &meter) { bg.shape->setFillColor(meter.color); }); - $world.query([](auto, auto &cell, auto& meter) { + query([](auto, auto &cell, auto& meter) { meter.init(cell); }); - $world.query([this](auto, auto& cell, auto& text) { + query([this](auto, auto& cell, auto& text) { text.init(cell, $font); }); - $world.query([this](auto, auto& cell, auto& text) { + query([this](auto, auto& cell, auto& text) { text.init(cell, $font); }); - $world.query([&](auto, auto &cell, auto &sprite) { + query([&](auto, auto &cell, auto &sprite) { sprite.init(cell); }); } void UI::debug_layout(sf::RenderWindow& window) { - $world.query([&](const auto, auto &cell) { + query([&](const auto, auto &cell) { sf::RectangleShape rect{{float(cell.w), float(cell.h)}}; rect.setPosition({float(cell.x), float(cell.y)}); rect.setFillColor(sf::Color::Transparent); @@ -229,33 +229,33 @@ namespace guecs { } void UI::render(sf::RenderWindow& window) { - if($world.has_the()) { - auto& bg = $world.get_the(); + if(has_the()) { + auto& bg = get_the(); window.draw(*bg.shape); } - $world.query([&](auto, auto& shader) { + query([&](auto, auto& shader) { if(shader.$active) shader.step(); }); - $world.query([&](auto ent, auto& rect) { + query([&](auto ent, auto& rect) { render_helper(window, ent, true, rect.shape); }); - $world.query([&](auto ent, auto& cell, auto &meter) { + query([&](auto ent, auto& cell, auto &meter) { meter.render(cell); render_helper(window, ent, true, meter.bar.shape); }); - $world.query([&](auto ent, auto& sprite) { + query([&](auto ent, auto& sprite) { render_helper(window, ent, false, sprite.sprite); }); - $world.query