From a44a9a04f9714bd1c8ba8cc548be174008edb616 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 1 Nov 2024 00:40:04 -0400 Subject: [PATCH] Learned yesterday that you can do a multi-return assing to auto[] by just returning a struct. --- collider.cpp | 4 ++-- collider.hpp | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/collider.cpp b/collider.cpp index c7f7f2a..262dfd2 100644 --- a/collider.cpp +++ b/collider.cpp @@ -41,7 +41,7 @@ inline void find_neighbor(const PointEntityMap &table, EntityList &result, Point } } -std::tuple 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 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}; } diff --git a/collider.hpp b/collider.hpp index 2a4f502..bbc5dee 100644 --- a/collider.hpp +++ b/collider.hpp @@ -4,12 +4,16 @@ #include "map.hpp" #include "dinkyecs.hpp" #include "point.hpp" -#include typedef std::vector EntityList; typedef std::unordered_map 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 neighbors(Point position, bool diag=false) const; + FoundEntities neighbors(Point position, bool diag=false) const; private: PointEntityMap table;