1 #ifndef BLANK_WORLD_CHUNKINDEX_HPP_
2 #define BLANK_WORLD_CHUNKINDEX_HPP_
4 #include "BlockLookup.hpp"
6 #include "../rand/GaloisLFSR.hpp"
18 ChunkIndex(ChunkStore &, const Chunk::Pos &base, int extent);
21 ChunkIndex(const ChunkIndex &) = delete;
22 ChunkIndex &operator =(const ChunkIndex &) = delete;
25 bool InRange(const Chunk::Pos &) const noexcept;
26 bool IsBorder(const Chunk::Pos &) const noexcept;
27 int Distance(const Chunk::Pos &) const noexcept;
29 bool HasAllSurrounding(const Chunk::Pos &) const noexcept;
31 int IndexOf(const Chunk::Pos &) const noexcept;
32 Chunk::Pos PositionOf(int) const noexcept;
34 /// returns nullptr if given position is out of range or the chunk
35 /// is not loaded, so also works as a "has" function
36 Chunk *Get(const Chunk::Pos &) noexcept;
37 const Chunk *Get(const Chunk::Pos &) const noexcept;
38 Chunk *operator [](int i) noexcept { return chunks[i]; }
39 const Chunk *operator [](int i) const noexcept { return chunks[i]; }
41 Chunk *RandomChunk(GaloisLFSR &rand) {
42 return rand.From(chunks);
44 BlockLookup RandomBlock(GaloisLFSR &rand) {
45 return BlockLookup(RandomChunk(rand), Chunk::ToPos(rand.Next<unsigned int>() % Chunk::size));
48 int Extent() const noexcept { return extent; }
50 Chunk::Pos CoordsBegin() const noexcept { return base - Chunk::Pos(extent); }
51 Chunk::Pos CoordsEnd() const noexcept { return base + Chunk::Pos(extent + 1); }
53 void Register(Chunk &) noexcept;
55 int TotalChunks() const noexcept { return total_length; }
56 int IndexedChunks() const noexcept { return total_indexed; }
57 int MissingChunks() const noexcept { return total_length - total_indexed; }
59 Chunk::Pos NextMissing() noexcept;
61 const Chunk::Pos &Base() const noexcept { return base; }
62 void Rebase(const Chunk::Pos &);
65 int GetCol(int) const noexcept;
67 void Shift(Block::Face);
69 void Clear() noexcept;
72 void Set(int index, Chunk &) noexcept;
73 void Unset(int index) noexcept;
84 std::vector<Chunk *> chunks;