diff options
| author | Mel <einebeere@gmail.com> | 2023-06-12 17:09:55 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-06-12 17:14:03 +0200 |
| commit | d0de60dc33df75fbcacb53a09568b14d0fd48cb9 (patch) | |
| tree | 7aefdbb81f114552881834bd5b0d842bc2bdb691 /src/World/Chunk.cpp | |
| parent | 23b0bc4d1ddc9fad3c32e8257497ddd13ac6a155 (diff) | |
| download | meowcraft-d0de60dc33df75fbcacb53a09568b14d0fd48cb9.tar.zst meowcraft-d0de60dc33df75fbcacb53a09568b14d0fd48cb9.zip | |
Multithreaded world generation with Perlin
Diffstat (limited to 'src/World/Chunk.cpp')
| -rw-r--r-- | src/World/Chunk.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp index 08f08bc..1874950 100644 --- a/src/World/Chunk.cpp +++ b/src/World/Chunk.cpp @@ -3,8 +3,12 @@ namespace MC::World { -void Chunk::set(uint32_t x, uint32_t y, uint32_t z, BlockType type) { - m_blocks[x][y][z].type = type; +void Chunk::set(uint32_t x, uint32_t y, uint32_t z, BlockData data) { + m_blocks[pos(x, y, z)] = data; +} + +Chunk::BlockData Chunk::get(uint32_t x, uint32_t y, uint32_t z) { + return m_blocks[pos(x, y, z)]; } GFX::Mesh Chunk::mesh() { @@ -16,7 +20,7 @@ GFX::Mesh Chunk::mesh() { for (int x = 0; x < Chunk::Width; x++) { for (int y = 0; y < Chunk::Height; y++) { for (int z = 0; z < Chunk::Width; z++) { - auto type = m_blocks[x][y][z].type; + auto type = get(x, y, z).type; if (type == BlockType::Air) { continue; } @@ -90,7 +94,7 @@ bool Chunk::is_face_visible(uint32_t x, uint32_t y, uint32_t z, BlockSide side) return true; } - auto neighbor = m_blocks[neighbor_pos.x()][neighbor_pos.y()][neighbor_pos.z()]; + auto neighbor = get(neighbor_pos.x(), neighbor_pos.y(), neighbor_pos.z()); if (neighbor.type == BlockType::Air) { return true; } @@ -154,4 +158,8 @@ std::array<Vector<3>, 4> Chunk::face_normals(BlockSide side) { return {normal, normal, normal, normal}; } +uint64_t Chunk::pos(uint32_t x, uint32_t y, uint32_t z) { + return x + Chunk::Width * y + Chunk::Width * Chunk::Height * z; +} + } |
