X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fchunk.cpp;h=77899e79d5da360506502ae8954e54bf56648a3c;hb=34a7fafb4c2d4ed95eb990eda5c02d5c79d3411b;hp=ef3c5fc869d80acb94d4ec054462ce2d85c9cc64;hpb=46b18a88fdda816f3c2c547aba68b0a5ea7970f7;p=blank.git diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index ef3c5fc..77899e7 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -65,9 +65,13 @@ struct SetNode { int Get() const noexcept { return chunk->GetLight(pos); } void Set(int level) noexcept { chunk->SetLight(pos, level); } + const BlockType &GetType() const noexcept { return chunk->Type(Chunk::ToIndex(pos)); } + bool HasNext(Block::Face face) noexcept { + const BlockType &type = GetType(); + if (type.block_light && !type.luminosity) return false; const BlockLookup next(chunk, pos, face); - return next && !next.GetType().block_light; + return next; } SetNode GetNext(Block::Face face) noexcept { const BlockLookup next(chunk, pos, face); @@ -315,7 +319,7 @@ int Chunk::GetLight(int index) const noexcept { return light[index]; } -float Chunk::GetVertexLight(const Pos &pos, const BlockModel::Position &vtx, const Model::Normal &norm) const noexcept { +float Chunk::GetVertexLight(const Pos &pos, const BlockModel::Position &vtx, const EntityModel::Normal &norm) const noexcept { int index = ToIndex(pos); float light = GetLight(index); @@ -838,9 +842,20 @@ void ChunkLoader::Update(int dt) { // check if a chunk generation is scheduled for this frame // and if there's a chunk waiting to be generated gen_timer.Update(dt); - if (!gen_timer.Hit() || to_generate.empty()) { - return; + if (gen_timer.Hit()) { + LoadOne(); + } +} + +void ChunkLoader::LoadN(std::size_t n) { + std::size_t end = std::min(n, ToLoad()); + for (std::size_t i = 0; i < end; ++i) { + LoadOne(); } +} + +void ChunkLoader::LoadOne() { + if (to_generate.empty()) return; // take position of next chunk in queue Chunk::Pos pos(to_generate.front());