From 9c66e870d2e2c6bb3531eba7b26054266fc2a3f3 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 18 Feb 2025 11:39:27 -0500 Subject: [PATCH] Finally get rid of this weird thing in dinkyecs where I was passing a const& to an _integer_ when a copy of the integer is exactly the same. --- dinkyecs.hpp | 4 ++-- ecs_gui.cpp | 16 ++++++++-------- systems.cpp | 15 ++++++++------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/dinkyecs.hpp b/dinkyecs.hpp index c0644f2..17dee17 100644 --- a/dinkyecs.hpp +++ b/dinkyecs.hpp @@ -181,7 +181,7 @@ namespace DinkyECS } template - void query(std::function cb) + void query(std::function cb) { EntityMap &map = entity_map_for(); @@ -192,7 +192,7 @@ namespace DinkyECS } template - void query(std::function cb) + void query(std::function cb) { EntityMap &map_a = entity_map_for(); EntityMap &map_b = entity_map_for(); diff --git a/ecs_gui.cpp b/ecs_gui.cpp index 91ea706..84b874f 100644 --- a/ecs_gui.cpp +++ b/ecs_gui.cpp @@ -21,15 +21,15 @@ DinkyECS::Entity GUECS::entity(std::string name) { } void GUECS::init(TexturePack& textures) { - $world.query([](const auto &, auto& cell, auto& rect) { + $world.query([](auto, auto& cell, auto& rect) { rect.init(cell); }); - $world.query([this](const auto &, auto& cell, auto& text) { + $world.query([this](auto, auto& cell, auto& text) { text.init(cell, $font); }); - $world.query([&](const auto &, auto &cell, auto &sprite) { + $world.query([&](auto, auto &cell, auto &sprite) { auto sprite_texture = textures.get(sprite.name); sprite.texture = sprite_texture.texture; sprite.sprite = make_shared(*sprite.texture); @@ -40,7 +40,7 @@ void GUECS::init(TexturePack& textures) { } void GUECS::render(sf::RenderWindow& window) { - $world.query([&](const auto &ent, const auto& cell, const auto &meter) { + $world.query([&](auto ent, auto& cell, const auto &meter) { if($world.has(ent)) { float level = meter.percent * float(cell.w); auto& target = $world.get(ent); @@ -49,15 +49,15 @@ void GUECS::render(sf::RenderWindow& window) { } }); - $world.query([&](const auto &, const auto& rect) { + $world.query([&](auto, auto& rect) { window.draw(*rect.shape); }); - $world.query([&](const auto &, const auto& sprite) { + $world.query([&](auto, auto& sprite) { window.draw(*sprite.sprite); }); - $world.query([&](const auto &, const auto& text) { + $world.query([&](auto, auto& text) { window.draw(*text.text); }); } @@ -65,7 +65,7 @@ void GUECS::render(sf::RenderWindow& window) { void GUECS::mouse(sf::RenderWindow &window) { if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) { sf::Vector2f pos = window.mapPixelToCoords(sf::Mouse::getPosition(window)); - $world.query([&](const auto &ent, auto& cell, auto &clicked) { + $world.query([&](auto ent, auto& cell, auto &clicked) { if((pos.x >= cell.x && pos.x <= cell.x + cell.w) && (pos.y >= cell.y && pos.y <= cell.y + cell.h)) { diff --git a/systems.cpp b/systems.cpp index 04aca58..adac189 100644 --- a/systems.cpp +++ b/systems.cpp @@ -22,13 +22,13 @@ void System::lighting(GameLevel &level) { light.reset_light(); - world.query([&](const auto &ent[[maybe_unused]], auto &position) { + world.query([&](auto, auto &position) { light.set_light_target(position.location); }); light.path_light(map.walls()); - world.query([&](const auto &ent[[maybe_unused]], auto &position, auto &lightsource) { + world.query([&](auto, auto &position, auto &lightsource) { light.render_light(lightsource, position.location); }); } @@ -43,7 +43,7 @@ void System::enemy_pathing(GameLevel &level) { map.set_target(player_position.location); map.make_paths(); - world.query([&](const auto &ent, auto &position, auto &motion) { + world.query([&](auto ent, auto &position, auto &motion) { if(ent != player.entity) { dbc::check(world.has(ent), "enemy is missing config"); const auto &config = world.get(ent); @@ -55,13 +55,14 @@ void System::enemy_pathing(GameLevel &level) { } } }); + map.clear_target(player_position.location); } void System::init_positions(DinkyECS::World &world, SpatialMap &collider) { // BUG: instead of separate things maybe just one // BUG: Collision component that references what is collide - world.query([&](const auto &ent, auto &pos) { + world.query([&](auto ent, auto &pos) { if(world.has(ent)) { const auto& combat = world.get(ent); if(!combat.dead) { @@ -95,7 +96,7 @@ void System::motion(GameLevel &level) { auto &world = *level.world; auto &collider = *level.collision; - world.query([&](const auto &ent, auto &position, auto &motion) { + world.query([&](auto ent, auto &position, auto &motion) { // don't process entities that don't move if(motion.dx != 0 || motion.dy != 0) { move_entity(collider, map, position, motion, ent); @@ -112,7 +113,7 @@ void System::death(GameLevel &level) { // BUG: eachother and overlap their corpse // BUG: maybe that can be allowed and looting just shows // BUG: all dead things there? - world.query([&](const auto &ent, auto &position, auto &combat) { + world.query([&](auto ent, auto &position, auto &combat) { // bring out yer dead if(combat.hp <= 0 && !combat.dead) { fmt::println("DIE! entity {} died", ent); @@ -256,7 +257,7 @@ void System::plan_motion(DinkyECS::World& world, Point move_to) { void System::draw_entities(DinkyECS::World &world, Map &map, const Matrix &lights, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) { auto &tiles = map.tiles(); - world.query([&](auto &ent[[maybe_unused]], auto &pos, auto &tile) { + world.query([&](auto, auto &pos, auto &tile) { if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x && pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y) { Point loc = map.map_to_camera(pos.location, cam_orig);