From 479d92b5737c4530116f22c7e0371864696034cb Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 30 Jan 2017 20:42:14 +1100 Subject: [PATCH] synchronize NMSRelighter map as switched to fastutil --- .../com/boydti/fawe/example/NMSRelighter.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java index 94ed4590..d4b6b8e8 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSRelighter.java @@ -45,7 +45,7 @@ public class NMSRelighter implements Relighter{ return skyToRelight.isEmpty() && lightQueue.isEmpty(); } - public boolean addChunk(int cx, int cz, byte[] fix, int bitmask) { + public synchronized boolean addChunk(int cx, int cz, byte[] fix, int bitmask) { long pair = MathMan.pairInt(cx, cz); RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask); RelightSkyEntry existing = skyToRelight.put(pair, toPut); @@ -60,7 +60,7 @@ public class NMSRelighter implements Relighter{ return true; } - public void removeLighting() { + public synchronized void removeLighting() { Iterator> iter = skyToRelight.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = iter.next(); @@ -75,7 +75,7 @@ public class NMSRelighter implements Relighter{ } } - public void updateBlockLight(Map> map) { + public synchronized void updateBlockLight(Map> map) { int size = map.size(); if (size == 0) { return; @@ -107,7 +107,7 @@ public class NMSRelighter implements Relighter{ IntegerTrio node = new IntegerTrio(x, y, z); if (newLevel < oldLevel) { removalVisited.put(node, present); - lightRemovalQueue.add(new Object[] { node, oldLevel }); + lightRemovalQueue.add(new Object[]{node, oldLevel}); } else { visited.put(node, present); lightPropagationQueue.add(node); @@ -196,7 +196,9 @@ public class NMSRelighter implements Relighter{ Map currentMap = lightQueue.get(index); if (currentMap == null) { currentMap = new Int2ObjectOpenHashMap<>(); - this.lightQueue.put(index, currentMap); + synchronized (lightQueue) { + this.lightQueue.put(index, currentMap); + } } currentMap.put((int) MathMan.tripleBlockCoord(x, y, z), present); } @@ -217,7 +219,7 @@ public class NMSRelighter implements Relighter{ updateBlockLight(this.lightQueue); } - public void sendChunks() { + public synchronized void sendChunks() { Iterator> iter = chunksToSend.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = iter.next(); @@ -234,7 +236,7 @@ public class NMSRelighter implements Relighter{ return queue.getOpacity(x, y, z) < 15; } - public void fixSkyLighting() { + public synchronized void fixSkyLighting() { // Order chunks ArrayList chunksList = new ArrayList<>(skyToRelight.size()); Iterator> iter = skyToRelight.entrySet().iterator();