diff --git a/include/fggl/entity/gridworld/zone.hpp b/include/fggl/entity/gridworld/zone.hpp index 38a14decba8be1a59bd8091ea17e89f02cb8c746..9e184dd391b865fbcdc835723f3f6a2d014004e4 100644 --- a/include/fggl/entity/gridworld/zone.hpp +++ b/include/fggl/entity/gridworld/zone.hpp @@ -34,17 +34,22 @@ namespace fggl::entity::grid { template<typename T, uint32_t width, uint32_t height> struct Grid { public: + constexpr static std::array<math::vec2i, 4> DIRECTIONS{{ {-1, 0}, {0, -1}, {1, 0}, {0, 1} }}; + Grid() = default; inline T& get(GridPos pos) { + assert(inBounds(pos)); return m_cells[getCellIndex(pos)]; } const T& get(GridPos pos) const { + assert(inBounds(pos)); return m_cells[getCellIndex(pos)]; } inline void set(GridPos pos, T value) { + assert(inBounds(pos)); m_cells[getCellIndex(pos)] = value; } @@ -57,7 +62,6 @@ namespace fggl::entity::grid { constexpr static math::vec2i size = math::vec2i(width, height); std::array<T, size.x * size.y> m_cells; - inline uint32_t getCellIndex(GridPos pos) const { assert( inBounds(pos)); return pos.y * size.x + pos.x; @@ -98,6 +102,7 @@ namespace fggl::entity::grid { clear(); } + [[nodiscard]] inline bool inBounds(GridPos pos) const { return 0 <= pos.x && pos.x <= width && 0 <= pos.y && pos.y <= height;