#include "block.hpp"
#include "chunk.hpp"
#include "entity.hpp"
-#include "noise.hpp"
+#include "generator.hpp"
#include "shader.hpp"
#include "shape.hpp"
class World {
public:
- World();
-
- void Generate(const glm::tvec3<int> &from, const glm::tvec3<int> &to);
+ 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 &,
glm::vec3 *normal = nullptr);
BlockTypeRegistry &BlockTypes() { return blockType; }
- std::list<Chunk> &LoadedChunks() { return loaded; }
- Entity &Player() { return player; }
+ Entity &Player() { return *player; }
+ Entity &AddEntity() { entities.emplace_back(); return entities.back(); }
- Chunk *ChunkLoaded(const glm::tvec3<int> &);
- Chunk *ChunkQueued(const glm::tvec3<int> &);
- Chunk *ChunkAvailable(const glm::tvec3<int> &);
- Chunk &Next(const Chunk &, const glm::tvec3<int> &dir);
+ Chunk &PlayerChunk();
+ Chunk &Next(const Chunk &to, const glm::tvec3<int> &dir);
void Update(int dt);
- void CheckChunkGeneration();
-
- void Render(DirectionalLighting &);
-private:
- void Generate(Chunk &);
+ void Render(BlockLighting &, DirectionalLighting &);
private:
BlockTypeRegistry blockType;
StairShape stairShape;
CuboidShape slabShape;
- SimplexNoise blockNoise;
- SimplexNoise colorNoise;
+ Generator generate;
+ ChunkLoader chunks;
- Entity player;
- glm::tvec3<int> player_chunk;
+ Entity *player;
+ std::list<Entity> entities;
- std::list<Chunk> loaded;
- std::list<Chunk> to_generate;
- std::list<Chunk> to_free;
+ glm::vec3 light_direction;
+ float fog_density;
};