X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fchunk.hpp;h=255d73b163f70ff25db4bade6f1b9a087a767aee;hb=b4995967309bf5570161db2287e27b84ca94ab9a;hp=5c1cadb38d50f1222253d26b123b916a28170b3e;hpb=82426ae2997d2b21703d2d5afb631a84736e975f;p=blank.git diff --git a/src/chunk.hpp b/src/chunk.hpp index 5c1cadb..255d73b 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -5,6 +5,7 @@ #include "geometry.hpp" #include "model.hpp" +#include #include #include @@ -50,6 +51,18 @@ public: 0.5f + (idx / (Width() * Height())) ); } + glm::mat4 ToTransform(int idx) const; + + static constexpr bool IsBorder(int idx) { + return + idx < Width() * Height() || + (idx / Width()) % Height() == 0 || + (idx / Width()) % Height() == Height() - 1 || + (idx / (Width() * Height())) == Depth() - 1; + } + + // check if block at given index is completely enclosed (and therefore invisible) + bool Obstructed(int idx) const; void Allocate(); void Invalidate() { dirty = true; } @@ -72,6 +85,7 @@ public: const Pos &Position() const { return position; } glm::mat4 Transform(const Pos &offset) const; + void CheckUpdate(); void Draw(); private: @@ -86,6 +100,41 @@ private: }; + +class Generator; + +class ChunkLoader { + +public: + ChunkLoader(const BlockTypeRegistry &, const Generator &); + + void Generate(const Chunk::Pos &from, const Chunk::Pos &to); + + std::list &Loaded() { return loaded; } + + Chunk *Loaded(const Chunk::Pos &); + bool Queued(const Chunk::Pos &); + bool Known(const Chunk::Pos &); + Chunk &ForceLoad(const Chunk::Pos &); + + void Rebase(const Chunk::Pos &); + void Update(); + +private: + Chunk::Pos base; + + const BlockTypeRegistry ® + const Generator &gen; + + std::list loaded; + std::list to_generate; + std::list to_free; + + int load_dist; + int unload_dist; + +}; + } #endif