X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgenerator.cpp;h=373374fa45447fa17daaf0f58ac356c4af589795;hb=38abfe4f5342f20b56052ac3090694eabf028d16;hp=10cb668c9cfb491681987501fe8a0f68199f6683;hpb=8acc3f990f1a5ee00471f72c150b407164149f2d;p=blank.git diff --git a/src/generator.cpp b/src/generator.cpp index 10cb668..373374f 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -5,34 +5,47 @@ namespace blank { -Generator::Generator(unsigned int seed) -: solidNoise(seed) -, typeNoise(seed + 1) -, stretch(64.0f) -, solid_threshold(0.8f) +Generator::Generator(const Config &config) +: solidNoise(config.solid_seed) +, typeNoise(config.type_seed) +, stretch(1.0f/config.stretch) +, solid_threshold(config.solid_threshold) +, space(0) +, light(0) , solids() { } void Generator::operator ()(Chunk &chunk) const { - chunk.Allocate(); Chunk::Pos pos(chunk.Position()); glm::vec3 coords(pos * Chunk::Extent()); for (int z = 0; z < Chunk::Depth(); ++z) { for (int y = 0; y < Chunk::Height(); ++y) { for (int x = 0; x < Chunk::Width(); ++x) { Block::Pos block_pos(x, y, z); - glm::vec3 gen_pos = (coords + block_pos) / stretch; - float val = solidNoise(gen_pos); + glm::vec3 gen_pos = (coords + block_pos) * stretch; + float val = OctaveNoise(solidNoise, coords + block_pos, 3, 0.5f, stretch, 2.0f); if (val > solid_threshold) { int type_val = int((typeNoise(gen_pos) + 1.0f) * solids.size()) % solids.size(); - chunk.BlockAt(block_pos) = Block(solids[type_val]); + chunk.SetBlock(block_pos, Block(solids[type_val])); + } else { + chunk.SetBlock(block_pos, Block(space)); } } } } + unsigned int random = 263167 * pos.x + 2097593 * pos.y + 426389 * pos.z; + for (int index = 0; index < Chunk::Size(); ++index) { + if (chunk.IsSurface(index)) { + random = random * 666649 + 7778777; + if ((random % 32) == 0) { + chunk.SetBlock(index, Block(light)); + } + } + } chunk.Invalidate(); + chunk.CheckUpdate(); } }