X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FGenerator.cpp;h=edb7e9caa51bc879ec7181c66153710dc5e24a34;hb=b94a7dc7daad9ae9be90a39d723e332dae375325;hp=88ac1eb674b0c24b5449f206694d0f70043145c4;hpb=9240fdf2e68ee014da0d0a89a7fb2f29ebf28e2d;p=blank.git diff --git a/src/world/Generator.cpp b/src/world/Generator.cpp index 88ac1eb..edb7e9c 100644 --- a/src/world/Generator.cpp +++ b/src/world/Generator.cpp @@ -50,13 +50,13 @@ void Generator::LoadTypes(const BlockTypeRegistry ®) { } void Generator::operator ()(Chunk &chunk) const noexcept { - 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); - chunk.SetBlock(block_pos, Generate(coords + block_pos)); + ExactLocation::Coarse pos(chunk.Position()); + ExactLocation::Fine coords(pos * ExactLocation::Extent()); + for (int z = 0; z < Chunk::side; ++z) { + for (int y = 0; y < Chunk::side; ++y) { + for (int x = 0; x < Chunk::side; ++x) { + ExactLocation::Fine block_pos(x, y, z); + chunk.SetBlock(RoughLocation::Fine(x, y, z), Generate(coords + ExactLocation::Fine(x, y, z))); } } } @@ -91,6 +91,8 @@ Block Generator::Generate(const glm::vec3 &pos) const noexcept { return Block(0); } float random = GetValue(random_noise, pos, config.randomness); + // as weird as it sounds, but this is faster tham glm::fract and generates a + // better distribution than (transformed variants of) erf, erfc, atan, and smoothstep if (random < 0.0f) random += 1.0f; float value = random * total; // TODO: change to binary search