X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FChunkIndex.hpp;h=97956e9c4d47b434a6f6981bb9908af76724b761;hb=9da6ac5e93d79e79658a95d5f6efe42146873583;hp=17b9dd697de901f38b4febbb8e6ba4e40241c2d2;hpb=ae5a7e7d8517fac406a88e9bf98fd3d5bb1728b9;p=blank.git diff --git a/src/world/ChunkIndex.hpp b/src/world/ChunkIndex.hpp index 17b9dd6..97956e9 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 @@ -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,13 @@ 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() % Chunk::size)); + } + int Extent() const noexcept { return extent; } Chunk::Pos CoordsBegin() const noexcept { return base - Chunk::Pos(extent); }