TazGraph Project v0.1.0
Loading...
Searching...
No Matches
Grid.h
1#pragma once
2#include "../GECS/Core/GECSEntity.h"
3#include "../GECS/Components.h"
4
5#include "../AABB/AABB.h"
6
7#include <vector>
8
9#include <cmath>
10
11constexpr int CELL_SIZE = 100;
12constexpr int AXIS_CELLS = 80;
13constexpr int DEPTH_AXIS_CELLS = 4;
14constexpr int ROW_CELL_SIZE = AXIS_CELLS * CELL_SIZE;
15constexpr int COLUMN_CELL_SIZE = AXIS_CELLS * CELL_SIZE;
16constexpr int DEPTH_CELL_SIZE = DEPTH_AXIS_CELLS * CELL_SIZE;
17
18
20 float numXCells, numYCells, numZCells;
21 float startX, endX, startY, endY, startZ, endZ;
22 float cameraMargin = 0.0f;
23};
24
25class Grid {
26public:
27 enum Level {
28 Basic,
29 Outer1,
30 Outer2
31 };
32
33 Grid(int width, int height, int depth, int cellSize);
34 ~Grid();
35
36 void setSize(int cellSize);
37 void init(int width, int height, int depth, int cellSize);
38
39 void createCells(Grid::Level size);
40
41 void addLink(LinkEntity* link, Grid::Level m_level);
42 std::vector<Cell*> getLinkCells(const LinkEntity& link, Grid::Level m_level);
43 void addLink(LinkEntity* link, std::vector<Cell*> cell);
44
45 void addEmpty(EmptyEntity* entity, Grid::Level m_level);
46
47 void addNode(NodeEntity* entity, Grid::Level m_level);
48 void addEmpty(EmptyEntity* entity, Cell* cell);
49 void addNode(NodeEntity* entity, Cell* cell);
50
51 Cell* getCell(int x, int y, int z, Grid::Level m_level);
52 Cell* getCell(const Entity& position, Grid::Level m_level);
53 std::vector<Cell*> getAdjacentCells(int x, int y, int z, Grid::Level m_level);
54 std::vector<Cell*> getAdjacentCells(const Entity& entity, Grid::Level m_level);
55 std::vector<Cell>& getCells(Grid::Level m_level);
56 int getCellSize();
57 int getNumXCells();
58 int getNumYCells();
59 int getNumZCells();
60
61 bool setIntersectedCameraCells(ICamera& camera);
62
63 std::vector<Cell*> getIntersectedCameraCells(ICamera& camera);
64
65 template <typename T>
66 std::vector<T*> getRevealedEntitiesInCameraCells() {
67 std::vector<T*> result;
68
69 if constexpr (std::is_same_v<T, NodeEntity>) {
70 for (auto& cell : _interceptedCells) {
71 for (auto& entity : cell->nodes) {
72 if (!entity->isHidden()) { // Check if the entity is visible
73 result.push_back(entity);
74 }
75 }
76 }
77 }
78 else if constexpr (std::is_same_v<T, EmptyEntity>) {
79 for (auto& cell : _interceptedCells) {
80 for (auto& entity : cell->emptyEntities) {
81 if (!entity->isHidden()) { // Check if the entity is visible
82 result.push_back(entity);
83 }
84 }
85 }
86 }
87 else if constexpr (std::is_same_v<T, LinkEntity>) {
88 std::map<unsigned int, LinkEntity*> uniqueEntities;
89
90 for (auto& cell : _interceptedCells) {
91 for (auto& link : cell->links) {
92 if (!link->isHidden()) {
93 unsigned int linkId = link->getId();
94
95 if (uniqueEntities.find(linkId) == uniqueEntities.end()) {
96 uniqueEntities[linkId] = link;
97 }
98 }
99 }
100 }
101 for (auto& entry : uniqueEntities) {
102 result.push_back(entry.second);
103 }
104 }
105 else {
106 static_assert(sizeof(T) == 0, "Unsupported entity type.");
107 }
108 return result;
109
110 }
111
112 template <typename T>
113 std::vector<T*> getEntitiesInCameraCells() {
114 std::vector<T*> result;
115
116 if constexpr (std::is_same_v<T, NodeEntity>) {
117 for (auto& cell : _interceptedCells) {
118 result.insert(result.end(), cell->nodes.begin(), cell->nodes.end());
119 }
120 }
121 else if constexpr (std::is_same_v<T, EmptyEntity>) {
122 for (auto& cell : _interceptedCells) {
123 result.insert(result.end(), cell->emptyEntities.begin(), cell->emptyEntities.end());
124 }
125 }
126 else {
127 static_assert(sizeof(T) == 0, "Unsupported entity type.");
128 }
129 return result;
130 }
131
132 std::vector<LinkEntity*> getLinksInCameraCells();
133
134
135 bool gridLevelChanged();
136
137 Level getGridLevel();
138 void setGridLevel(Level newLevel);
139
140 int getLevelCellScale();
141
142 int getLevelCellScale(Level level);
143private:
144 std::vector<Cell*> _interceptedCells;
145
146 std::vector<Cell> _cells;
147 std::vector<Cell> _parentCells;
148 std::vector<Cell> _superParentCells;
149
150 int _cellSize;
151
152 int _width;
153 int _height;
154 int _depth;
155
156 int _numXCells;
157 int _numYCells;
158 int _numZCells;
159
160 // can change between different scenes/managers
161 std::map<Level, GridLevelData> gridLevelsData;
162
163 std::map<Level, int> gridLevels = {
164 {Level::Basic, 1},
165 {Level::Outer1, 2},
166 {Level::Outer2, 4}
167 };
168
169 Level _level = Level::Basic;
170 Level _lastLevel = Level::Basic;
171};
Definition GECSEntity.h:7
Definition GECS.h:140
Definition Grid.h:25
Definition ICamera.h:9
Definition GECSEntity.h:90
Definition GECSEntity.h:43
Definition CellEntity.h:5
Definition Grid.h:19