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;
20 struct EntityDerivative;
28 std::string name = "default";
29 // chunk base where new players are spawned
30 glm::ivec3 spawn = { 0, 0, 0 };
31 // direction facing towards(!) the light
32 glm::vec3 light_direction = { -1.0f, -3.0f, -2.0f };
33 // fade out reaches 1/e (0.3679) at 1/fog_density,
34 // gets less than 0.01 at e/(2 * fog_density)
35 // I chose 0.011 because it yields 91 and 124 for those, so
36 // slightly less than 6 and 8 chunks
37 float fog_density = 0.011f;
40 World(const BlockTypeRegistry &, const Config &);
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> &col) {
66 // return Intersection(e, e.GetState(), col);
68 bool Intersection(const Entity &e, const EntityState &, std::vector<WorldCollision> &);
70 const BlockTypeRegistry &BlockTypes() noexcept { return block_type; }
71 ChunkStore &Chunks() noexcept { return chunks; }
73 /// add player with given name
74 /// returns nullptr if the name is already taken
75 Player *AddPlayer(const std::string &name);
76 /// add player with given name and ID
77 /// returns nullptr if the name or ID is already taken
78 Player *AddPlayer(const std::string &name, std::uint32_t id);
79 /// add an entity with an autogenerated ID
81 /// add entity with given ID
82 /// returns nullptr if the ID is already taken
83 Entity *AddEntity(std::uint32_t id);
84 /// add entity with given ID
85 /// returs an existing entity if ID is already taken
86 Entity &ForceAddEntity(std::uint32_t id);
88 const std::list<Player> &Players() const noexcept { return players; }
89 std::list<Entity> &Entities() noexcept { return entities; }
90 const std::list<Entity> &Entities() const noexcept { return entities; }
95 void Update(Entity &, float dt);
97 void Render(Viewport &);
100 using EntityHandle = std::list<Entity>::iterator;
101 EntityHandle RemoveEntity(EntityHandle &);
103 EntityDerivative CalculateStep(
105 const EntityState &cur,
107 const EntityDerivative &prev
109 glm::vec3 CalculateForce(
111 const EntityState &cur
113 glm::vec3 ControlForce(
117 glm::vec3 CollisionForce(
129 const BlockTypeRegistry &block_type;
133 std::list<Player> players;
134 std::list<Entity> entities;
136 glm::vec3 light_direction;