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 // raw iteration access, may contain nullptrs
51 std::vector<Chunk *>::const_iterator begin() const noexcept { return chunks.begin(); }
52 std::vector<Chunk *>::const_iterator end() const noexcept { return chunks.end(); }
54 ExactLocation::Coarse CoordsBegin() const noexcept { return base - ExactLocation::Coarse(extent); }
55 ExactLocation::Coarse CoordsEnd() const noexcept { return base + ExactLocation::Coarse(extent + 1); }
57 void Register(Chunk &) noexcept;
59 int TotalChunks() const noexcept { return total_length; }
60 int IndexedChunks() const noexcept { return total_indexed; }
61 int MissingChunks() const noexcept { return total_length - total_indexed; }
63 ExactLocation::Coarse NextMissing() noexcept;
65 const ExactLocation::Coarse &Base() const noexcept { return base; }
66 void Rebase(const ExactLocation::Coarse &);
69 int GetCol(int) const noexcept;
71 void Shift(Block::Face);
73 void Clear() noexcept;
76 void Set(int index, Chunk &) noexcept;
77 void Unset(int index) noexcept;
81 ExactLocation::Coarse base;
88 std::vector<Chunk *> chunks;