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