summary refs log tree commit diff
path: root/src/World/Chunk.hpp
blob: bc441378a14272e73f4dba9fa580df51d526cc58 (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
#pragma once

#include "../Common/Sizes.hpp"
#include "BiomeType.hpp"
#include "BlockType.hpp"
#include "../GFX/Mesh.hpp"
#include "BlockSide.hpp"

namespace MC::World {

class Chunk {
public:
    static constexpr U32 Width = 16;
    static constexpr U32 Height = 128;

    Chunk(I64 x, I64 y)
        : m_blocks{Width * Height * Width, {BlockType::Air}},
        m_position{(Real)x * Width, 0.0f, (Real)y * Width} {}

    struct BlockData {
        BlockType type;

        Bool empty() const { return type == BlockType::Air; }
    };

    void set(U32 x, U32 y, U32 z, BlockData data);
    BlockData get(U32 x, U32 y, U32 z) const;
    Bool is_empty(U32 x, U32 y, U32 z) const;

    struct Details {
        Matrix<Width, Width> landmass_values{};
        Matrix<Width, Width> hill_values{};

        Matrix<Width, Width> temperature_values{};
        Matrix<Width, Width> humidity_values{};

        Matrix<Width, Width, BiomeType> biome_values{};
    };
    void set_details(const Details& details) { m_details = details; }
    Details& details(){ return m_details; }

    Vector<3> position() const;

    static Bool is_valid_position(U32 x, U32 y, U32 z);
private:
    static U64 pos(U32 x, U32 y, U32 z);

    Vector<3> m_position;
    std::vector<BlockData> m_blocks;

    Details m_details;
};

}