X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fchunk.cpp;h=800012e601cfa1cdc966b70f09ebd5876982e002;hb=ba55bf4293f3abc742eef710545a4b207ba2c820;hp=bd2d426f1005b8fc0088429117a49011ee7276c3;hpb=3a487f44c26f9bb9d1a1c831406b6497b2b3b425;p=blank.git diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index bd2d426..800012e 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -371,7 +371,7 @@ bool Chunk::Intersection( for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x, ++idx) { const BlockType &type = Type(idx); - if (!type.visible) { + if (!type.collision || !type.shape) { continue; } float cur_dist; @@ -412,7 +412,7 @@ bool Chunk::Intersection( for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x, ++idx) { const BlockType &type = Type(idx); - if (!type.collision) { + if (!type.collision || !type.shape) { continue; } if (type.shape->Intersects(Mchunk * ToTransform(Pos(x, y, z), idx), box, Mbox, penetration, normal)) { @@ -435,33 +435,37 @@ BlockMesh::Buffer buf; void Chunk::Update(BlockMesh &model) noexcept { int vtx_count = 0, idx_count = 0; for (const auto &block : blocks) { - const CollisionBounds *shape = Type(block).shape; - vtx_count += shape->VertexCount(); - idx_count += shape->VertexIndexCount(); + const BlockType &type = Type(block); + if (type.visible && type.shape) { + vtx_count += type.shape->VertexCount(); + idx_count += type.shape->IndexCount(); + } } buf.Clear(); buf.Reserve(vtx_count, idx_count); - int idx = 0; - BlockMesh::Index vtx_counter = 0; - for (size_t z = 0; z < depth; ++z) { - for (size_t y = 0; y < height; ++y) { - for (size_t x = 0; x < width; ++x, ++idx) { - const BlockType &type = Type(BlockAt(idx)); - const Pos pos(x, y, z); - - if (!type.visible || Obstructed(pos).All()) continue; - - type.FillBlockMesh(buf, ToTransform(pos, idx), 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( - pos, - buf.vertices[vtx], - type.shape->VertexNormal(vtx - vtx_begin, BlockAt(idx).Transform()) - )); + if (idx_count > 0) { + int idx = 0; + BlockMesh::Index vtx_counter = 0; + for (size_t z = 0; z < depth; ++z) { + for (size_t y = 0; y < height; ++y) { + for (size_t x = 0; x < width; ++x, ++idx) { + const BlockType &type = Type(BlockAt(idx)); + const Pos pos(x, y, z); + + if (!type.visible || !type.shape || Obstructed(pos).All()) continue; + + type.FillBlockMesh(buf, ToTransform(pos, idx), 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( + pos, + buf.vertices[vtx], + type.shape->VertexNormal(vtx - vtx_begin, BlockAt(idx).Transform()) + )); + } } } }