From 8181cff72e7f79296548eb75000746cae34bf032 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:36:36 +1100 Subject: [PATCH] Hopefully fix the rare lightmap flicker --- source/game/StarWorldClient.cpp | 12 ++++-------- source/game/StarWorldClient.hpp | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 470ff42..b2a79fb 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -1403,7 +1403,7 @@ void WorldClient::collectLiquid(List const& tilePositions, LiquidId liqui } void WorldClient::waitForLighting(Image* out) { - MutexLocker lock(m_lightingMutex); + MutexLocker lock(m_lightMapMutex); if (out) *out = move(m_lightMap); } @@ -1648,22 +1648,18 @@ void WorldClient::lightingTileGather() { } void WorldClient::lightingMain() { + MutexLocker condLocker(m_lightingMutex); while (true) { - MutexLocker locker(m_lightingMutex); - m_lightingCond.wait(m_lightingMutex); if (m_stopLightingThread) return; + MutexLocker mapLocker(m_lightMapMutex); int64_t start = Time::monotonicMicroseconds(); lightingTileGather(); m_lightingCalculator.calculate(m_lightMap); + mapLocker.unlock(); LogMap::set("client_render_world_async_light_calc", strf(u8"{:05d}\u00b5s", Time::monotonicMicroseconds() - start)); - - continue; - - locker.unlock(); - Thread::yield(); } } diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index a8080f1..3e9d15e 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -269,9 +269,10 @@ private: CellularLightingCalculator m_lightingCalculator; mutable CellularLightIntensityCalculator m_lightIntensityCalculator; ThreadFunction m_lightingThread; - + Mutex m_lightingMutex; ConditionVariable m_lightingCond; + Mutex m_lightMapMutex; Image m_lightMap; atomic m_stopLightingThread;