]> git.localhorst.tv Git - blank.git/blobdiff - src/world/chunk.cpp
fix iteration in entity/world intersection
[blank.git] / src / world / chunk.cpp
index e93966e959ce13d4678dfaa3f5870ffcade50e17..d124eb7373c8b4d34ab65406f4db4bb0cf350ffe 100644 (file)
@@ -368,7 +368,7 @@ float Chunk::GetVertexLight(const RoughLocation::Fine &pos, const BlockMesh::Pos
 
 
 glm::vec3 Chunk::GravityAt(const ExactLocation &coords) const noexcept {
-       glm::vec3 grav;
+       glm::vec3 grav(0.0f);
        for (int index : gravity) {
                RoughLocation::Fine block_pos(ToPos(index));
                ExactLocation block_coords(position, ToCoords(block_pos));
@@ -1075,7 +1075,7 @@ ChunkIndex *ChunkStore::ClosestIndex(const ExactLocation::Coarse &pos) {
        return closest_index;
 }
 
-Chunk *ChunkStore::Get(const ExactLocation::Coarse &pos) {
+Chunk *ChunkStore::Get(const ExactLocation::Coarse &pos) noexcept {
        for (ChunkIndex &index : indices) {
                Chunk *chunk = index.Get(pos);
                if (chunk) {
@@ -1085,6 +1085,16 @@ Chunk *ChunkStore::Get(const ExactLocation::Coarse &pos) {
        return nullptr;
 }
 
+const Chunk *ChunkStore::Get(const ExactLocation::Coarse &pos) const noexcept {
+       for (const ChunkIndex &index : indices) {
+               const Chunk *chunk = index.Get(pos);
+               if (chunk) {
+                       return chunk;
+               }
+       }
+       return nullptr;
+}
+
 Chunk *ChunkStore::Allocate(const ExactLocation::Coarse &pos) {
        Chunk *chunk = Get(pos);
        if (chunk) {