More world generators support

This commit is contained in:
Onran
2024-02-21 11:54:10 +09:00
committed by GitHub
parent 399bd9c362
commit 9cc2f93cfd
9 changed files with 209 additions and 30 deletions
+28
View File
@@ -0,0 +1,28 @@
#include "FlatWorldGenerator.h"
#include "voxel.h"
#include "Chunk.h"
#include "../content/Content.h"
#include "../core_defs.h"
void FlatWorldGenerator::generate(voxel* voxels, int cx, int cz, int seed) {
for (int z = 0; z < CHUNK_D; z++) {
for (int x = 0; x < CHUNK_W; x++) {
for (int cur_y = 0; cur_y < CHUNK_H; cur_y++){
int id = BLOCK_AIR;
int states = 0;
if(cur_y == 2) {
id = idBazalt;
} else if(cur_y == 6) {
id = idGrassBlock;
} else if(cur_y > 2 && cur_y <= 5) {
id = idDirt;
}
voxels[(cur_y * CHUNK_D + z) * CHUNK_W + x].id = id;
voxels[(cur_y * CHUNK_D + z) * CHUNK_W + x].states = states;
}
}
}
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef VOXELS_FLATWORLDGENERATOR_H_
#define VOXELS_FLATWORLDGENERATOR_H_
#include "../typedefs.h"
#include "../voxels/WorldGenerator.h"
struct voxel;
class Content;
class FlatWorldGenerator : WorldGenerator {
public:
FlatWorldGenerator(const Content* content) : WorldGenerator(content) {}
void generate(voxel* voxels, int x, int z, int seed) override;
};
#endif /* VOXELS_FLATWORLDGENERATOR_H_ */
+3 -2
View File
@@ -7,6 +7,7 @@ struct voxel;
class Content;
class WorldGenerator {
protected:
blockid_t const idStone;
blockid_t const idDirt;
blockid_t const idGrassBlock;
@@ -19,7 +20,7 @@ class WorldGenerator {
blockid_t const idBazalt;
public:
WorldGenerator(const Content* content);
void generate(voxel* voxels, int x, int z, int seed);
virtual void generate(voxel* voxels, int x, int z, int seed);
};
#endif /* VOXELS_WORLDGENERATOR_H_ */
#endif /* VOXELS_WORLDGENERATOR_H_ */