]> git.localhorst.tv Git - blank.git/commitdiff
fixed oriented block occlusion check
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 13 Mar 2015 20:10:43 +0000 (21:10 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 13 Mar 2015 20:10:43 +0000 (21:10 +0100)
src/block.cpp
src/block.hpp
src/chunk.cpp

index c9fceec85aeb6da7ebe03381bd3af182cf1ac22f..50ade3901fd65aebdf96ef29ebd2499fc6ffbf41 100644 (file)
@@ -56,6 +56,41 @@ BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s)
 
 }
 
+namespace {
+
+const Block::Face face_map[Block::FACE_COUNT * Block::TURN_COUNT][Block::FACE_COUNT] = {
+       { Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_FRONT, Block::FACE_BACK,  }, // face: up,    turn: none x
+       { Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_LEFT,  Block::FACE_RIGHT, }, // face: up,    turn: left
+       { Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_BACK,  Block::FACE_FRONT, }, // face: up,    turn: around
+       { Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_RIGHT, Block::FACE_LEFT,  }, // face: up,    turn: right
+       { Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_BACK,  Block::FACE_FRONT, }, // face: down,  turn: none
+       { Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_LEFT,  Block::FACE_RIGHT, }, // face: down,  turn: left
+       { Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_FRONT, Block::FACE_BACK,  }, // face: down,  turn: around
+       { Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_RIGHT, Block::FACE_LEFT,  }, // face: down,  turn: right
+       { Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_FRONT, Block::FACE_BACK,  }, // face: right, turn: none
+       { Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_DOWN,  Block::FACE_UP,    }, // face: right, turn: left
+       { Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_BACK,  Block::FACE_FRONT, }, // face: right, turn: around
+       { Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_UP,    Block::FACE_DOWN,  }, // face: right, turn: right
+       { Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_FRONT, Block::FACE_BACK,  }, // face: left,  turn: none
+       { Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_UP,    Block::FACE_DOWN,  }, // face: left,  turn: left
+       { Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_BACK,  Block::FACE_FRONT, }, // face: left,  turn: around
+       { Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_DOWN,  Block::FACE_UP,    }, // face: left,  turn: right
+       { Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_UP,    Block::FACE_DOWN,  }, // face: front, turn: none
+       { Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_LEFT,  Block::FACE_RIGHT, }, // face: front, turn: left
+       { Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_DOWN,  Block::FACE_UP,    }, // face: front, turn: around
+       { Block::FACE_BACK,  Block::FACE_FRONT, Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_RIGHT, Block::FACE_LEFT,  }, // face: front, turn: right
+       { Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_RIGHT, Block::FACE_LEFT,  Block::FACE_DOWN,  Block::FACE_UP,    }, // face: back,  turn: none
+       { Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_DOWN,  Block::FACE_UP,    Block::FACE_LEFT,  Block::FACE_RIGHT, }, // face: back,  turn: left
+       { Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_LEFT,  Block::FACE_RIGHT, Block::FACE_UP,    Block::FACE_DOWN,  }, // face: back,  turn: around
+       { Block::FACE_FRONT, Block::FACE_BACK,  Block::FACE_UP,    Block::FACE_DOWN,  Block::FACE_RIGHT, Block::FACE_LEFT,  }, // face: back,  turn: right
+};
+
+}
+
+bool BlockType::FaceFilled(const Block &block, Block::Face face) const {
+       return fill[face_map[block.orient][face]];
+}
+
 void BlockType::FillModel(
        Model::Buffer &buf,
        const glm::mat4 &transform,
index 3ccd74f71937f523473536910d1a28d4cfaf964b..72954ce596a6b846c2b14e0ac8227064c3c7d792 100644 (file)
@@ -61,14 +61,17 @@ struct BlockType {
 
        bool visible;
 
-       // FIXME: fill faces don't respect block orientation
        struct Faces {
-               bool up;
-               bool down;
-               bool right;
-               bool left;
-               bool front;
-               bool back;
+               bool face[Block::FACE_COUNT];
+               Faces &operator =(const Faces &other) {
+                       for (int i = 0; i < Block::FACE_COUNT; ++i) {
+                               face[i] = other.face[i];
+                       }
+                       return *this;
+               }
+               bool operator [](Block::Face f) const {
+                       return face[f];
+               }
        } fill;
 
        explicit BlockType(
@@ -79,6 +82,7 @@ struct BlockType {
 
        static const NullShape DEFAULT_SHAPE;
 
+       bool FaceFilled(const Block &, Block::Face) const;
 
        void FillModel(
                Model::Buffer &m,
index e61a3a70ba0260a2600f8498fb4c24996c1c89d3..ae13aec24c4e6de4de2d6e429dcf662bcb98a9d3 100644 (file)
@@ -136,23 +136,23 @@ bool Chunk::Obstructed(int idx) const {
        // invisible blocks must have their fill set to 6x false
        // (the default, so should be okay)
 
-       const BlockType &right = Type(blocks[idx + 1]);
-       if (!right.fill.left) return false;
+       const Block &right = blocks[idx + 1];
+       if (!Type(right).FaceFilled(right, Block::FACE_LEFT)) return false;
 
-       const BlockType &left = Type(blocks[idx - 1]);
-       if (!left.fill.right) return false;
+       const Block &left = blocks[idx - 1];
+       if (!Type(left).FaceFilled(left, Block::FACE_RIGHT)) return false;
 
-       const BlockType &up = Type(blocks[idx + Width()]);
-       if (!up.fill.down) return false;
+       const Block &up = blocks[idx + Width()];
+       if (!Type(up).FaceFilled(up, Block::FACE_DOWN)) return false;
 
-       const BlockType &down = Type(blocks[idx - Width()]);
-       if (!down.fill.up) return false;
+       const Block &down = blocks[idx - Width()];
+       if (!Type(down).FaceFilled(down, Block::FACE_UP)) return false;
 
-       const BlockType &front = Type(blocks[idx + Width() * Height()]);
-       if (!front.fill.back) return false;
+       const Block &front = blocks[idx + Width() * Height()];
+       if (!Type(front).FaceFilled(front, Block::FACE_BACK)) return false;
 
-       const BlockType &back = Type(blocks[idx - Width() * Height()]);
-       if (!back.fill.front) return false;
+       const Block &back = blocks[idx - Width() * Height()];
+       if (!Type(back).FaceFilled(back, Block::FACE_FRONT)) return false;
 
        return true;
 }