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