blob: 4c7810de446ac1220291a0badbe4fc5666214596 (
plain)
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
|
#pragma once
#include <cstdint>
#include <optional>
#include "BlockType.hpp"
#include "../GFX/Mesh.hpp"
#include "BlockSide.hpp"
#include "../GFX/Binder.hpp"
#define CHUNK_WIDTH 16
#define CHUNK_HEIGHT 64
namespace MC::World {
class Chunk {
public:
Chunk(int64_t x, int64_t y)
: m_blocks{}, m_position{(float)x * CHUNK_WIDTH, 0.0f, (float)y * CHUNK_WIDTH} {};
void set(uint32_t x, uint32_t y, uint32_t z, BlockType type);
Vector<3> position();
GFX::Mesh mesh();
private:
bool is_face_visible(uint32_t x, uint32_t y, uint32_t z, BlockSide side);
static std::array<Vector<2>, 4> face_tex_coords(BlockType type, BlockSide side);
struct BlockData {
BlockType type;
};
Vector<3> m_position;
BlockData m_blocks[CHUNK_WIDTH][CHUNK_HEIGHT][CHUNK_WIDTH];
};
}
|