X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FChunk.hpp;h=045f58df7d6ac29f1140fea27849cc212aea5e30;hb=ab0ba4313c473378b4516e3702d524dc1d1fc5d4;hp=d0dcf9404219ba063f91fb9b2e5dced933df40e9;hpb=7354c74fb8f409336db3a6d70455fbc10232ae64;p=blank.git diff --git a/src/world/Chunk.hpp b/src/world/Chunk.hpp index d0dcf94..045f58d 100644 --- a/src/world/Chunk.hpp +++ b/src/world/Chunk.hpp @@ -6,6 +6,7 @@ #include "../geometry/Location.hpp" #include "../geometry/primitive.hpp" +#include #include #include #include @@ -34,6 +35,14 @@ public: static glm::vec3 Center() noexcept { return glm::vec3(8.0f); } static float Radius() noexcept { return 27.71281292110203669632f; /* 16 * √3 */ } + /// get bounding box relative to given reference chunk + AABB RelativeBounds(const ExactLocation::Coarse &ref) const noexcept { + AABB bounds; + bounds.min = (position - ref) * ExactLocation::Extent(); + bounds.max = bounds.min + ExactLocation::FExtent(); + return bounds; + } + static constexpr bool InBounds(const ExactLocation::Fine &pos) noexcept { return pos.x >= 0.0f && pos.x < fside && @@ -132,12 +141,15 @@ public: float GetVertexLight(const RoughLocation::Fine &, const BlockMesh::Position &, const EntityMesh::Normal &) const noexcept; + /// get gravity for one unit mass at given point + glm::vec3 GravityAt(const ExactLocation &) const noexcept; + bool Intersection( const Ray &ray, const ExactLocation::Coarse &reference, float &dist ) const noexcept { - return blank::Intersection(ray, Bounds(), Transform(reference), &dist); + return blank::Intersection(ray, RelativeBounds(reference), dist); } /// check if given ray intersects any block of this chunk @@ -175,6 +187,10 @@ public: bool Lighted() const noexcept { return lighted; } void ScanLights(); + /// check for active blocks, should be called after + /// block data was modified by means other than SetBlock() + void ScanActive(); + void Ref() noexcept { ++ref_count; } void UnRef() noexcept { --ref_count; } bool Referenced() const noexcept { return ref_count > 0; } @@ -192,6 +208,8 @@ private: const BlockTypeRegistry *types; Chunk *neighbor[Block::FACE_COUNT]; + std::set gravity; + Block blocks[size]; unsigned char light[size]; bool generated;