Skip to content

Commit 1dab358

Browse files
clean up code
1 parent a45ba02 commit 1dab358

File tree

6 files changed

+9
-87
lines changed

6 files changed

+9
-87
lines changed

chunk/Chunk.cpp

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
#include "../structures/Rock.h"
1414
#include "../structures/Cloud.h"
1515
#include "../structures/SnowFlake.h"
16-
17-
//#include "../biome/BiomeType.h"
18-
1916
#include "../main.h"
2017

2118
using namespace std;
@@ -123,81 +120,65 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
123120
if (k <= height) {
124121
int water_level = 7;
125122

126-
127123
if (k <= water_level) {
128124
this->blocks[i][water_level][j] = WATER;
129125
} else {
130-
131126
this->blocks[i][k][j] = this->biome->ground;
127+
string key;
132128

133-
134-
std::string key;
135-
136-
key = std::to_string(this->x + 1) + "_" + std::to_string(this->z);
129+
key = to_string(this->x + 1) + "_" + to_string(this->z);
137130
if (worldPtr->chunks.count(key) > 0) {
138131
if (this->biome != worldPtr->chunks[key]->biome) {
139132
int random_number = rand() % 100;
140-
141133
int prob_actual_next_ground = 0;
134+
142135
if (i == CHUNK_SIZE - 1) prob_actual_next_ground = 80;
143136
if (i == CHUNK_SIZE - 2) prob_actual_next_ground = 20;
144-
//if (i == 2) prob_actual_next_ground = 60;
145-
//if (i == 3) prob_actual_next_ground = 80;
146-
147137
if (random_number < prob_actual_next_ground) {
148138
this->blocks[i][k][j] = worldPtr->chunks[key]->biome->ground;
149139
}
150140
}
151141
}
152142

153143

154-
key = std::to_string(this->x) + "_" + std::to_string(this->z + 1);
144+
key = to_string(this->x) + "_" + to_string(this->z + 1);
155145
if (worldPtr->chunks.count(key) > 0) {
156146
if (this->biome != worldPtr->chunks[key]->biome) {
157147
int random_number = rand() % 100;
158-
159148
int prob_actual_next_ground = 0;
149+
160150
if (j == CHUNK_SIZE - 1) prob_actual_next_ground = 80;
161151
if (j == CHUNK_SIZE - 2) prob_actual_next_ground = 20;
162-
//if (j == 2) prob_actual_next_ground = 60;
163-
//if (j == 3) prob_actual_next_ground = 80;
164-
165152
if (random_number < prob_actual_next_ground) {
166153
this->blocks[i][k][j] = worldPtr->chunks[key]->biome->ground;
167154
}
168155
}
169156
}
170157

171158

172-
key = std::to_string(this->x - 1) + "_" + std::to_string(this->z);
159+
key = to_string(this->x - 1) + "_" + to_string(this->z);
173160
if (worldPtr->chunks.count(key) > 0) {
174161
if (this->biome != worldPtr->chunks[key]->biome) {
175162
int random_number = rand() % 100;
176-
177163
int prob_actual_next_ground = 0;
164+
178165
if (i == 0) prob_actual_next_ground = 80;
179166
if (i == 1) prob_actual_next_ground = 20;
180-
//if (i == CHUNK_SIZE - 3) prob_actual_next_ground = 60;
181-
//if (i == CHUNK_SIZE - 4) prob_actual_next_ground = 80;
182-
183167
if (random_number < prob_actual_next_ground) {
184168
this->blocks[i][k][j] = worldPtr->chunks[key]->biome->ground;
185169
}
186170
}
187171
}
188172

189173

190-
key = std::to_string(this->x) + "_" + std::to_string(this->z - 1);
174+
key = to_string(this->x) + "_" + to_string(this->z - 1);
191175
if (worldPtr->chunks.count(key) > 0) {
192176
if (this->biome != worldPtr->chunks[key]->biome) {
193177
int random_number = rand() % 100;
194-
195178
int prob_actual_next_ground = 0;
179+
196180
if (j == 0) prob_actual_next_ground = 80;
197181
if (j == 1) prob_actual_next_ground = 20;
198-
//if (j == CHUNK_SIZE - 3) prob_actual_next_ground = 60;
199-
//if (j == CHUNK_SIZE - 4) prob_actual_next_ground = 80;
200-
201182
if (random_number < prob_actual_next_ground) {
202183
this->blocks[i][k][j] = worldPtr->chunks[key]->biome->ground;
203184
}
@@ -208,31 +189,15 @@ Chunk::Chunk(int chunk_x, int chunk_z, BiomeType *biome) {
208189
}
209190

210191
int snow_level_min = 23;
211-
//int snow_progress = 15;
212-
213-
214-
//int snow = (rand() % (k+1) - snow_level_min) * snow_progress;
215192

216193
if (k > snow_level_min + 3 * sin(0.1 * (i + j))) {
217194
this->blocks[i][k][j] = SNOW;
218195
}
219-
220-
221-
// DEBUG
222-
// if (i == 0 || j == 0) {
223-
// this->blocks[i][k][j] = GROUND;
224-
// }
225-
226-
227-
228-
229196
} else {
230197
if (this->blocks[i][k][j] != WATER) {
231198
this->blocks[i][k][j] = AIR;
232199
}
233200
}
234-
235-
236201
}
237202
}
238203
}

chunk/Chunk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Chunk {
2121

2222
int blocks[CHUNK_SIZE][CHUNK_HEIGHT][CHUNK_SIZE];
2323
int heights[CHUNK_SIZE][CHUNK_SIZE];
24-
//BiomeType biome;
2524

2625
Chunk(int chunk_x, int chunk_z, BiomeType *biome);
2726

main.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ void display() {
4040
playerPtr->takeAction();
4141
playerPtr->camera.refresh(light);
4242

43-
/**
44-
* TODO: Getter for the player position
45-
*/
4643
worldPtr->update(playerPtr->camera.camera_x, playerPtr->camera.camera_z);
4744

4845
playerPtr->camera.idle(sin((float) count++ / 40), 0);

structures/Rock.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
Rock::Rock(int x, int y, int z, Chunk *chunk) {
1111

12-
1312
int proba = 10;
1413
int proba_mount = 30;
1514

@@ -18,16 +17,12 @@ Rock::Rock(int x, int y, int z, Chunk *chunk) {
1817

1918
int random_number = rand() % 100;
2019
if (random_number < proba) {
21-
22-
2320
chunk->blocks[x + i][chunk->heights[x + i][z + j] + 1][z + j] = ROCK;
2421
int random_number = rand() % 100;
2522
if (random_number < proba_mount) {
2623
chunk->blocks[x + i][chunk->heights[x + i][z + j] + 2][z + j] = ROCK;
2724
}
28-
2925
}
3026
}
3127
}
32-
3328
}

structures/Tree.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Tree::Tree(int x, int y, int z, Chunk *chunk) {
2525

2626

2727
int radius_tree = MIN_RADIUS_TREE + rand() % (MAX_RADIUS_TREE - MIN_RADIUS_TREE);
28-
2928
int texture = this->chooseTexture();
3029

3130
for (int i = -radius_tree + 1; i <= radius_tree - 1; i++) {

world/World.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ BiomeType *World::chooseChunkBiome(int chunk_x, int chunk_y) {
109109

110110
// For the first chunk
111111
if (this->biomes.empty()) {
112-
// auto it = this->biome_types.begin();
113-
// advance(it, rand() % this->biome_types.size());
114-
// string key = it->first;
115-
//
116-
117112
// Force desert because the biome is cool
118113
string key = "desert";
119114

@@ -153,19 +148,13 @@ BiomeType *World::chooseChunkBiome(int chunk_x, int chunk_y) {
153148
return this->biome_types[*it];
154149
}
155150

156-
157151
return best_distance_biome.type;
158-
159-
160152
}
161153

162154
vector<Chunk *> World::getNeighborsChunks(int x, int z) {
163155

164-
165156
vector<Chunk *> neighbors;
166157

167-
//cout << "BIOMES NEIGHBORS" << endl;
168-
169158
for (int i = -1; i <= 1; ++i) {
170159
for (int j = -1; j <= 1; ++j) {
171160
if (i != 0 && j != 0) {
@@ -177,37 +166,16 @@ vector<Chunk *> World::getNeighborsChunks(int x, int z) {
177166
}
178167
}
179168

180-
181-
// if (this->chunks.count(key) > 0) {
182-
// chunk = this->chunks[key];
183-
// } else {
184-
// chunk = this->generateChunk(chunk_x, chunk_y);
185-
// this->chunks[key] = chunk;
186-
// }
187-
//
188-
//
189-
// string key = to_string(chunk_x) + "_" + to_string(chunk_y);
190-
191-
192169
return vector<Chunk *>();
193170
}
194171

195172
void World::initializeBiomes() {
196173

197-
198174
this->biome_types["prairie"] = new BiomeType();
199175
this->biome_types["prairie"]->id = "prairie";
200176
this->biome_types["prairie"]->ground = GRASS;
201177
this->biome_types["prairie"]->tree_frequency = 0.02;
202178

203-
204-
// this->biome_types["icy"] = new BiomeType();
205-
// this->biome_types["icy"]->ground = SNOW;
206-
207-
// this->biome_types["forest"] = new BiomeType();
208-
// this->biome_types["forest"]->ground = GRASS;
209-
// this->biome_types["forest"]->tree_frequency = 0.1;
210-
211179
this->biome_types["desert"] = new BiomeType();
212180
this->biome_types["desert"]->id = "desert";
213181
this->biome_types["desert"]->ground = SAND;
@@ -218,5 +186,4 @@ void World::initializeBiomes() {
218186
this->biome_types["mountain"]->id = "mountain";
219187
this->biome_types["mountain"]->ground = GRASS;
220188
this->biome_types["mountain"]->rock_frequency = 0.05;
221-
222189
}

0 commit comments

Comments
 (0)