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.

master
Zed A. Shaw 3 weeks ago
parent 49a71e257e
commit 9c66e870d2
  1. 4
      dinkyecs.hpp
  2. 16
      ecs_gui.cpp
  3. 15
      systems.cpp

@ -181,7 +181,7 @@ namespace DinkyECS
}
template <typename Comp>
void query(std::function<void(const Entity &, Comp &)> cb)
void query(std::function<void(Entity, Comp &)> cb)
{
EntityMap &map = entity_map_for<Comp>();
@ -192,7 +192,7 @@ namespace DinkyECS
}
template <typename CompA, typename CompB>
void query(std::function<void(const Entity &, CompA &, CompB &)> cb)
void query(std::function<void(Entity, CompA &, CompB &)> cb)
{
EntityMap &map_a = entity_map_for<CompA>();
EntityMap &map_b = entity_map_for<CompB>();

@ -21,15 +21,15 @@ DinkyECS::Entity GUECS::entity(std::string name) {
}
void GUECS::init(TexturePack& textures) {
$world.query<lel::Cell, Rectangle>([](const auto &, auto& cell, auto& rect) {
$world.query<lel::Cell, Rectangle>([](auto, auto& cell, auto& rect) {
rect.init(cell);
});
$world.query<lel::Cell, Textual>([this](const auto &, auto& cell, auto& text) {
$world.query<lel::Cell, Textual>([this](auto, auto& cell, auto& text) {
text.init(cell, $font);
});
$world.query<lel::Cell, Sprite>([&](const auto &, auto &cell, auto &sprite) {
$world.query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) {
auto sprite_texture = textures.get(sprite.name);
sprite.texture = sprite_texture.texture;
sprite.sprite = make_shared<sf::Sprite>(*sprite.texture);
@ -40,7 +40,7 @@ void GUECS::init(TexturePack& textures) {
}
void GUECS::render(sf::RenderWindow& window) {
$world.query<lel::Cell, Meter>([&](const auto &ent, const auto& cell, const auto &meter) {
$world.query<lel::Cell, Meter>([&](auto ent, auto& cell, const auto &meter) {
if($world.has<Rectangle>(ent)) {
float level = meter.percent * float(cell.w);
auto& target = $world.get<Rectangle>(ent);
@ -49,15 +49,15 @@ void GUECS::render(sf::RenderWindow& window) {
}
});
$world.query<Rectangle>([&](const auto &, const auto& rect) {
$world.query<Rectangle>([&](auto, auto& rect) {
window.draw(*rect.shape);
});
$world.query<Sprite>([&](const auto &, const auto& sprite) {
$world.query<Sprite>([&](auto, auto& sprite) {
window.draw(*sprite.sprite);
});
$world.query<Textual>([&](const auto &, const auto& text) {
$world.query<Textual>([&](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<lel::Cell, Clickable>([&](const auto &ent, auto& cell, auto &clicked) {
$world.query<lel::Cell, Clickable>([&](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))
{

@ -22,13 +22,13 @@ void System::lighting(GameLevel &level) {
light.reset_light();
world.query<Position>([&](const auto &ent[[maybe_unused]], auto &position) {
world.query<Position>([&](auto, auto &position) {
light.set_light_target(position.location);
});
light.path_light(map.walls());
world.query<Position, LightSource>([&](const auto &ent[[maybe_unused]], auto &position, auto &lightsource) {
world.query<Position, LightSource>([&](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<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
world.query<Position, Motion>([&](auto ent, auto &position, auto &motion) {
if(ent != player.entity) {
dbc::check(world.has<EnemyConfig>(ent), "enemy is missing config");
const auto &config = world.get<EnemyConfig>(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<Position>([&](const auto &ent, auto &pos) {
world.query<Position>([&](auto ent, auto &pos) {
if(world.has<Combat>(ent)) {
const auto& combat = world.get<Combat>(ent);
if(!combat.dead) {
@ -95,7 +96,7 @@ void System::motion(GameLevel &level) {
auto &world = *level.world;
auto &collider = *level.collision;
world.query<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
world.query<Position, Motion>([&](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<Position, Combat>([&](const auto &ent, auto &position, auto &combat) {
world.query<Position, Combat>([&](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<Position, Tile>([&](auto &ent[[maybe_unused]], auto &pos, auto &tile) {
world.query<Position, Tile>([&](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);

Loading…
Cancel
Save