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
|
#pragma once
#include <cstdint>
#include "BiomeType.hpp"
#include "BlockType.hpp"
#include "../GFX/Mesh.hpp"
#include "BlockSide.hpp"
namespace MC::World {
class Chunk {
public:
static constexpr uint32_t Width = 16;
static constexpr uint32_t Height = 128;
Chunk(int64_t x, int64_t y)
: m_blocks{Width * Height * Width, {BlockType::Air}},
m_position{(float)x * Width, 0.0f, (float)y * Width} {}
struct BlockData {
BlockType type;
};
void set(uint32_t x, uint32_t y, uint32_t z, BlockData data);
BlockData get(uint32_t x, uint32_t y, uint32_t z) const;
struct Details {
Matrix<Width, Width> landmass_values{};
Matrix<Width, Width> hill_values{};
Matrix<Width, Width, BiomeType> biome_values{};
};
void set_details(const Details& details) { m_details = details; }
Details& details(){ return m_details; }
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);
static std::array<Vector<3>, 4> face_normals(BlockSide side);
static uint64_t pos(uint32_t x, uint32_t y, uint32_t z);
Vector<3> m_position;
std::vector<BlockData> m_blocks;
Details m_details;
};
}
|