Learned yesterday that you can do a multi-return assing to auto[] by just returning a struct.

main
Zed A. Shaw 2 months ago
parent 3394327981
commit a44a9a04f9
  1. 4
      collider.cpp
  2. 8
      collider.hpp

@ -41,7 +41,7 @@ inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point
}
}
std::tuple<bool, EntityList> spatial_map::neighbors(Point cell, bool diag) const {
FoundEntities spatial_map::neighbors(Point cell, bool diag) const {
EntityList result;
// just unroll the loop since we only check four directions
@ -58,5 +58,5 @@ std::tuple<bool, EntityList> spatial_map::neighbors(Point cell, bool diag) const
find_neighbor(table, result, cell, -1, 1); // north west
}
return std::tuple(!result.empty(), result);
return {!result.empty(), result};
}

@ -4,12 +4,16 @@
#include "map.hpp"
#include "dinkyecs.hpp"
#include "point.hpp"
#include <tuple>
typedef std::vector<DinkyECS::Entity> EntityList;
typedef std::unordered_map<Point, DinkyECS::Entity, PointHash> PointEntityMap;
struct FoundEntities {
bool found;
EntityList nearby;
};
class spatial_map {
public:
spatial_map() {}
@ -18,7 +22,7 @@ class spatial_map {
void move(Point from, Point to, DinkyECS::Entity ent);
void remove(Point pos);
bool occupied(Point pos) const;
std::tuple<bool, EntityList> neighbors(Point position, bool diag=false) const;
FoundEntities neighbors(Point position, bool diag=false) const;
private:
PointEntityMap table;

Loading…
Cancel
Save