-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunkmanager.cpp
86 lines (78 loc) · 3.01 KB
/
chunkmanager.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "chunkmanager.hpp"
#include "worldgenerator.hpp"
#include <iostream>
ChunkManager::ChunkManager(const Texture &tex) {
/** TODO: VERY TEMPORARY **/
/*
{
auto result = m_chunks.emplace(std::piecewise_construct,
std::forward_as_tuple(0, -1, 0), std::forward_as_tuple());
if(result.second) {
std::cout << "result.second" << std::endl;
wg::generate(result.first->second, 0, -1, 0);
result.first->second.generateGeometry(tex, 0, -1, 0);
} else {
std::cout << "!result.second" << std::endl;
}
}
{
auto result = m_chunks.emplace(std::piecewise_construct,
std::forward_as_tuple(0, 0, 0), std::forward_as_tuple());
if(result.second) {
std::cout << "result.second" << std::endl;
wg::generate(result.first->second, 0, 0, 0);
result.first->second.generateGeometry(tex, 0, 0, 0);
} else {
std::cout << "!result.second" << std::endl;
}
}
{
auto result = m_chunks.emplace(std::piecewise_construct,
std::forward_as_tuple(0, 1, 0), std::forward_as_tuple());
if(result.second) {
std::cout << "result.second" << std::endl;
wg::generate(result.first->second, 0, 1, 0);
result.first->second.generateGeometry(tex, 0, 1, 0);
} else {
std::cout << "!result.second" << std::endl;
}
}
{
auto result = m_chunks.emplace(std::piecewise_construct,
std::forward_as_tuple(0, 2, 0), std::forward_as_tuple());
if(result.second) {
std::cout << "result.second" << std::endl;
wg::generate(result.first->second, 0, 2, 0);
result.first->second.generateGeometry(tex, 0, 2, 0);
} else {
std::cout << "!result.second" << std::endl;
}
}
*/
//The loop counters are in chunk coords.
/*
for(int cx = -k_chunks_x / 2; cx < k_chunks_x / 2; ++cx) {
for(int cy = -k_chunks_y / 2; cy < k_chunks_y / 2; ++cy) {
for(int cz = -k_chunks_z / 2; cz < k_chunks_z / 2; ++cz) {
*/
for(int cx = 0; cx < k_chunks_x; ++cx) {
for(int cy = 0; cy < k_chunks_y; ++cy) {
for(int cz = 0; cz < k_chunks_z; ++cz) {
auto result = m_chunks.emplace(std::piecewise_construct,
std::forward_as_tuple(cx, cy, cz),
std::forward_as_tuple());
wg::generate(result.first->second, cx, cy, cz);
result.first->second.generateGeometry(tex, cx, cy, cz);
}
}
}
}
void ChunkManager::draw(BlockShader &shader) {
//m_chunk.draw(shader);
for(auto &i : m_chunks) {
i.second.draw(shader);
}
}
bool operator==(const ChunkManager::Key &l, const ChunkManager::Key &r) {
return (l.x == r.x) && (l.y == r.y) && (l.z == r.z);
}