]> git.localhorst.tv Git - blank.git/blobdiff - src/chunk.cpp
added ability to get seperate information about block face obstruction
[blank.git] / src / chunk.cpp
index 2a764f31c1c637435feb7738161a42f576f997b9..23d5a13c260e8dfdefab8e5ec3f444a8a537967f 100644 (file)
@@ -322,7 +322,7 @@ int Chunk::GetLight(int index) const {
        return light[index];
 }
 
-float Chunk::GetVertexLight(int index, const BlockModel::Position &vtx, const BlockModel::Normal &norm) const {
+float Chunk::GetVertexLight(int index, const BlockModel::Position &vtx, const Model::Normal &norm) const {
        float light = GetLight(index);
        Chunk::Pos pos(ToPos(index));
 
@@ -445,14 +445,18 @@ void Chunk::Update() {
        for (size_t i = 0; i < Size(); ++i) {
                const BlockType &type = Type(blocks[i]);
 
-               if (!type.visible || Obstructed(i)) continue;
+               if (!type.visible || Obstructed(i).All()) continue;
 
                type.FillBlockModel(buf, ToTransform(i), vtx_counter);
                size_t vtx_begin = vtx_counter;
                vtx_counter += type.shape->VertexCount();
 
                for (size_t vtx = vtx_begin; vtx < vtx_counter; ++vtx) {
-                       buf.lights.emplace_back(GetVertexLight(i, buf.vertices[vtx], buf.normals[vtx]));
+                       buf.lights.emplace_back(GetVertexLight(
+                               i,
+                               buf.vertices[vtx],
+                               type.shape->VertexNormal(vtx - vtx_begin, blocks[i].Transform())
+                       ));
                }
        }
 
@@ -460,18 +464,19 @@ void Chunk::Update() {
        dirty = false;
 }
 
-bool Chunk::Obstructed(int idx) const {
+Block::FaceSet Chunk::Obstructed(int idx) const {
        Chunk::Pos pos(ToPos(idx));
+       Block::FaceSet result;
 
        for (int f = 0; f < Block::FACE_COUNT; ++f) {
                Block::Face face = Block::Face(f);
                BlockLookup next(const_cast<Chunk *>(this), pos, face);
-               if (!next || !next.GetType().FaceFilled(next.GetBlock(), Block::Opposite(face))) {
-                       return false;
+               if (next && next.GetType().FaceFilled(next.GetBlock(), Block::Opposite(face))) {
+                       result.Set(face);
                }
        }
 
-       return true;
+       return result;
 }
 
 glm::mat4 Chunk::ToTransform(int idx) const {