1 #include "Generator.hpp"
4 #include "../rand/OctaveNoise.hpp"
11 Generator::Generator(const Config &config) noexcept
12 : solidNoise(config.seed)
13 , typeNoise(config.seed)
14 , stretch(1.0f/config.stretch)
15 , solid_threshold(config.solid_threshold)
16 // TODO: stable dynamic generator configuration
19 , solids({ 1, 4, 7, 10 }) {
24 void Generator::operator ()(Chunk &chunk) const noexcept {
25 Chunk::Pos pos(chunk.Position());
26 glm::vec3 coords(pos * Chunk::Extent());
27 for (int z = 0; z < Chunk::depth; ++z) {
28 for (int y = 0; y < Chunk::height; ++y) {
29 for (int x = 0; x < Chunk::width; ++x) {
30 Block::Pos block_pos(x, y, z);
31 glm::vec3 gen_pos = (coords + block_pos) * stretch;
32 float val = OctaveNoise(solidNoise, coords + block_pos, 3, 0.5f, stretch, 2.0f);
33 if (val > solid_threshold) {
34 int type_val = int((typeNoise(gen_pos) + 1.0f) * solids.size()) % solids.size();
35 chunk.SetBlock(block_pos, Block(solids[type_val]));
37 chunk.SetBlock(block_pos, Block(space));
42 unsigned int random = 263167 * pos.x + 2097593 * pos.y + 426389 * pos.z;
43 for (int index = 0; index < Chunk::size; ++index) {
44 if (chunk.IsSurface(index)) {
45 random = random * 666649 + 7778777;
46 if ((random % 32) == 0) {
47 chunk.SetBlock(index, Block(light));