summaryrefslogtreecommitdiffstats
path: root/src/RendererWorld.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-08 22:44:17 +0100
committerLaG1924 <12997935+LaG1924@users.noreply.github.com>2018-03-08 22:44:17 +0100
commita4d017a3f2b841788f7e47669c0d0cac9c3f31c8 (patch)
treead14b1f27ee9dff35aaed29e67cb3a912bd5bb46 /src/RendererWorld.cpp
parentSome parsing optimizations (diff)
downloadAltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.tar
AltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.tar.gz
AltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.tar.bz2
AltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.tar.lz
AltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.tar.xz
AltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.tar.zst
AltCraft-a4d017a3f2b841788f7e47669c0d0cac9c3f31c8.zip
Diffstat (limited to '')
-rw-r--r--src/RendererWorld.cpp36
1 files changed, 31 insertions, 5 deletions
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<std::tuple<size_t, Vector>>();
+ auto data = eventData.get<std::tuple<size_t, Vector, bool>>();
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<RendererSectionData>(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<RendererSectionData>(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>();
+ 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);
});