summary refs log tree commit diff
path: root/src/World/Generator.cpp
blob: e8b3bbde8920d01b1bb82771b2c8d6aab557b7be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Generator.hpp"
#include "../Math/Perlin.hpp"

namespace MC::World {

Chunk Generator::generate(int64_t chunk_x, int64_t chunk_y) {
    Chunk chunk(chunk_x, chunk_y);

    Math::Perlin::Noise<3> noise{.scale=20.0f, .octaves=2};

    for (uint x = 0; x < Chunk::Width; x++) {
        for (uint z = 0; z < Chunk::Width; z++) {
            for (uint y = 0; y < Chunk::Height; y++) {
                auto value = noise.at({
                    (float)(chunk_x * Chunk::Width + x),
                    (float)y,
                    (float)(chunk_y * Chunk::Width + z),
                });

                if (value > 0.6f && value < 0.7f) {
                    chunk.set(x, y, z, {BlockType::Stone});
                }
            }
        }
    }

    return chunk;
}

}