From 4ad6c854c84d9de13f85e183b81b5926fa835efc Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 6 Aug 2023 16:09:42 -0500 Subject: [PATCH] update comment in ChunkWrapper --- .../common/wrappers/chunk/ChunkWrapper.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java index 756a30c5f..6992e10f9 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java @@ -75,16 +75,18 @@ public class ChunkWrapper implements IChunkWrapper private final boolean useDhLightingEngine; - // Due to vanilla `isClientLightReady()` not designed to be used by non-render thread, that value may return 'true' - // just before the light engine is ticked, (right after all light changes is marked to the engine to be processed). - // To fix this, on client-only mode, we mixin-redirect the `isClientLightReady()` so that after the call, it will - // trigger a synchronous update of this flag here on all chunks that are wrapped. - // - // Note: Using a static weak hash map to store the chunks that need to be updated, as instance of chunk wrapper - // can be duplicated, with same chunk instance. And the data stored here are all temporary, and thus will not be - // visible when a chunk is re-wrapped later. - // (Also, thread safety done via a reader writer lock) - private final static WeakHashMap chunksToUpdateClientLightReady = new WeakHashMap<>(); + /** + * Due to vanilla `isClientLightReady()` not designed to be used by non-render thread, that value may return 'true' + * just before the light engine is ticked, (right after all light changes is marked to the engine to be processed). + * To fix this, on client-only mode, we mixin-redirect the `isClientLightReady()` so that after the call, it will + * trigger a synchronous update of this flag here on all chunks that are wrapped.

+ * + * Note: Using a static weak hash map to store the chunks that need to be updated, as instance of chunk wrapper + * can be duplicated, with same chunk instance. And the data stored here are all temporary, and thus will not be + * visible when a chunk is re-wrapped later.
+ * (Also, thread safety done via a reader writer lock) + */ + private final static WeakHashMap chunksToUpdateClientLightReady = new WeakHashMap<>(); // TODO this is never cleared private final static ReentrantReadWriteLock weakMapLock = new ReentrantReadWriteLock(); @@ -400,7 +402,8 @@ public class ChunkWrapper implements IChunkWrapper { chunksToUpdateClientLightReady.replaceAll(ChunkWrapper::updateClientLightReady); } - finally { + finally + { weakMapLock.writeLock().unlock(); } #endif