diff options
| author | Mel <einebeere@gmail.com> | 2022-10-21 17:46:35 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-21 17:46:35 +0200 |
| commit | 20c53c7473fc6cc08944f502f078dfe57bcae1c9 (patch) | |
| tree | 7e6b09cea68251d4564a363c1a372d6daf746dcf /src/World/World.hpp | |
| parent | 6ed978051668c08f5a957c97570f364dd580c807 (diff) | |
| download | meowcraft-20c53c7473fc6cc08944f502f078dfe57bcae1c9.tar.zst meowcraft-20c53c7473fc6cc08944f502f078dfe57bcae1c9.zip | |
Broken infinite world
Diffstat (limited to 'src/World/World.hpp')
| -rw-r--r-- | src/World/World.hpp | 38 |
1 files changed, 38 insertions, 0 deletions
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 <memory> +#include <unordered_set> +#include <utility> +#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> chunk) + : index(index), chunk(std::move(chunk)), mesh() {} + + ChunkIndex index; + std::shared_ptr<Chunk> chunk; + std::optional<GFX::BindableMesh> mesh; + }; + + std::vector<ChunkData> get_visible_chunks(Vector<3> position); + +private: + std::unordered_set<ChunkIndex> 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<ChunkIndex, ChunkData> m_chunks; + std::unordered_set<ChunkIndex> m_visible_chunks; +}; + +} |
