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

#include <optional>
#include <unordered_map>
#include "Chunk.hpp"
#include "ChunkIndex.hpp"
#include "Position.hpp"
#include "../GFX/Binder.hpp"

namespace MC::World {

class ChunkRegistry {
public:
    enum class Status {
        Empty,
        WaitingForGeneration,
        WaitingForReification,
        Done
    };

    // I think a Chunk entity should just store all this by itself...
    struct Data {
        ChunkIndex index;
        Status status;
        std::optional<Chunk> chunk = {};

        std::optional<GFX::Mesh> land_mesh_data = {};
        std::optional<GFX::Mesh> water_mesh_data = {};

        std::optional<GFX::BindableMesh> land_mesh = {};
        std::optional<GFX::BindableMesh> water_mesh = {};
    };

    Data& get(ChunkIndex index);

    Data& find(Position::BlockWorld pos);
    Data& find(ChunkIndex chunk, Position::BlockLocal pos);
private:
    std::unordered_map<ChunkIndex, Data> m_chunks;
};

}