]> git.localhorst.tv Git - blank.git/blob - src/world/World.hpp
test entities for world collision
[blank.git] / src / world / World.hpp
1 #ifndef BLANK_WORLD_WORLD_HPP_
2 #define BLANK_WORLD_WORLD_HPP_
3
4 #include "BlockTypeRegistry.hpp"
5 #include "ChunkLoader.hpp"
6 #include "Entity.hpp"
7 #include "Generator.hpp"
8 #include "../model/shapes.hpp"
9
10 #include <list>
11 #include <glm/glm.hpp>
12
13
14 namespace blank {
15
16 class BlockLighting;
17 class DirectionalLighting;
18
19 class World {
20
21 public:
22         struct Config {
23                 // initial player position
24                 glm::vec3 spawn = { 0.0f, 0.0f, 0.0f };
25                 // direction facing towards(!) the light
26                 glm::vec3 light_direction = { -1.0f, -3.0f, -2.0f };
27                 // fade out reaches 1/e (0.3679) at 1/fog_density,
28                 // gets less than 0.01 at e/(2 * fog_density)
29                 // I chose 0.011 because it yields 91 and 124 for those, so
30                 // slightly less than 6 and 8 chunks
31                 float fog_density = 0.011f;
32
33                 Generator::Config gen = Generator::Config();
34                 ChunkLoader::Config load = ChunkLoader::Config();
35         };
36
37         explicit World(const Config &);
38
39         bool Intersection(
40                 const Ray &,
41                 const glm::mat4 &M,
42                 Chunk *&chunk,
43                 int &blkid,
44                 float &dist,
45                 glm::vec3 &normal);
46
47         bool Intersection(const Entity &e);
48
49         BlockTypeRegistry &BlockTypes() { return blockType; }
50
51         Entity &Player() { return *player; }
52         Entity &AddEntity() { entities.emplace_back(); return entities.back(); }
53
54         Chunk &PlayerChunk();
55         Chunk &Next(const Chunk &to, const glm::tvec3<int> &dir);
56
57         void Update(int dt);
58
59         void Render(BlockLighting &, DirectionalLighting &);
60
61 private:
62         BlockTypeRegistry blockType;
63         CuboidShape blockShape;
64         StairShape stairShape;
65         CuboidShape slabShape;
66
67         Generator generate;
68         ChunkLoader chunks;
69
70         Entity *player;
71         std::list<Entity> entities;
72
73         glm::vec3 light_direction;
74         float fog_density;
75
76 };
77
78 }
79
80 #endif