]> git.localhorst.tv Git - blank.git/blobdiff - src/world/ChunkIndex.hpp
merge common parts of pre- and unload states
[blank.git] / src / world / ChunkIndex.hpp
index 6749737acb8f6966101aad7ba92a78f89d81ff35..97956e9c4d47b434a6f6981bb9908af76724b761 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef BLANK_WORLD_CHUNKINDEX_HPP_
 #define BLANK_WORLD_CHUNKINDEX_HPP_
 
+#include "BlockLookup.hpp"
 #include "Chunk.hpp"
+#include "../rand/GaloisLFSR.hpp"
 
 #include <vector>
 
@@ -21,8 +23,14 @@ public:
 
 public:
        bool InRange(const Chunk::Pos &) const noexcept;
+       bool IsBorder(const Chunk::Pos &) const noexcept;
+       int Distance(const Chunk::Pos &) const noexcept;
+
+       bool HasAllSurrounding(const Chunk::Pos &) const noexcept;
+
        int IndexOf(const Chunk::Pos &) const noexcept;
        Chunk::Pos PositionOf(int) const noexcept;
+
        /// returns nullptr if given position is out of range or the chunk
        /// is not loaded, so also works as a "has" function
        Chunk *Get(const Chunk::Pos &) noexcept;
@@ -30,6 +38,18 @@ public:
        Chunk *operator [](int i) noexcept { return chunks[i]; }
        const Chunk *operator [](int i) const noexcept { return chunks[i]; }
 
+       Chunk *RandomChunk(GaloisLFSR &rand) {
+               return rand.From(chunks);
+       }
+       BlockLookup RandomBlock(GaloisLFSR &rand) {
+               return BlockLookup(RandomChunk(rand), Chunk::ToPos(rand.Next<unsigned int>() % Chunk::size));
+       }
+
+       int Extent() const noexcept { return extent; }
+
+       Chunk::Pos CoordsBegin() const noexcept { return base - Chunk::Pos(extent); }
+       Chunk::Pos CoordsEnd() const noexcept { return base + Chunk::Pos(extent + 1); }
+
        void Register(Chunk &) noexcept;
 
        int TotalChunks() const noexcept { return total_length; }