From 20c53c7473fc6cc08944f502f078dfe57bcae1c9 Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 21 Oct 2022 17:46:35 +0200 Subject: Broken infinite world --- src/World/World.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/World/World.hpp (limited to 'src/World/World.hpp') diff --git a/src/World/World.hpp b/src/World/World.hpp new file mode 100644 index 0000000..3453b18 --- /dev/null +++ b/src/World/World.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include "Generator.hpp" +#include "ChunkIndex.hpp" + +namespace MC::World { + +class World { +public: + World() : m_generator(), m_chunks(), m_visible_chunks() {} + + struct ChunkData { + ChunkData(ChunkIndex index, std::shared_ptr chunk) + : index(index), chunk(std::move(chunk)), mesh() {} + + ChunkIndex index; + std::shared_ptr chunk; + std::optional mesh; + }; + + std::vector get_visible_chunks(Vector<3> position); + +private: + std::unordered_set get_visible_chunk_indices(Vector<3> position) const; + ChunkData& get_or_generate(ChunkIndex index); + + uint8_t m_view_distance_radius = 6; + + Generator m_generator; + + std::unordered_map m_chunks; + std::unordered_set m_visible_chunks; +}; + +} -- cgit 1.4.1