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