X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fchunk.cpp;h=83c94e3403a14ddd97283739dfe34e0e50fa9696;hb=d2fa8ca97d291508ce3812fb052a8255d3190d00;hp=2d5b7cec853272f1868da71b069760156ab8ca74;hpb=071459d05271dd9376364fc3d8c33bf091724321;p=blank.git diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index 2d5b7ce..83c94e3 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -4,7 +4,7 @@ #include "Generator.hpp" #include "WorldCollision.hpp" -#include "WorldSave.hpp" +#include "../io/WorldSave.hpp" #include #include @@ -440,13 +440,12 @@ void Chunk::Draw() noexcept { bool Chunk::Intersection( const Ray &ray, const glm::mat4 &M, - int &blkid, - float &dist, - glm::vec3 &normal -) const noexcept { + WorldCollision &coll +) noexcept { int idx = 0; - blkid = -1; - dist = std::numeric_limits::infinity(); + coll.chunk = this; + coll.block = -1; + coll.depth = std::numeric_limits::infinity(); for (int z = 0; z < depth; ++z) { for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x, ++idx) { @@ -457,20 +456,20 @@ bool Chunk::Intersection( float cur_dist; glm::vec3 cur_norm; if (type.shape->Intersects(ray, M * ToTransform(Pos(x, y, z), idx), cur_dist, cur_norm)) { - if (cur_dist < dist) { - blkid = idx; - dist = cur_dist; - normal = cur_norm; + if (cur_dist < coll.depth) { + coll.block = idx; + coll.depth = cur_dist; + coll.normal = cur_norm; } } } } } - if (blkid < 0) { + if (coll.block < 0) { return false; } else { - normal = glm::vec3(BlockAt(blkid).Transform() * glm::vec4(normal, 0.0f)); + coll.normal = glm::vec3(BlockAt(coll.block).Transform() * glm::vec4(coll.normal, 0.0f)); return true; } } @@ -480,7 +479,7 @@ bool Chunk::Intersection( const glm::mat4 &Mbox, const glm::mat4 &Mchunk, std::vector &col -) const noexcept { +) noexcept { bool any = false; float penetration; glm::vec3 normal; @@ -772,6 +771,10 @@ std::list::iterator ChunkLoader::Remove(std::list::iterator chunk) ++next; // unlink neighbors so they won't reference a dead chunk chunk->ClearNeighbors(); + // if it should be saved, do it now + if (chunk->ShouldUpdateSave()) { + save.Write(*chunk); + } // and move it from loaded to free list to_free.splice(to_free.end(), loaded, chunk); return next;