6#include <aegis2d/ecs/export.hpp>
68 static constexpr std::size_t max_cells = std::size_t{1} << 20U;
109 [[nodiscard]] std::optional<Cell>
cell_at(
Vec2 position)
const noexcept;
128 [[nodiscard]] std::uint64_t
version() const noexcept;
132 [[nodiscard]]
int columns() const noexcept;
136 [[nodiscard]]
int rows() const noexcept;
139 [[nodiscard]]
std::
size_t index_of(
Cell cell) const;
140 [[nodiscard]]
std::
size_t slot(
Cell cell) const noexcept;
141 [[nodiscard]]
Cell cell_of(
std::
size_t slot) const noexcept;
147 std::uint64_t version_ = 1;
148 std::vector<
std::uint8_t> walkable_;
149 std::vector<
float> costs_;
162 std::vector<Vec2> points{};
164 std::uint64_t version = 0;
170 if (version == grid.
version()) {
Grid of cells that can be walked or not, each with a cost, and the shortest path between two of them.
Definition pathfinding.hpp:55
void set_walkable(Cell cell, bool walkable)
Makes a cell walkable or blocked; its cost is kept.
std::uint64_t version() const noexcept
Number of changes made to the grid.
float cost(Cell cell) const
Cost of entering a cell.
Vec2 center(Cell cell) const noexcept
Center of a cell.
std::vector< Vec2 > find_path(Cell from, Cell to) const
Shortest path between two cells.
NavGrid(int columns, int rows, Vec2 cell_size, Vec2 origin={})
Creates a grid where every cell is walkable with a cost of 1.
std::optional< Cell > cell_at(Vec2 position) const noexcept
Cell under a position.
bool contains(Cell cell) const noexcept
Tells whether a cell is in the grid.
void set_cost(Cell cell, float cost)
Sets the cost of entering a cell.
void mark_tiles(std::span< const std::uint32_t > tiles, Painted painted)
Sets every cell walkable or blocked from a tile layer.
bool walkable(Cell cell) const
Tells whether a cell can be walked.
Vector and matrix types of the engine (GLM behind engine names).
Entity-Component-System used by client and server.
Definition animation.hpp:13
Painted
What the painted cells of a tile layer are, for NavGrid::mark_tiles().
Definition pathfinding.hpp:28
@ Blocked
Painted cells are blocked, empty ones can be walked (a layer of walls).
@ Walkable
Painted cells can be walked, empty ones cannot (a layer that draws the path).
glm::vec2 Vec2
2D vector of floats: positions, velocities, sizes (glm::vec2).
Definition math.hpp:19
Definition endpoint.hpp:85
Column and row of a grid cell, from the top-left one.
Definition pathfinding.hpp:17
int x
Column, from 0 on the left.
Definition pathfinding.hpp:19
friend constexpr bool operator==(Cell, Cell) noexcept=default
Compares the cells.
int y
Row, from 0 at the top.
Definition pathfinding.hpp:21
Path between two cells, found again only when the grid has changed.
Definition pathfinding.hpp:156
bool update(const NavGrid &grid)
Finds the path again if the grid changed since the last time.
Definition pathfinding.hpp:169