From a4d017a3f2b841788f7e47669c0d0cac9c3f31c8 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Fri, 9 Mar 2018 02:44:17 +0500 Subject: Fixed holes when block on section border destroyed --- src/RendererSectionData.hpp | 1 + src/RendererWorld.cpp | 36 +++++++++++++++++++++++++++++++----- src/World.cpp | 16 ++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index ca652f4..42e1a06 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -15,6 +15,7 @@ struct RendererSectionData { std::vector lights; size_t hash = 0; Vector sectionPos; + bool forced = false; }; RendererSectionData ParseSection(World *world, Vector sectionPosition); \ No newline at end of file diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index 3630a7a..7354c7c 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -17,17 +17,19 @@ void RendererWorld::WorkerFunction(size_t workerId) { EventListener tasksListener; tasksListener.RegisterHandler("RendererWorkerTask", [&](const Event& eventData) { - auto data = eventData.get>(); + auto data = eventData.get>(); if (std::get<0>(data) != workerId) return; Vector vec = std::get<1>(data); + auto forced = std::get<2>(data); sectionsMutex.lock(); auto result = sections.find(vec); if (result != sections.end()) { - if (result->second.GetHash() != gs->world.GetSection(result->first).GetHash()) { + if (result->second.GetHash() != gs->world.GetSection(result->first).GetHash() || forced) { sectionsMutex.unlock(); auto data = std::make_unique(ParseSection(&gs->world, vec)); + data->forced = true; renderDataMutex.lock(); renderData.push(std::move(data)); renderDataMutex.unlock(); @@ -43,6 +45,7 @@ void RendererWorld::WorkerFunction(size_t workerId) { else { sectionsMutex.unlock(); auto data = std::make_unique(ParseSection(&gs->world, vec)); + data->forced = true; renderDataMutex.lock(); renderData.push(std::move(data)); renderDataMutex.unlock(); @@ -133,10 +136,9 @@ RendererWorld::RendererWorld(GameState* ptr) { sectionsMutex.lock(); if (sections.find(data->sectionPos) != sections.end()) { - if (sections.find(data->sectionPos)->second.GetHash() == data->hash) { + if (sections.find(data->sectionPos)->second.GetHash() == data->hash && !data->forced) { LOG(INFO) << "Generated not necesarry RendererData"; sectionsMutex.unlock(); - renderData.pop(); continue; } sections.erase(sections.find(data->sectionPos)); @@ -176,11 +178,35 @@ RendererWorld::RendererWorld(GameState* ptr) { isParsing[vec] = true; isParsingMutex.unlock(); - PUSH_EVENT("RendererWorkerTask", std::make_tuple(currentWorker++, vec)); + PUSH_EVENT("RendererWorkerTask", std::make_tuple(currentWorker++, vec, false)); if (currentWorker >= numOfWorkers) currentWorker = 0; }); + listener->RegisterHandler("ChunkChangedForce", [this](const Event& eventData) { + auto vec = eventData.get(); + Vector playerChunk(std::floor(gs->player->pos.x / 16), 0, std::floor(gs->player->pos.z / 16)); + + double distanceToChunk = (Vector(vec.x, 0, vec.z) - playerChunk).GetLength(); + if (MaxRenderingDistance != 1000 && distanceToChunk > MaxRenderingDistance) { + return; + } + + isParsingMutex.lock(); + if (isParsing.find(vec) == isParsing.end()) + isParsing[vec] = false; + if (isParsing[vec] == true) { + isParsingMutex.unlock(); + return; + } + isParsing[vec] = true; + isParsingMutex.unlock(); + + PUSH_EVENT("RendererWorkerTask", std::make_tuple(currentWorker++, vec, true)); + if (currentWorker >= numOfWorkers) + currentWorker = 0; + }); + listener->RegisterHandler("UpdateSectionsRender", [this](const Event&) { UpdateAllSections(gs->player->pos); }); diff --git a/src/World.cpp b/src/World.cpp index 59399f5..67abc02 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -350,10 +350,22 @@ void World::SetBlockId(Vector pos, BlockId block) { Vector sectionPos(std::floor(pos.x / 16.0), std::floor(pos.y / 16.0), std::floor(pos.z / 16.0)); - + Vector blockPos = pos - (sectionPos * 16); Section* section = GetSectionPtr(sectionPos); - section->SetBlockId(pos - (sectionPos * 16), block); + section->SetBlockId(blockPos, block); PUSH_EVENT("ChunkChanged",sectionPos); + if (blockPos.x == 0) + PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(-1, 0, 0)); + if (blockPos.x == 15) + PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(1, 0, 0)); + if (blockPos.y == 0) + PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(0, -1, 0)); + if (blockPos.y == 15) + PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(0, 1, 0)); + if (blockPos.z == 0) + PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(0, 0, -1)); + if (blockPos.z == 15) + PUSH_EVENT("ChunkChangedForce", sectionPos + Vector(0, 0, 1)); } void World::SetBlockLight(Vector pos, unsigned char light) { -- cgit v1.2.3