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 int IndexOf(const Chunk::Pos &) const noexcept;
27 Chunk::Pos PositionOf(int) const noexcept;
28 /// returns nullptr if given position is out of range or the chunk
29 /// is not loaded, so also works as a "has" function
30 Chunk *Get(const Chunk::Pos &) noexcept;
31 const Chunk *Get(const Chunk::Pos &) const noexcept;
32 Chunk *operator [](int i) noexcept { return chunks[i]; }
33 const Chunk *operator [](int i) const noexcept { return chunks[i]; }
35 Chunk *RandomChunk(GaloisLFSR &rand) {
36 return rand.From(chunks);
38 BlockLookup RandomBlock(GaloisLFSR &rand) {
39 return BlockLookup(RandomChunk(rand), Chunk::ToPos(rand.Next<unsigned int>() % Chunk::size));
42 int Extent() const noexcept { return extent; }
44 Chunk::Pos CoordsBegin() const noexcept { return base - Chunk::Pos(extent); }
45 Chunk::Pos CoordsEnd() const noexcept { return base + Chunk::Pos(extent + 1); }
47 void Register(Chunk &) noexcept;
49 int TotalChunks() const noexcept { return total_length; }
50 int IndexedChunks() const noexcept { return total_indexed; }
51 int MissingChunks() const noexcept { return total_length - total_indexed; }
53 Chunk::Pos NextMissing() noexcept;
55 const Chunk::Pos &Base() const noexcept { return base; }
56 void Rebase(const Chunk::Pos &);
59 int GetCol(int) const noexcept;
61 void Shift(Block::Face);
63 void Clear() noexcept;
66 void Set(int index, Chunk &) noexcept;
67 void Unset(int index) noexcept;
78 std::vector<Chunk *> chunks;