@@ -26,16 +26,20 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
26
26
27
27
*****************************************************/
28
28
29
- vector<vector<vector<int >>> gridMap (
30
- depth, vector<vector<int >>(width, vector<int >(height, 0 )));
31
-
29
+ // Raw Noise -> Stored for possible random value use
32
30
vector<vector<float >> rawNoise (width, vector<float >(height, 0 ));
33
- vector<vector<int >> elevationMap (width, vector<int >(height, 0 ));
31
+ // Data Grid -> Simply an Elevation Map double the size of our Render Grid
32
+ vector<vector<int >> elevationMap (width * 2 , vector<int >(height * 2 , 0 ));
33
+ // Render Grid
34
34
vector<vector<TileType>> tileMap (width, vector<TileType>(height, GROUND));
35
35
36
+ // Produce a 2x Grid for the Data Grid
37
+ int widthx2 = width * 2 ;
38
+ int heightx2 = height * 2 ;
39
+
36
40
int blockSize = 4 ;
37
- int reducedX = floor (width / blockSize);
38
- int reducedY = floor (height / blockSize);
41
+ int reducedX = floor (widthx2 / blockSize);
42
+ int reducedY = floor (heightx2 / blockSize);
39
43
vector<vector<int >> lowResMap (reducedX, vector<int >(reducedY, 0 ));
40
44
41
45
int dx[4 ] = { 1 , -1 , 0 , 0 };
@@ -48,8 +52,8 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
48
52
*****************************************************/
49
53
50
54
// Generate the Elevation Map
51
- for (int x = 0 ; x < width ; x++) {
52
- for (int y = 0 ; y < height ; y++) {
55
+ for (int x = 0 ; x < widthx2 ; x++) {
56
+ for (int y = 0 ; y < heightx2 ; y++) {
53
57
float currentNoise = noise->get_noise_2d ((float )x, (float )y);
54
58
55
59
rawNoise[x][y] = currentNoise;
@@ -78,8 +82,8 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
78
82
}
79
83
80
84
// Upscale back to Original Size
81
- for (int x = 0 ; x < width ; x++) {
82
- for (int y = 0 ; y < height ; y++) {
85
+ for (int x = 0 ; x < widthx2 ; x++) {
86
+ for (int y = 0 ; y < heightx2 ; y++) {
83
87
int srcX = x / blockSize;
84
88
int srcY = y / blockSize;
85
89
@@ -99,8 +103,8 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
99
103
// TODO...
100
104
101
105
// Water Clean Up
102
- for (int x = 1 ; x < width - 1 ; x++) {
103
- for (int y = 1 ; y < height - 1 ; y++) {
106
+ for (int x = 1 ; x < widthx2 - 1 ; x++) {
107
+ for (int y = 1 ; y < heightx2 - 1 ; y++) {
104
108
if (elevationMap[x][y] > 0 ) { // Check if it's an elevated tile
105
109
int waterCount = 0 ;
106
110
@@ -130,11 +134,147 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
130
134
// Loop over all the grid cells
131
135
for (int x = 0 ; x < width; ++x) {
132
136
for (int y = 0 ; y < height; ++y) {
133
- // Get the elevation for the current grid cell
134
- int elevation = elevationMap[x][y];
137
+ // Godot GridMap Tile Rotation
138
+ //
139
+ // North = 0; // No rotation
140
+ // South = 16;
141
+ // East = 10;
142
+ // West = 22;
143
+ //
144
+ int tilesRotation = 0 ;
145
+
146
+ //
147
+ // +----+----+
148
+ // | n1 | n2 |
149
+ // +----+----+
150
+ // | n3 | n4 |
151
+ // +----+----+
152
+ //
153
+ // Get the surrounding DataGrid Neighbors overlap of the Render Grid
154
+ int n1 = elevationMap[y][x];
155
+ int n2 = elevationMap[y][x + 1 ];
156
+ int n3 = elevationMap[y + 1 ][x];
157
+ int n4 = elevationMap[y + 1 ][x + 1 ];
158
+
159
+ // Determine Elevation Changes
160
+ //
161
+ // Elevation change needs to be known in Left, Right, Up, & Down
162
+ // due to the determination of a tiles type and rotation
163
+ //
164
+ // ! Unneeded due to the simpler way of just using neighbor values
165
+ //
166
+ // bool change1right = n1 < n2; // n1 -> n2
167
+ // bool change3down = n1 < n3; // n1 -> n3
168
+ // bool change3right = n3 < n4; // n3 -> n4
169
+ // bool change4down = n2 < n4; // n2 -> n4
170
+
171
+ // bool change1left = n1 > n2; // n1 -> n2
172
+ // bool change2up = n1 > n3; // n1 -> n3
173
+ // bool change3left = n3 > n4; // n3 -> n4
174
+ // bool change4up = n2 > n4; // n2 -> n4
175
+
176
+ // Water's Water
177
+ // +---+---+
178
+ // | 0 | 0 |
179
+ // +---+---+
180
+ // | 0 | 0 |
181
+ // +---+---+
182
+ //
183
+ if (n1 == 0 && n2 == 0 && n3 == 0 && n4 == 0 ) {
184
+ tileMap[x][y] = WATER;
185
+ }
186
+
187
+ // Ground's Ground
188
+ // +----+----+ +---+---+ +---+---+
189
+ // | n1 | n2 | | 1 | 1 | | 2 | 2 |
190
+ // +----+----+ +---+---+ +---+---+
191
+ // | n3 | n4 | | 1 | 1 | | 2 | 2 |
192
+ // +----+----+ +---+---+ +---+---+
193
+ //
194
+ if (n1 == n2 && n2 == n3 && n3 == 4 && n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 ) {
195
+ tileMap[x][y] = GROUND;
196
+ }
197
+
198
+ // Water's Edge South
199
+ // +----+----+ +---+---+
200
+ // | n1 | n2 | | 0 | 0 |
201
+ // +----+----+ +---+---+
202
+ // | n3 | n4 | | 1 | 1 |
203
+ // +----+----+ +---+---+
204
+ //
205
+ if (n1 == 0 && n2 == 0 && n3 > 0 && n4 > 0 ) {
206
+ tileMap[x][y] = WATER_EDGE;
207
+ tilesRotation = 16 ; // Facing South
208
+ }
209
+ // Water's Edge North
210
+ // +----+----+ +---+---+
211
+ // | n1 | n2 | | 1 |1 |
212
+ // +----+----+ +---+---+
213
+ // | n3 | n4 | | 0 | 0 |
214
+ // +----+----+ +---+---+
215
+ //
216
+ else if (n1 > 0 && n2 > 0 && n3 == 0 && n4 == 0 ) {
217
+ tileMap[x][y] = WATER_EDGE;
218
+ tilesRotation = 0 ; // Facing North
219
+ }
220
+ // Water's Edge East
221
+ // +----+----+ +---+---+
222
+ // | n1 | n2 | | 0 | 1 |
223
+ // +----+----+ +---+---+
224
+ // | n3 | n4 | | 0 | 1 |
225
+ // +----+----+ +---+---+
226
+ //
227
+ else if (n1 == 0 && n3 == 0 && n2 > 0 && n4 > 0 ) {
228
+ tileMap[x][y] = WATER_EDGE;
229
+ tilesRotation = 10 ; // Facing East
230
+
231
+ }
232
+ // Water's Edge West
233
+ // +----+----+ +---+---+
234
+ // | n1 | n2 | | 1 | 0 |
235
+ // +----+----+ +---+---+
236
+ // | n3 | n4 | | 1 | 0 |
237
+ // +----+----+ +---+---+
238
+ //
239
+ else if (n2 == 0 && n4 == 0 && n1 > 0 && n3 > 0 ) {
240
+ tileMap[x][y] = WATER_EDGE;
241
+ tilesRotation = 22 ; // Facing West
242
+ }
243
+
244
+ // Water's Corner's
245
+ if (n1 == 0 && n2 == 0 && n3 == 0 && n4 > 0 ) {
246
+ tileMap[x][y] = WATER_CORNER; // Land in SE
247
+ } else if (n1 > 0 && n2 == 0 && n3 == 0 && n4 == 0 ) {
248
+ tileMap[x][y] = WATER_CORNER; // Land in NW
249
+ }
250
+
251
+ // Cliff's Edge
252
+ // +----+----+ +---+---+
253
+ // | n1 | n2 | | 2 | 1 |
254
+ // +----+----+ +---+---+
255
+ // | n3 | n4 | | 2 | 1 |
256
+ // +----+----+ +---+---+
257
+ //
258
+ // TODO : Determine the way of choosing between cliffs and ramps
259
+ if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 ) {
260
+ tileMap[x][y] = CLIFF;
261
+ }
262
+
263
+ // Cliff's Edge
264
+ // +----+----+ +---+---+
265
+ // | n1 | n2 | | 2 | 1 |
266
+ // +----+----+ +---+---+
267
+ // | n3 | n4 | | 2 | 1 |
268
+ // +----+----+ +---+---+
269
+ //
270
+ // TODO : Determine the way of choosing between cliffs and ramps
271
+ if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 && n1 > n2 && n3 > n4) {
272
+ tileMap[x][y] = CLIFF;
273
+ }
274
+
275
+ // TODO : Add rest of the logic for all tile types
135
276
136
- // Init the current grid cell to ground
137
- tileMap[x][y] = GROUND;
277
+ // TODO : Remove unneeded Code below
138
278
139
279
// Setup booleans & Ints
140
280
bool needsRamp = false , needsCliff = false , adjacentToWater = false ;
0 commit comments