]> git.localhorst.tv Git - blank.git/blobdiff - src/world.hpp
minor optimizations in chunk
[blank.git] / src / world.hpp
index ccd743dd4f1321955410ef1e055f5354140bdb16..1d43fbe7ffce45e2929ea659ea48293be33daa33 100644 (file)
@@ -8,6 +8,7 @@
 #include "shader.hpp"
 #include "shape.hpp"
 
+#include <list>
 #include <glm/glm.hpp>
 
 
@@ -16,7 +17,22 @@ namespace blank {
 class World {
 
 public:
-       World();
+       struct Config {
+               // initial player position
+               glm::vec3 spawn = { 4.0f, 4.0f, 4.0f };
+               // direction facing towards(!) the light
+               glm::vec3 light_direction = { -1.0f, -3.0f, -2.0f };
+               // fade out reaches 1/e (0.3679) at 1/fog_density,
+               // gets less than 0.01 at e/(2 * fog_density)
+               // I chose 0.011 because it yields 91 and 124 for those, so
+               // slightly less than 6 and 8 chunks
+               float fog_density = 0.011f;
+
+               Generator::Config gen = Generator::Config();
+               ChunkLoader::Config load = ChunkLoader::Config();
+       };
+
+       explicit World(const Config &);
 
        bool Intersection(
                const Ray &,
@@ -28,13 +44,15 @@ public:
 
        BlockTypeRegistry &BlockTypes() { return blockType; }
 
-       Entity &Player() { return player; }
+       Entity &Player() { return *player; }
+       Entity &AddEntity() { entities.emplace_back(); return entities.back(); }
 
+       Chunk &PlayerChunk();
        Chunk &Next(const Chunk &to, const glm::tvec3<int> &dir);
 
        void Update(int dt);
 
-       void Render(DirectionalLighting &);
+       void Render(BlockLighting &, DirectionalLighting &);
 
 private:
        BlockTypeRegistry blockType;
@@ -45,7 +63,11 @@ private:
        Generator generate;
        ChunkLoader chunks;
 
-       Entity player;
+       Entity *player;
+       std::list<Entity> entities;
+
+       glm::vec3 light_direction;
+       float fog_density;
 
 };