]> git.localhorst.tv Git - blank.git/blob - src/world/ChunkRenderer.hpp
split chunk redering from world model
[blank.git] / src / world / ChunkRenderer.hpp
1 #ifndef BLANK_WORLD_CHUNKRENDERER_HPP_
2 #define BLANK_WORLD_CHUNKRENDERER_HPP_
3
4 #include "Block.hpp"
5 #include "Chunk.hpp"
6 #include "../graphics/ArrayTexture.hpp"
7 #include "../model/BlockModel.hpp"
8
9 #include <vector>
10
11
12 namespace blank {
13
14 class Assets;
15 class TextureIndex;
16 class Viewport;
17 class World;
18
19 class ChunkRenderer {
20
21 public:
22         /// render_distance in chunks, excluding the base chunk which is always rendered
23         ChunkRenderer(World &, int render_distance);
24
25         void LoadTextures(const Assets &, const TextureIndex &);
26         void FogDensity(float d) noexcept { fog_density = d; }
27
28         bool InRange(const Chunk::Pos &) const noexcept;
29         int IndexOf(const Chunk::Pos &) const noexcept;
30
31         int TotalChunks() const noexcept { return total_length; }
32         int IndexedChunks() const noexcept { return total_indexed; }
33         int MissingChunks() const noexcept { return total_length - total_indexed; }
34
35         void Rebase(const Chunk::Pos &);
36         void Rescan();
37         void Scan();
38         void Update(int dt);
39
40         void Render(Viewport &);
41
42 private:
43         int GetCol(int) const noexcept;
44
45         void Shift(Block::Face);
46
47 private:
48         World &world;
49         ArrayTexture block_tex;
50
51         int render_dist;
52         int side_length;
53         int total_length;
54         int total_indexed;
55         glm::ivec3 stride;
56         std::vector<BlockModel> models;
57         std::vector<Chunk *> chunks;
58
59         Chunk::Pos base;
60
61         float fog_density;
62
63 };
64
65 }
66
67 #endif