Maze Builder Docs 7.5.6
Loading...
Searching...
No Matches
grid.h
Go to the documentation of this file.
1#ifndef GRID_H
2#define GRID_H
3
4#include <MazeBuilder/enums.h>
7
8#include <atomic>
9#include <cstdint>
10#include <functional>
11#include <memory>
12#include <mutex>
13#include <optional>
14#include <string>
15#include <tuple>
16#include <unordered_map>
17#include <vector>
18
19namespace mazes
20{
21
22 class cell;
23
27 class grid : public grid_interface, public grid_operations
28 {
29
30 public:
35 explicit grid(unsigned int rows = 1u, unsigned int columns = 1u, unsigned int levels = 1u);
36
39 explicit grid(std::tuple<unsigned int, unsigned int, unsigned int> dimens);
40
43 grid(const grid &other);
44
48 grid &operator=(const grid &other);
49
52 grid(grid &&other) noexcept;
53
57 grid &operator=(grid &&other) noexcept;
58
60 ~grid() override;
61
64 grid_operations &operations() noexcept override;
65
68 const grid_operations &operations() const noexcept override;
69
72 std::tuple<unsigned int, unsigned int, unsigned int> get_dimensions() const noexcept override;
73
77 virtual std::string contents_of(std::shared_ptr<cell> const &c) const noexcept override;
78
82 virtual std::uint32_t background_color_for(std::shared_ptr<cell> const &c) const noexcept override;
83
88 virtual std::shared_ptr<cell> get_neighbor(std::shared_ptr<cell> const &c, Direction dir) const noexcept override;
89
93 virtual std::vector<std::shared_ptr<cell>> get_neighbors(std::shared_ptr<cell> const &c) const noexcept override;
94
100 virtual void set_neighbor(const std::shared_ptr<cell> &c, Direction dir, std::shared_ptr<cell> const &neighbor) noexcept override;
101
102 // Convenience methods for accessing neighbors
103 virtual std::shared_ptr<cell> get_north(const std::shared_ptr<cell> &c) const noexcept override;
104 virtual std::shared_ptr<cell> get_south(const std::shared_ptr<cell> &c) const noexcept override;
105 virtual std::shared_ptr<cell> get_east(const std::shared_ptr<cell> &c) const noexcept override;
106 virtual std::shared_ptr<cell> get_west(const std::shared_ptr<cell> &c) const noexcept override;
107
111 virtual std::shared_ptr<cell> search(int index) const noexcept override;
112
115 virtual int num_cells() const noexcept override;
116
118 virtual void clear_cells() noexcept override;
119
120 virtual void set_str(std::string const &str) noexcept override;
121
122 virtual std::string get_str() const noexcept override;
123
126 virtual std::vector<std::tuple<int, int, int, int>> get_vertices() const noexcept override;
127
130 virtual void set_vertices(const std::vector<std::tuple<int, int, int, int>> &vertices) noexcept override;
131
134 virtual std::vector<std::vector<std::uint32_t>> get_faces() const noexcept override;
135
138 virtual void set_faces(const std::vector<std::vector<std::uint32_t>> &faces) noexcept override;
139
140 private:
141 std::unordered_map<int, std::shared_ptr<cell>> m_cells;
142
143 std::tuple<unsigned int, unsigned int, unsigned int> m_dimensions;
144
145 // Store topology - which cell is neighbor to which in what direction
146 // Key: cell index, Value: map of direction to neighbor cell index
147 mutable std::mutex m_topology_mutex;
148 std::unordered_map<int, std::unordered_map<Direction, int>> m_topology;
149
150 std::string m_str;
151
152 // 3D data
153 std::vector<std::tuple<int, int, int, int>> m_vertices;
154 std::vector<std::vector<std::uint32_t>> m_faces;
155 };
156
157} // namespace mazes
158
159#endif // GRID_H
Cell class with links to other cells.
Definition cell.h:19
Interface for the grid class.
Definition grid_interface.h:20
Interface for grid navigation and manipulation operations.
Definition grid_operations.h:18
General purpose grid class for 2D maze generation.
Definition grid.h:28
grid_operations & operations() noexcept override
grid(const grid &other)
Copy constructor.
virtual std::shared_ptr< cell > search(int index) const noexcept override
Search for a cell by index.
virtual std::vector< std::vector< std::uint32_t > > get_faces() const noexcept override
Get the faces for wavefront object file generation.
virtual void clear_cells() noexcept override
Cleanup cells by cleaning up links within cells.
virtual std::string contents_of(std::shared_ptr< cell > const &c) const noexcept override
Get detailed information of a cell in the grid.
virtual std::uint32_t background_color_for(std::shared_ptr< cell > const &c) const noexcept override
Get the background color for a cell in the grid.
virtual std::vector< std::tuple< int, int, int, int > > get_vertices() const noexcept override
Get the vertices for wavefront object file generation.
virtual void set_faces(const std::vector< std::vector< std::uint32_t > > &faces) noexcept override
Set the faces for wavefront object file generation.
grid & operator=(const grid &other)
Assignment operator.
grid & operator=(grid &&other) noexcept
Move assignment operator.
std::tuple< unsigned int, unsigned int, unsigned int > get_dimensions() const noexcept override
Get the dimensions of the grid.
virtual std::shared_ptr< cell > get_neighbor(std::shared_ptr< cell > const &c, Direction dir) const noexcept override
Get neighbor by the cell's respective location.
grid(std::tuple< unsigned int, unsigned int, unsigned int > dimens)
Construct a grid using a tuple of unsigned integers.
virtual void set_vertices(const std::vector< std::tuple< int, int, int, int > > &vertices) noexcept override
Set the vertices for wavefront object file generation.
grid(grid &&other) noexcept
Move constructor.
grid(unsigned int rows=1u, unsigned int columns=1u, unsigned int levels=1u)
Construct a grid using unsigned integers.
virtual int num_cells() const noexcept override
Get the count of cells in the grid.
~grid() override
Destructor.
virtual void set_neighbor(const std::shared_ptr< cell > &c, Direction dir, std::shared_ptr< cell > const &neighbor) noexcept override
Set neighbor for a cell in a given direction.
virtual std::vector< std::shared_ptr< cell > > get_neighbors(std::shared_ptr< cell > const &c) const noexcept override
Get all the neighbors by the cell.
Enumerations and utilities for the maze builder program.
Namespace for the maze builder.
Definition algo_interface.h:6
Direction
Directional neighbors for grid topology.
Definition enums.h:183