]> git.localhorst.tv Git - blank.git/blob - src/world/ChunkStore.hpp
some linting
[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         explicit ChunkStore(const BlockTypeRegistry &);
17         ~ChunkStore();
18
19         ChunkStore(const ChunkStore &) = delete;
20         ChunkStore &operator =(const ChunkStore &) = delete;
21
22 public:
23         ChunkIndex &MakeIndex(const ExactLocation::Coarse &base, int extent);
24         void UnregisterIndex(ChunkIndex &);
25
26         ChunkIndex *ClosestIndex(const ExactLocation::Coarse &pos);
27
28         /// returns nullptr if given position is not loaded
29         Chunk *Get(const ExactLocation::Coarse &) noexcept;
30         const Chunk *Get(const ExactLocation::Coarse &) const noexcept;
31         /// returns nullptr if given position is not indexed
32         Chunk *Allocate(const ExactLocation::Coarse &);
33
34         std::list<Chunk>::iterator begin() noexcept { return loaded.begin(); }
35         std::list<Chunk>::iterator end() noexcept { return loaded.end(); }
36
37         std::size_t NumLoaded() const noexcept { return loaded.size(); }
38
39         /// returns true if one of the indices is incomplete
40         bool HasMissing() const noexcept;
41         /// get the total number of missing chunks
42         /// this is an estimate and represents the upper bound since
43         /// chunks may be counted more than once if indices overlap
44         int EstimateMissing() const noexcept;
45
46         /// get coordinates of a missing chunk
47         /// this will return garbage if none are actually missing
48         ExactLocation::Coarse NextMissing() noexcept;
49
50         void Clean();
51
52 private:
53         const BlockTypeRegistry &types;
54
55         std::list<Chunk> loaded;
56         std::list<Chunk> free;
57
58         std::list<ChunkIndex> indices;
59
60 };
61
62 }
63
64 #endif