]> git.localhorst.tv Git - blank.git/blob - src/world/Generator.hpp
fix entity/world collision
[blank.git] / src / world / Generator.hpp
1 #ifndef BLANK_WORLD_GENERATOR_HPP_
2 #define BLANK_WORLD_GENERATOR_HPP_
3
4 #include "../rand/SimplexNoise.hpp"
5
6 #include <cstdint>
7 #include <vector>
8 #include <glm/glm.hpp>
9
10
11 namespace blank {
12
13 class Block;
14 class BlockType;
15 class BlockTypeRegistry;
16 class Chunk;
17
18 class Generator {
19
20 public:
21         struct Config {
22                 std::uint64_t seed = 0;
23                 struct NoiseParam {
24                         std::uint64_t seed_mask;
25                         int octaves;
26                         float persistence;
27                         float frequency;
28                         float amplitude;
29                         float growth;
30                 };
31                 NoiseParam solidity = { 0xA85033F6BCBDD110, 3, 0.5f, 1.0f/64.0f, 2.0f, 2.0f };
32                 NoiseParam humidity = { 0x3A463FB24B04A901, 2, 0.5f, 1.0f/512.0f, 2.0f, 2.0f };
33                 NoiseParam temperature = { 0x2530BA6C6134A9FB, 2, 0.5f, 1.0f/1024.0f, 2.0f, 2.0f };
34                 NoiseParam richness = { 0x95A179F180103446, 3, 0.5f, 1.0f/128.0f, 2.0f, 2.0f };
35                 NoiseParam randomness = { 0x074453EEE1496390, 3, 0.5f, 1.0f/16.0f, 2.0f, 2.0f };
36         };
37
38         explicit Generator(const Config &) noexcept;
39
40         void LoadTypes(const BlockTypeRegistry &);
41
42         void operator ()(Chunk &) const noexcept;
43
44 private:
45         Block Generate(const glm::vec3 &position) const noexcept;
46         static float GetValue(
47                 const SimplexNoise &,
48                 const glm::vec3 &,
49                 const Config::NoiseParam &) noexcept;
50
51 private:
52         const Config &config;
53         std::vector<const BlockType *> types;
54         float min_solidity;
55
56         SimplexNoise solidity_noise;
57         SimplexNoise humidity_noise;
58         SimplexNoise temperature_noise;
59         SimplexNoise richness_noise;
60         SimplexNoise random_noise;
61
62 };
63
64 }
65
66 #endif