X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FWorld.hpp;h=3981b28e336f9dcf8e28ee84411486d1e23121d2;hb=dbfcb12348b80e2582f710acb1e4ed0011889ba2;hp=7f38942ea2e4d9b4389dc97e2a430a1458951ff3;hpb=c04ea5a6f67d446ea29aa2e88dc4c666956d7732;p=blank.git diff --git a/src/world/World.hpp b/src/world/World.hpp index 7f38942..3981b28 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -1,20 +1,21 @@ #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 #include namespace blank { -class BlockLighting; -class DirectionalLighting; +class BlockTypeRegistry; +class EntityCollision; +class Viewport; +class WorldCollision; class World { @@ -34,40 +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 &); - bool Intersection(const Entity &e); + /// 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 &); - BlockTypeRegistry &BlockTypes() { return blockType; } + /// check if given entity intersects with the world + bool Intersection(const Entity &e, std::vector &); + void Resolve(Entity &e, std::vector &); - Entity &Player() { return *player; } + const BlockTypeRegistry &BlockTypes() noexcept { return block_type; } + ChunkLoader &Loader() noexcept { return chunks; } + + /// 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::tvec3 &dir); + const std::vector &Players() const noexcept { return players; } + const std::list &Entities() const noexcept { return entities; } void Update(int dt); - void Render(BlockLighting &, DirectionalLighting &); + 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;