-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChunk.h
48 lines (38 loc) · 917 Bytes
/
Chunk.h
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
#pragma once
#include <cereal/archives/binary.hpp>
#include <cereal/types/unordered_map.hpp>
#include <unordered_map>
#include "XYZ.h"
class Chunk
{
private:
int x, z;
std::unordered_map<XYZ, int, XYZ::Hash> cubeList;
public:
Chunk();
Chunk(int x, int z);
void setXZ(int x, int z) { this->x = x; this->z = z; }
int getX() { return x; };
int getZ() {return z; };
// 加载位于(x,z)的区块
void load();
// 生成位于(x, z)的区块
void generate();
// 保存位于(x,z)的区块
void save();
bool operator==(const Chunk& other) const {
return x == other.x && z == other.z;
}
struct Hash {
std::size_t operator()(const Chunk& chunk) const {
return std::hash<int>()(chunk.x) ^ std::hash<int>()(chunk.z);
}
};
std::unordered_map<XYZ, int, XYZ::Hash> getCubeList();
// 序列化函数
template <class Archive>
void serialize(Archive& archive)
{
archive(cereal::make_nvp("cubeList", cubeList));
}
};