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