]> git.localhorst.tv Git - blank.git/blob - src/world/ChunkStore.hpp
68434bbd84952489a98fa4dd9b2490ad7606cdd9
[blank.git] / src / world / ChunkStore.hpp
1 #ifndef BLANK_WORLD_CHUNKSTORE_HPP_
2 #define BLANK_WORLD_CHUNKSTORE_HPP_
3
4 #include "Chunk.hpp"
5
6 #include <list>
7
8
9 namespace blank {
10
11 class ChunkIndex;
12
13 class ChunkStore {
14
15 public:
16         ChunkStore(const BlockTypeRegistry &);
17         ~ChunkStore();
18
19         ChunkStore(const ChunkStore &) = delete;
20         ChunkStore &operator =(const ChunkStore &) = delete;
21
22 public:
23         ChunkIndex &MakeIndex(const Chunk::Pos &base, int extent);
24         void UnregisterIndex(ChunkIndex &);
25
26         /// returns nullptr if given position is not loaded
27         Chunk *Get(const Chunk::Pos &);
28         /// returns nullptr if given position is not indexed
29         Chunk *Allocate(const Chunk::Pos &);
30
31         std::list<Chunk>::iterator begin() noexcept { return loaded.begin(); }
32         std::list<Chunk>::iterator end() noexcept { return loaded.end(); }
33
34         std::size_t NumLoaded() const noexcept { return loaded.size(); }
35
36         /// returns true if one of the indices is incomplete
37         bool HasMissing() const noexcept;
38         /// get the total number of missing chunks
39         /// this is an estimate and represents the upper bound since
40         /// chunks may be counted more than once if indices overlap
41         int EstimateMissing() const noexcept;
42
43         /// get coordinates of a missing chunk
44         /// this will return garbage if none are actually missing
45         Chunk::Pos NextMissing() noexcept;
46
47         void Clean();
48
49 private:
50         const BlockTypeRegistry &types;
51
52         std::list<Chunk> loaded;
53         std::list<Chunk> free;
54
55         std::list<ChunkIndex> indices;
56
57 };
58
59 }
60
61 #endif