From d0de60dc33df75fbcacb53a09568b14d0fd48cb9 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 12 Jun 2023 17:09:55 +0200 Subject: Multithreaded world generation with Perlin --- src/World/Chunk.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/World/Chunk.hpp') diff --git a/src/World/Chunk.hpp b/src/World/Chunk.hpp index cb4f7e1..2b0379c 100644 --- a/src/World/Chunk.hpp +++ b/src/World/Chunk.hpp @@ -12,12 +12,18 @@ namespace MC::World { class Chunk { public: static constexpr const uint32_t Width = 16; - static constexpr const uint32_t Height = 64; + static constexpr const uint32_t Height = 128; Chunk(int64_t x, int64_t y) - : m_blocks{}, m_position{(float)x * Chunk::Width, 0.0f, (float)y * Chunk::Width} {}; + : m_blocks{Chunk::Width * Chunk::Height * Chunk::Width, {BlockType::Air}}, + 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); + struct BlockData { + BlockType type; + }; + + void set(uint32_t x, uint32_t y, uint32_t z, BlockData type); + BlockData get(uint32_t x, uint32_t y, uint32_t z); Vector<3> position(); GFX::Mesh mesh(); @@ -27,12 +33,10 @@ private: static std::array, 4> face_tex_coords(BlockType type, BlockSide side); static std::array, 4> face_normals(BlockSide side); - struct BlockData { - BlockType type; - }; + static uint64_t pos(uint32_t x, uint32_t y, uint32_t z); Vector<3> m_position; - BlockData m_blocks[Chunk::Width][Chunk::Height][Chunk::Width]; + std::vector m_blocks; }; } -- cgit 1.4.1