]> git.localhorst.tv Git - blank.git/blob - src/world/ChunkIndex.hpp
split chunk stuff
[blank.git] / src / world / ChunkIndex.hpp
1 #ifndef BLANK_WORLD_CHUNKINDEX_HPP_
2 #define BLANK_WORLD_CHUNKINDEX_HPP_
3
4 #include "Chunk.hpp"
5
6 #include <vector>
7
8
9 namespace blank {
10
11 class ChunkStore;
12
13 class ChunkIndex {
14
15 public:
16         ChunkIndex(ChunkStore &, const Chunk::Pos &base, int extent);
17         ~ChunkIndex();
18
19         ChunkIndex(const ChunkIndex &) = delete;
20         ChunkIndex &operator =(const ChunkIndex &) = delete;
21
22 public:
23         bool InRange(const Chunk::Pos &) const noexcept;
24         int IndexOf(const Chunk::Pos &) const noexcept;
25         Chunk::Pos PositionOf(int) const noexcept;
26         /// returns nullptr if given position is out of range or the chunk
27         /// is not loaded, so also works as a "has" function
28         Chunk *Get(const Chunk::Pos &) noexcept;
29         const Chunk *Get(const Chunk::Pos &) const noexcept;
30         Chunk *operator [](int i) noexcept { return chunks[i]; }
31         const Chunk *operator [](int i) const noexcept { return chunks[i]; }
32
33         void Register(Chunk &) noexcept;
34
35         int TotalChunks() const noexcept { return total_length; }
36         int IndexedChunks() const noexcept { return total_indexed; }
37         int MissingChunks() const noexcept { return total_length - total_indexed; }
38
39         Chunk::Pos NextMissing() noexcept;
40
41         const Chunk::Pos &Base() const noexcept { return base; }
42         void Rebase(const Chunk::Pos &);
43
44 private:
45         int GetCol(int) const noexcept;
46
47         void Shift(Block::Face);
48
49         void Clear() noexcept;
50         void Scan() noexcept;
51
52         void Set(int index, Chunk &) noexcept;
53         void Unset(int index) noexcept;
54
55 private:
56         ChunkStore &store;
57         Chunk::Pos base;
58         int extent;
59         int side_length;
60         int total_length;
61         int total_indexed;
62         int last_missing;
63         glm::ivec3 stride;
64         std::vector<Chunk *> chunks;
65
66 };
67
68 }
69
70 #endif