]> git.localhorst.tv Git - blank.git/commitdiff
added ability to get seperate information about block face obstruction
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 27 May 2015 16:50:52 +0000 (18:50 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 29 May 2015 11:16:25 +0000 (13:16 +0200)
src/block.hpp
src/chunk.cpp
src/chunk.hpp

index 4fcee4cac2f0c2a6e7be58d095e6ee16c982870e..3af80a854f29cc8945201b6af8d9babfd855c60a 100644 (file)
@@ -87,6 +87,43 @@ struct Block {
                }
        }
 
+       struct FaceSet {
+
+               explicit FaceSet(unsigned char v = 0)
+               : value(v) { }
+
+               bool IsSet(Face f) const {
+                       return value & Mask(f);
+               }
+               void Set(Face f) {
+                       value |= Mask(f);
+               }
+               void Unset(Face f) {
+                       value |= ~Mask(f);
+               }
+
+               void Clear() {
+                       value = 0;
+               }
+               void Fill() {
+                       value = Mask(FACE_COUNT) - 1;
+               }
+
+               bool Empty() const {
+                       return value == 0;
+               }
+               bool All() const {
+                       return value == Mask(FACE_COUNT) - 1;
+               }
+
+               unsigned char Mask(Face f) const {
+                       return 1 << f;
+               }
+
+               unsigned char value;
+
+       };
+
 };
 
 
index 74ca1bcf96933274f9560cbb151e8629177eeb0c..23d5a13c260e8dfdefab8e5ec3f444a8a537967f 100644 (file)
@@ -445,7 +445,7 @@ 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;
@@ -464,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 {
index 4addb56d7a9bf9b87935664dba54fdfe266756f7..06dc98bab34075ba0234103a572f1f17b55609b9 100644 (file)
@@ -88,8 +88,8 @@ public:
        void Unlink();
        void Relink();
 
-       // check if block at given index is completely enclosed (and therefore invisible)
-       bool Obstructed(int idx) const;
+       // check which faces of a block at given index are obstructed (and therefore invisible)
+       Block::FaceSet Obstructed(int idx) const;
 
        void Invalidate() { dirty = true; }