]> git.localhorst.tv Git - blank.git/blob - src/world.hpp
generate and unload chunks on player move
[blank.git] / src / world.hpp
1 #ifndef BLANK_WORLD_HPP_
2 #define BLANK_WORLD_HPP_
3
4 #include "block.hpp"
5 #include "chunk.hpp"
6 #include "entity.hpp"
7 #include "noise.hpp"
8 #include "shader.hpp"
9 #include "shape.hpp"
10
11 #include <list>
12 #include <glm/glm.hpp>
13
14
15 namespace blank {
16
17 class World {
18
19 public:
20         World();
21
22         void Generate(const glm::tvec3<int> &from, const glm::tvec3<int> &to);
23
24         bool Intersection(
25                 const Ray &,
26                 const glm::mat4 &M,
27                 Chunk **chunk = nullptr,
28                 int *blkid = nullptr,
29                 float *dist = nullptr,
30                 glm::vec3 *normal = nullptr);
31
32         BlockTypeRegistry &BlockTypes() { return blockType; }
33         std::list<Chunk> &LoadedChunks() { return loaded; }
34
35         Entity &Player() { return player; }
36
37         Chunk *ChunkLoaded(const glm::tvec3<int> &);
38         Chunk *ChunkQueued(const glm::tvec3<int> &);
39         Chunk *ChunkAvailable(const glm::tvec3<int> &);
40         Chunk &Next(const Chunk &, const glm::vec3 &dir);
41
42         void Update(int dt);
43         void CheckChunkGeneration();
44
45         void Render(DirectionalLighting &);
46
47 private:
48         void Generate(Chunk &);
49
50 private:
51         BlockTypeRegistry blockType;
52         CuboidShape blockShape;
53         StairShape stairShape;
54         CuboidShape slabShape;
55
56         SimplexNoise blockNoise;
57         SimplexNoise colorNoise;
58
59         Entity player;
60         glm::tvec3<int> player_chunk;
61
62         std::list<Chunk> loaded;
63         std::list<Chunk> to_generate;
64
65 };
66
67 }
68
69 #endif