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