X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fchunk.cpp;h=16ff4e5023bb65f4f68495294b7b940007b67239;hb=a58c4558e7d4934f4d0ee621520acfe1c8258c93;hp=bed947e3d5fdfff7182056313a30667ad9996edb;hpb=f932e8c0273794bcd954c9f5b504bad6140f7cf4;p=blank.git diff --git a/src/chunk.cpp b/src/chunk.cpp index bed947e..16ff4e5 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -137,6 +137,8 @@ void Chunk::Update() { Model::Index vtx_counter = 0; for (size_t i = 0; i < Size(); ++i) { + if (Obstructed(i)) continue; + const BlockType &type = Type(blocks[i]); type.FillModel(buf, ToCoords(i), vtx_counter); vtx_counter += type.shape->VertexCount(); @@ -146,6 +148,34 @@ void Chunk::Update() { dirty = false; } +bool Chunk::Obstructed(int idx) const { + if (IsBorder(idx)) return false; + + // not checking neighbor visibility here, so all + // 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 BlockType &left = Type(blocks[idx - 1]); + if (!left.fill.right) return false; + + const BlockType &top = Type(blocks[idx + Width()]); + if (!top.fill.bottom) return false; + + const BlockType &bottom = Type(blocks[idx - Width()]); + if (!bottom.fill.top) return false; + + const BlockType &front = Type(blocks[idx + Width() * Height()]); + if (!front.fill.back) return false; + + const BlockType &back = Type(blocks[idx - Width() * Height()]); + if (!back.fill.front) return false; + + return true; +} + ChunkLoader::ChunkLoader(const BlockTypeRegistry ®, const Generator &gen) : base(0, 0, 0)