1 #include "generator.hpp"
8 Generator::Generator(const Config &config)
9 : solidNoise(config.solid_seed)
10 , typeNoise(config.type_seed)
11 , stretch(1.0f/config.stretch)
12 , solid_threshold(config.solid_threshold)
20 void Generator::operator ()(Chunk &chunk) const {
21 Chunk::Pos pos(chunk.Position());
22 glm::vec3 coords(pos * Chunk::Extent());
23 for (int z = 0; z < Chunk::Depth(); ++z) {
24 for (int y = 0; y < Chunk::Height(); ++y) {
25 for (int x = 0; x < Chunk::Width(); ++x) {
26 Block::Pos block_pos(x, y, z);
27 glm::vec3 gen_pos = (coords + block_pos) * stretch;
28 float val = OctaveNoise(solidNoise, coords + block_pos, 3, 0.5f, stretch, 2.0f);
29 if (val > solid_threshold) {
30 int type_val = int((typeNoise(gen_pos) + 1.0f) * solids.size()) % solids.size();
31 chunk.SetBlock(block_pos, Block(solids[type_val]));
33 chunk.SetBlock(block_pos, Block(space));
38 unsigned int random = 263167 * pos.x + 2097593 * pos.y + 426389 * pos.z;
39 for (int index = 0; index < Chunk::Size(); ++index) {
40 if (chunk.IsSurface(index)) {
41 random = random * 666649 + 7778777;
42 if ((random % 32) == 0) {
43 chunk.SetBlock(index, Block(light));