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 ExactLocation::Coarse &base, int extent);
21 ChunkIndex(const ChunkIndex &) = delete;
22 ChunkIndex &operator =(const ChunkIndex &) = delete;
25 bool InRange(const ExactLocation::Coarse &) const noexcept;
26 bool IsBorder(const ExactLocation::Coarse &) const noexcept;
27 int Distance(const ExactLocation::Coarse &) const noexcept;
29 bool HasAllSurrounding(const ExactLocation::Coarse &) const noexcept;
31 int IndexOf(const ExactLocation::Coarse &) const noexcept;
32 ExactLocation::Coarse 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 ExactLocation::Coarse &) noexcept;
37 const Chunk *Get(const ExactLocation::Coarse &) 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 ExactLocation::Coarse CoordsBegin() const noexcept { return base - ExactLocation::Coarse(extent); }
51 ExactLocation::Coarse CoordsEnd() const noexcept { return base + ExactLocation::Coarse(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 ExactLocation::Coarse NextMissing() noexcept;
61 const ExactLocation::Coarse &Base() const noexcept { return base; }
62 void Rebase(const ExactLocation::Coarse &);
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;
77 ExactLocation::Coarse base;
84 std::vector<Chunk *> chunks;