]> git.localhorst.tv Git - blank.git/blob - src/world/ChunkLoader.hpp
some code reorganization
[blank.git] / src / world / ChunkLoader.hpp
1 #ifndef BLANK_WORLD_CHUNKLOADER_HPP_
2 #define BLANK_WORLD_CHUNKLOADER_HPP_
3
4 #include "Chunk.hpp"
5
6 #include <list>
7
8
9 namespace blank {
10
11 class BlockTypeRegistry;
12 class Generator;
13
14 class ChunkLoader {
15
16 public:
17         struct Config {
18                 int load_dist = 6;
19                 int unload_dist = 8;
20         };
21
22         ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &) noexcept;
23
24         void Generate(const Chunk::Pos &from, const Chunk::Pos &to);
25         void GenerateSurrounding(const Chunk::Pos &);
26
27         std::list<Chunk> &Loaded() noexcept { return loaded; }
28
29         Chunk *Loaded(const Chunk::Pos &) noexcept;
30         bool Queued(const Chunk::Pos &) noexcept;
31         bool Known(const Chunk::Pos &) noexcept;
32         Chunk &ForceLoad(const Chunk::Pos &);
33
34         void Rebase(const Chunk::Pos &);
35         void Update();
36
37 private:
38         Chunk &Generate(const Chunk::Pos &pos);
39         void Insert(Chunk &) noexcept;
40         void Remove(Chunk &) noexcept;
41
42 private:
43         Chunk::Pos base;
44
45         const BlockTypeRegistry &reg;
46         const Generator &gen;
47
48         std::list<Chunk> loaded;
49         std::list<Chunk::Pos> to_generate;
50         std::list<Chunk> to_free;
51
52         int load_dist;
53         int unload_dist;
54
55 };
56
57 }
58
59 #endif