From: Daniel Karbach Date: Fri, 13 Mar 2015 20:10:43 +0000 (+0100) Subject: fixed oriented block occlusion check X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=75e72685a7398d2e30d51fadeaacde849518e188;p=blank.git fixed oriented block occlusion check --- diff --git a/src/block.cpp b/src/block.cpp index c9fceec..50ade39 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -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, diff --git a/src/block.hpp b/src/block.hpp index 3ccd74f..72954ce 100644 --- a/src/block.hpp +++ b/src/block.hpp @@ -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, diff --git a/src/chunk.cpp b/src/chunk.cpp index e61a3a7..ae13aec 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -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; }