X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FWorld.hpp;h=3981b28e336f9dcf8e28ee84411486d1e23121d2;hb=dbfcb12348b80e2582f710acb1e4ed0011889ba2;hp=b98efca544ef0969af3f056075b43f039986e80f;hpb=549646ac3e5bede5e77031f773649edf8de83608;p=blank.git diff --git a/src/world/World.hpp b/src/world/World.hpp index b98efca..3981b28 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -1,11 +1,9 @@ #ifndef BLANK_WORLD_WORLD_HPP_ #define BLANK_WORLD_WORLD_HPP_ -#include "BlockTypeRegistry.hpp" #include "ChunkLoader.hpp" #include "Entity.hpp" #include "Generator.hpp" -#include "../model/shapes.hpp" #include #include @@ -14,6 +12,8 @@ namespace blank { +class BlockTypeRegistry; +class EntityCollision; class Viewport; class WorldCollision; @@ -35,42 +35,55 @@ public: ChunkLoader::Config load = ChunkLoader::Config(); }; - explicit World(const Config &); + World(const BlockTypeRegistry &, const Config &, const WorldSave &); + /// check if this ray hits a block + /// depth in the collision is the distance between the ray's + /// origin and the intersection point + /// M is the global transform for given reference chunk bool Intersection( const Ray &, const glm::mat4 &M, - Chunk *&chunk, - int &blkid, - float &dist, - glm::vec3 &normal); + const Chunk::Pos &reference, + WorldCollision &); + /// check if this ray hits an entity + /// intersections with the reference are not tested + /// M is the global transform for the chunk of given reference entity + bool Intersection( + const Ray &, + const glm::mat4 &M, + const Entity &reference, + EntityCollision &); + + /// check if given entity intersects with the world bool Intersection(const Entity &e, std::vector &); void Resolve(Entity &e, std::vector &); - BlockTypeRegistry &BlockTypes() noexcept { return blockType; } + const BlockTypeRegistry &BlockTypes() noexcept { return block_type; } ChunkLoader &Loader() noexcept { return chunks; } - Entity &Player() { return *player; } + /// add player with given name + /// returns nullptr if the name is already taken + Entity *AddPlayer(const std::string &name); Entity &AddEntity() { entities.emplace_back(); return entities.back(); } - Chunk &PlayerChunk(); - Chunk &Next(const Chunk &to, const glm::ivec3 &dir); + const std::vector &Players() const noexcept { return players; } + const std::list &Entities() const noexcept { return entities; } void Update(int dt); void Render(Viewport &); private: - BlockTypeRegistry blockType; - CuboidShape blockShape; - StairShape stairShape; - CuboidShape slabShape; + Config config; + + const BlockTypeRegistry &block_type; Generator generate; ChunkLoader chunks; - Entity *player; + std::vector players; std::list entities; glm::vec3 light_direction;