X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FGenerator.cpp;fp=src%2Fworld%2FGenerator.cpp;h=c49dce17bf153d15bdc7dd12360254b2d86d137a;hb=b7d09e1e35ef90282c97509e0020b20db3c7ea9f;hp=0000000000000000000000000000000000000000;hpb=e53a0e2e711a7d8bd9b0ddacd1360aa14370643f;p=blank.git diff --git a/src/world/Generator.cpp b/src/world/Generator.cpp new file mode 100644 index 0000000..c49dce1 --- /dev/null +++ b/src/world/Generator.cpp @@ -0,0 +1,54 @@ +#include "Generator.hpp" + +#include "Chunk.hpp" +#include "../rand/OctaveNoise.hpp" + +#include + + +namespace blank { + +Generator::Generator(const Config &config) noexcept +: 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 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); + 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.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(); +} + +}