-void World::Generate(Chunk &chunk) {
- chunk.Allocate();
- Chunk::Pos pos(chunk.Position());
- glm::vec3 coords(pos * Chunk::Extent());
- if (pos.x == 0 && pos.y == 0 && pos.z == 0) {
- for (size_t i = 1; i < blockType.Size(); ++i) {
- chunk.BlockAt(i) = Block(blockType[i]);
- chunk.BlockAt(i + 257) = Block(blockType[i]);
- chunk.BlockAt(i + 514) = Block(blockType[i]);
- }
- } else {
- 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{float(x), float(y), float(z)};
- glm::vec3 gen_pos = (coords + block_pos) / 64.0f;
- float val = blockNoise(gen_pos);
- if (val > 0.8f) {
- int col_val = int((colorNoise(gen_pos) + 1.0f) * 2.0f) % 4;
- chunk.BlockAt(block_pos) = Block(blockType[col_val * 3 + 1]);
- }
- }
- }
- }
- }
- chunk.Invalidate();
-}
-