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