1 #ifndef BLANK_WORLD_WORLD_HPP_
2 #define BLANK_WORLD_WORLD_HPP_
4 #include "ChunkLoader.hpp"
6 #include "Generator.hpp"
12 #include <glm/glm.hpp>
17 class BlockTypeRegistry;
18 class EntityCollision;
26 std::string name = "default";
27 // initial player position
28 glm::vec3 spawn = { 0.0f, 0.0f, 0.0f };
29 // direction facing towards(!) the light
30 glm::vec3 light_direction = { -1.0f, -3.0f, -2.0f };
31 // fade out reaches 1/e (0.3679) at 1/fog_density,
32 // gets less than 0.01 at e/(2 * fog_density)
33 // I chose 0.011 because it yields 91 and 124 for those, so
34 // slightly less than 6 and 8 chunks
35 float fog_density = 0.011f;
37 Generator::Config gen = Generator::Config();
38 ChunkLoader::Config load = ChunkLoader::Config();
41 World(const BlockTypeRegistry &, const Config &, const WorldSave &);
43 const std::string &Name() const noexcept { return config.name; }
45 /// check if this ray hits a block
46 /// depth in the collision is the distance between the ray's
47 /// origin and the intersection point
48 /// M is the global transform for given reference chunk
52 const Chunk::Pos &reference,
55 /// check if this ray hits an entity
56 /// intersections with the reference are not tested
57 /// M is the global transform for the chunk of given reference entity
61 const Entity &reference,
64 /// check if given entity intersects with the world
65 bool Intersection(const Entity &e, std::vector<WorldCollision> &);
66 void Resolve(Entity &e, std::vector<WorldCollision> &);
68 const BlockTypeRegistry &BlockTypes() noexcept { return block_type; }
69 ChunkLoader &Loader() noexcept { return chunks; }
71 /// add player with given name
72 /// returns nullptr if the name is already taken
73 Entity *AddPlayer(const std::string &name);
74 /// add player with given name and ID
75 /// returns nullptr if the name or ID is already taken
76 Entity *AddPlayer(const std::string &name, std::uint32_t id);
77 /// add an entity with an autogenerated ID
79 /// add entity with given ID
80 /// returns nullptr if the ID is already taken
81 Entity *AddEntity(std::uint32_t id);
83 const std::vector<Entity *> &Players() const noexcept { return players; }
84 const std::list<Entity> &Entities() const noexcept { return entities; }
88 void Render(Viewport &);
93 const BlockTypeRegistry &block_type;
98 std::vector<Entity *> players;
99 std::list<Entity> entities;
101 glm::vec3 light_direction;