-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunk.cpp
More file actions
46 lines (39 loc) · 911 Bytes
/
Copy pathchunk.cpp
File metadata and controls
46 lines (39 loc) · 911 Bytes
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
#include "chunk.h"
Chunk::Chunk()
: mesh()
, m_position(0,0,0)
{
// Create the blocks
m_pBlocks = new Block * *[CHUNK_SIZE];
for (int i = 0; i < CHUNK_SIZE; i++) {
m_pBlocks[i] = new Block * [CHUNK_SIZE];
for (int j = 0; j < CHUNK_SIZE; j++) {
m_pBlocks[i][j] = new Block[CHUNK_SIZE];
}
}
}
Chunk::~Chunk() { // Delete the blocks
for (int i = 0; i < CHUNK_SIZE; ++i) {
for (int j = 0; j < CHUNK_SIZE; ++j) {
delete[] m_pBlocks[i][j];
}
delete[] m_pBlocks[i];
}
delete[] m_pBlocks;
}
void Chunk::update()
{
mesh.buildMesh(*this);
}
void Chunk::render(Shader& ourShader)
{
mesh.render(m_position, ourShader);
}
const BlockType Chunk::getBlockType(int x, int y, int z) const
{
if (x < 0 || y < 0 || z < 0)
return BlockType::BlockType_Air;
if (x >= CHUNK_SIZE || y >= CHUNK_SIZE || z >= CHUNK_SIZE)
return BlockType::BlockType_Air;
return m_pBlocks[x][y][z].m_blockType;
}