blob: 2b87a3a14f03ff8ffb89c8d4e07607e89622c780 (
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
|
#pragma once
#include <optional>
#include <unordered_map>
#include "Chunk.hpp"
#include "ChunkIndex.hpp"
#include "Position.hpp"
namespace MC::World {
class ChunkRegistry {
public:
enum class Status {
Empty,
WaitingForGeneration,
NeedsReification,
WaitingForReification,
Damaged,
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 = {};
std::optional<GFX::Mesh> water_mesh = {};
Status get_status() const {
if (status == Status::Done && chunk.value().is_damaged()) { return Status::Damaged; }
return status;
}
void damage() {
// if (status == Status::Done) chunk.value().damage();
// TODO: Properly damage the chunk, notifying the nearby chunks, too.
status = Status::NeedsReification;
}
};
Data& get(ChunkIndex index);
Data& find(Position::BlockWorld pos);
Data& find(Position::World pos);
private:
std::unordered_map<ChunkIndex, Data> m_chunks;
};
}
|