-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunkmanager.hpp
56 lines (45 loc) · 1.61 KB
/
chunkmanager.hpp
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
#ifndef CHUNKMANAGER_HPP_INCLUDED
#define CHUNKMANAGER_HPP_INCLUDED
#include <cstddef>
#include <cstdint>
#include <unordered_map>
#include <utility>
#include "blockshader.hpp"
#include "chunk.hpp"
#include "texture.hpp"
class ChunkManager /* final */ {
private:
//Chunk m_chunk;
static constexpr int k_chunks_x = 32;
static constexpr int k_chunks_y = 2;
static constexpr int k_chunks_z = 32;
struct Key {
std::int64_t x, y, z;
Key(int new_x, int new_y, int new_z)
: x(new_x),
y(new_y),
z(new_z)
{}
};
friend bool operator==(const Key &, const Key &);
struct Hasher {
std::size_t operator()(const Key &key) const {
/** TODO: IS A BETTER HASH FUNCTION NEEDED? **/
return (((std::hash<std::int32_t>()(key.x) ^
(std::hash<std::int32_t>()(key.y) << 1)) >> 1) ^
(std::hash<std::int32_t>()(key.z) << 1));
}
};
typedef std::unordered_map<Key, Chunk, Hasher> chunk_map_t;
chunk_map_t m_chunks;
public:
ChunkManager(const Texture &tex);
~ChunkManager() {}
ChunkManager(const ChunkManager &) = delete;
ChunkManager & operator=(const ChunkManager &) = delete;
ChunkManager(ChunkManager &&) = delete;
ChunkManager & operator=(ChunkManager &&) = delete;
void draw(BlockShader &shader);
};
bool operator==(const ChunkManager::Key &l, const ChunkManager::Key &r);
#endif // CHUNKMANAGER_HPP_INCLUDED