X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FChunkIndex.hpp;h=1823de72b154359c4635a7a0e4f0d1d55ae6f9db;hb=4727825186798902f68df5b99a6a32f0ef618454;hp=6749737acb8f6966101aad7ba92a78f89d81ff35;hpb=13e676a6e49128ebc6c63b8dd08bef51d360e8e9;p=blank.git diff --git a/src/world/ChunkIndex.hpp b/src/world/ChunkIndex.hpp index 6749737..1823de7 100644 --- a/src/world/ChunkIndex.hpp +++ b/src/world/ChunkIndex.hpp @@ -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 @@ -13,33 +15,51 @@ class ChunkStore; class ChunkIndex { public: - ChunkIndex(ChunkStore &, const Chunk::Pos &base, int extent); + ChunkIndex(ChunkStore &, const ExactLocation::Coarse &base, int extent); ~ChunkIndex(); ChunkIndex(const ChunkIndex &) = delete; ChunkIndex &operator =(const ChunkIndex &) = delete; public: - bool InRange(const Chunk::Pos &) const noexcept; - int IndexOf(const Chunk::Pos &) const noexcept; - Chunk::Pos PositionOf(int) const noexcept; + bool InRange(const ExactLocation::Coarse &) const noexcept; + bool IsBorder(const ExactLocation::Coarse &) const noexcept; + int Distance(const ExactLocation::Coarse &) const noexcept; + + bool HasAllSurrounding(const ExactLocation::Coarse &) const noexcept; + + int IndexOf(const ExactLocation::Coarse &) const noexcept; + ExactLocation::Coarse 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; - const Chunk *Get(const Chunk::Pos &) const noexcept; + Chunk *Get(const ExactLocation::Coarse &) noexcept; + const Chunk *Get(const ExactLocation::Coarse &) const noexcept; 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() % Chunk::size)); + } + + int Extent() const noexcept { return extent; } + + ExactLocation::Coarse CoordsBegin() const noexcept { return base - ExactLocation::Coarse(extent); } + ExactLocation::Coarse CoordsEnd() const noexcept { return base + ExactLocation::Coarse(extent + 1); } + void Register(Chunk &) noexcept; int TotalChunks() const noexcept { return total_length; } int IndexedChunks() const noexcept { return total_indexed; } int MissingChunks() const noexcept { return total_length - total_indexed; } - Chunk::Pos NextMissing() noexcept; + ExactLocation::Coarse NextMissing() noexcept; - const Chunk::Pos &Base() const noexcept { return base; } - void Rebase(const Chunk::Pos &); + const ExactLocation::Coarse &Base() const noexcept { return base; } + void Rebase(const ExactLocation::Coarse &); private: int GetCol(int) const noexcept; @@ -54,7 +74,7 @@ private: private: ChunkStore &store; - Chunk::Pos base; + ExactLocation::Coarse base; int extent; int side_length; int total_length;