1 #ifndef BLANK_WORLD_WORLD_HPP_
2 #define BLANK_WORLD_WORLD_HPP_
4 #include "ChunkStore.hpp"
6 #include "Generator.hpp"
13 #include <glm/glm.hpp>
18 class BlockTypeRegistry;
19 class EntityCollision;
27 std::string name = "default";
28 // initial player position
29 glm::vec3 spawn = { 0.0f, 0.0f, 0.0f };
30 // direction facing towards(!) the light
31 glm::vec3 light_direction = { -1.0f, -3.0f, -2.0f };
32 // fade out reaches 1/e (0.3679) at 1/fog_density,
33 // gets less than 0.01 at e/(2 * fog_density)
34 // I chose 0.011 because it yields 91 and 124 for those, so
35 // slightly less than 6 and 8 chunks
36 float fog_density = 0.011f;
39 World(const BlockTypeRegistry &, const Config &);
42 const std::string &Name() const noexcept { return config.name; }
44 /// check if this ray hits a block
45 /// depth in the collision is the distance between the ray's
46 /// origin and the intersection point
47 /// M is the global transform for given reference chunk
51 const Chunk::Pos &reference,
54 /// check if this ray hits an entity
55 /// intersections with the reference are not tested
56 /// M is the global transform for the chunk of given reference entity
60 const Entity &reference,
63 /// check if given entity intersects with the world
64 bool Intersection(const Entity &e, std::vector<WorldCollision> &);
65 void Resolve(Entity &e, std::vector<WorldCollision> &);
67 const BlockTypeRegistry &BlockTypes() noexcept { return block_type; }
68 ChunkStore &Chunks() noexcept { return chunks; }
70 /// add player with given name
71 /// returns nullptr if the name is already taken
72 Player *AddPlayer(const std::string &name);
73 /// add player with given name and ID
74 /// returns nullptr if the name or ID is already taken
75 Player *AddPlayer(const std::string &name, std::uint32_t id);
76 /// add an entity with an autogenerated ID
78 /// add entity with given ID
79 /// returns nullptr if the ID is already taken
80 Entity *AddEntity(std::uint32_t id);
81 /// add entity with given ID
82 /// returs an existing entity if ID is already taken
83 Entity &ForceAddEntity(std::uint32_t id);
85 const std::list<Player> &Players() const noexcept { return players; }
86 std::list<Entity> &Entities() noexcept { return entities; }
87 const std::list<Entity> &Entities() const noexcept { return entities; }
91 void Render(Viewport &);
94 using EntityHandle = std::list<Entity>::iterator;
95 EntityHandle RemoveEntity(EntityHandle &);
100 const BlockTypeRegistry &block_type;
103 ChunkIndex &spawn_index;
105 std::list<Player> players;
106 std::list<Entity> entities;
108 glm::vec3 light_direction;