-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk.hpp
65 lines (55 loc) · 2.11 KB
/
chunk.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
57
58
59
60
61
62
63
64
65
#ifndef CHUNK_HPP_INCLUDED
#define CHUNK_HPP_INCLUDED
#include <array>
#include <string>
#include <vector>
#include "glad/glad.h"
//#include "blocks.hpp"
#include "blockshader.hpp"
#include "dynamicexception.hpp"
#include "entity.hpp"
#include "model.hpp"
#include "node.hpp"
#include "texture.hpp"
class Chunk /* final */ {
public:
static constexpr int k_chunk_size = 8;
static constexpr int k_chunk_size_sq = k_chunk_size * k_chunk_size;
static constexpr int k_chunk_size_cb = k_chunk_size_sq * k_chunk_size;
private:
std::array<Node, k_chunk_size_cb> m_blocks;
Model *m_model;
Entity *m_entity;
int index(int x, int y, int z) const;
Node & blockAt(int x, int y, int z);
const Node & blockAt(int x, int y, int z) const;
/* void generateGeometry(std::vector<GLuint> &indices,
std::vector<GLfloat> &positions,
std::vector<GLfloat> &colors,
std::vector<GLfloat> &uv);
*/
public:
class UninitializedChunkException : public DynamicException {
public:
UninitializedChunkException(const std::string &msg) : DynamicException(msg) {}
};
class OutOfRangeException : public DynamicException {
public:
OutOfRangeException(const std::string &msg) : DynamicException(msg) {}
};
/*
Chunk(const Texture &tex, int chunk_x, int chunk_y, int chunk_z);
Chunk(const Texture &tex) : Chunk(tex, 0, 0, 0) {}
*/
Chunk();
~Chunk();
Chunk(const Chunk &) = delete;
Chunk & operator=(const Chunk &) = delete;
Chunk(Chunk &&) = delete;
Chunk & operator=(Chunk &&) = delete;
void generateGeometry(const Texture &tex, int chunk_x, int chunk_y, int chunk_z);
void draw(BlockShader &shader);
//Sets a block in the chunk. The coords must be realative to the origin of the chunk!
inline void setBlock(int x, int y, int z, BlockId id) { blockAt(x, y, z) = id; }
};
#endif // CHUNK_HPP_INCLUDED