summaryrefslogtreecommitdiffstats
path: root/game/server/world/overworld.hh
blob: f3fc8cfc52eaf707235cf12d2d944aa80efa9bea (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include "core/config/number.hh"

#include "core/io/config_map.hh"

#include "shared/world/dimension.hh"
#include "shared/world/feature.hh"

#include "shared/const.hh"

constexpr static unsigned int OW_NUM_TREES = 4U;

namespace world
{
struct Overworld_Metadata final {
    world::dimension_entropy_map entropy;
    world::dimension_height_map heightmap;
    std::vector<local_pos> trees;
};
} // namespace world

namespace world
{
class Overworld final : public Dimension {
public:
    explicit Overworld(std::string_view name);
    virtual ~Overworld(void) = default;

public:
    virtual void init(io::ConfigMap& config) override;
    virtual void init_late(std::uint64_t global_seed) override;
    virtual bool generate(const chunk_pos& cpos, VoxelStorage& voxels) override;

private:
    bool is_inside_cave(const voxel_pos& vpos);
    bool is_inside_terrain(const voxel_pos& vpos);

private:
    const Overworld_Metadata& get_or_create_metadata(const chunk_pos_xz& cpos);

private:
    void generate_terrain(const chunk_pos& cpos, VoxelStorage& voxels);
    void generate_surface(const chunk_pos& cpos, VoxelStorage& voxels);
    void generate_caves(const chunk_pos& cpos, VoxelStorage& voxels);
    void generate_features(const chunk_pos& cpos, VoxelStorage& voxels);

private:
    config::Int m_terrain_variation;
    config::Int m_bottommost_chunk;

private:
    emhash8::HashMap<chunk_pos_xz, Overworld_Metadata> m_metamap;

private:
    fnl_state m_fnl_variation;
    fnl_state m_fnl_terrain;
    fnl_state m_fnl_caves_a;
    fnl_state m_fnl_caves_b;
    fnl_state m_fnl_nvdi;

private:
    Feature m_feat_tree[OW_NUM_TREES];

private:
    std::mutex m_mutex;
};
} // namespace world