Learned yesterday that you can do a multi-return assing to auto[] by just returning a struct.
This commit is contained in:
parent
3394327981
commit
a44a9a04f9
2 changed files with 8 additions and 4 deletions
|
@ -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;
|
EntityList result;
|
||||||
|
|
||||||
// just unroll the loop since we only check four directions
|
// 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
|
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 "map.hpp"
|
||||||
#include "dinkyecs.hpp"
|
#include "dinkyecs.hpp"
|
||||||
#include "point.hpp"
|
#include "point.hpp"
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
typedef std::vector<DinkyECS::Entity> EntityList;
|
typedef std::vector<DinkyECS::Entity> EntityList;
|
||||||
|
|
||||||
typedef std::unordered_map<Point, DinkyECS::Entity, PointHash> PointEntityMap;
|
typedef std::unordered_map<Point, DinkyECS::Entity, PointHash> PointEntityMap;
|
||||||
|
|
||||||
|
struct FoundEntities {
|
||||||
|
bool found;
|
||||||
|
EntityList nearby;
|
||||||
|
};
|
||||||
|
|
||||||
class spatial_map {
|
class spatial_map {
|
||||||
public:
|
public:
|
||||||
spatial_map() {}
|
spatial_map() {}
|
||||||
|
@ -18,7 +22,7 @@ class spatial_map {
|
||||||
void move(Point from, Point to, DinkyECS::Entity ent);
|
void move(Point from, Point to, DinkyECS::Entity ent);
|
||||||
void remove(Point pos);
|
void remove(Point pos);
|
||||||
bool occupied(Point pos) const;
|
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:
|
private:
|
||||||
PointEntityMap table;
|
PointEntityMap table;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue