]> git.localhorst.tv Git - blank.git/blobdiff - src/world/chunk.cpp
move block type loading details to BlockType
[blank.git] / src / world / chunk.cpp
index 9e95458ef45ac7b9b818cd40d32193bc52fc9f51..1d120bb2ebe8d2475a4be2ac1bc4799755b8d25d 100644 (file)
@@ -84,6 +84,9 @@ struct SetNode {
 
        const BlockType &GetType() const noexcept { return chunk->Type(Chunk::ToIndex(pos)); }
 
+       int EmitLevel() const noexcept { return GetType().luminosity; }
+       bool EmitsLight() const noexcept { return EmitLevel() > 0; }
+
        bool HasNext(Block::Face face) noexcept {
                const BlockType &type = GetType();
                if (type.block_light && !type.luminosity) return false;
@@ -146,9 +149,13 @@ void work_dark() noexcept {
                for (int face = 0; face < Block::FACE_COUNT; ++face) {
                        if (node.HasNext(Block::Face(face))) {
                                UnsetNode other = node.GetNext(Block::Face(face));
-                               // TODO: if there a light source here with the same level this will err
                                if (other.Get() != 0 && other.Get() < node.level) {
-                                       other.Set(0);
+                                       if (other.EmitsLight()) {
+                                               other.Set(other.EmitLevel());
+                                               light_queue.emplace(other);
+                                       } else {
+                                               other.Set(0);
+                                       }
                                        dark_queue.emplace(other);
                                } else {
                                        light_queue.emplace(other);
@@ -453,7 +460,7 @@ bool Chunk::Intersection(
        const glm::vec3 entity_coords(Mentity[3] - Mchunk[3]);
        const float ec_radius = entity.Radius() + Radius();
 
-       if (distance_squared(entity_coords, Center()) > ec_radius * ec_radius) {
+       if (distance2(entity_coords, Center()) > ec_radius * ec_radius) {
                return false;
        }
 
@@ -772,6 +779,7 @@ void ChunkRenderer::Render(Viewport &viewport) {
 
        for (int i = 0; i < index.TotalChunks(); ++i) {
                if (!index[i]) continue;
+               // TODO: optimize chunk culling, shoudn't be that hard
                glm::mat4 m(index[i]->Transform(index.Base()));
                glm::mat4 mvp(chunk_prog.GetVP() * m);
                if (!CullTest(Chunk::Bounds(), mvp)) {