synchronize NMSRelighter map as switched to fastutil

This commit is contained in:
Jesse Boyd 2017-01-30 20:42:14 +11:00
parent 6408320843
commit 479d92b573
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F

View File

@ -45,7 +45,7 @@ public class NMSRelighter implements Relighter{
return skyToRelight.isEmpty() && lightQueue.isEmpty(); 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); long pair = MathMan.pairInt(cx, cz);
RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask); RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask);
RelightSkyEntry existing = skyToRelight.put(pair, toPut); RelightSkyEntry existing = skyToRelight.put(pair, toPut);
@ -60,7 +60,7 @@ public class NMSRelighter implements Relighter{
return true; return true;
} }
public void removeLighting() { public synchronized void removeLighting() {
Iterator<Map.Entry<Long, RelightSkyEntry>> iter = skyToRelight.entrySet().iterator(); Iterator<Map.Entry<Long, RelightSkyEntry>> iter = skyToRelight.entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Map.Entry<Long, RelightSkyEntry> entry = iter.next(); Map.Entry<Long, RelightSkyEntry> entry = iter.next();
@ -75,7 +75,7 @@ public class NMSRelighter implements Relighter{
} }
} }
public void updateBlockLight(Map<Long, Map<Integer, Object>> map) { public synchronized void updateBlockLight(Map<Long, Map<Integer, Object>> map) {
int size = map.size(); int size = map.size();
if (size == 0) { if (size == 0) {
return; return;
@ -196,8 +196,10 @@ public class NMSRelighter implements Relighter{
Map<Integer, Object> currentMap = lightQueue.get(index); Map<Integer, Object> currentMap = lightQueue.get(index);
if (currentMap == null) { if (currentMap == null) {
currentMap = new Int2ObjectOpenHashMap<>(); currentMap = new Int2ObjectOpenHashMap<>();
synchronized (lightQueue) {
this.lightQueue.put(index, currentMap); this.lightQueue.put(index, currentMap);
} }
}
currentMap.put((int) MathMan.tripleBlockCoord(x, y, z), present); currentMap.put((int) MathMan.tripleBlockCoord(x, y, z), present);
} }
@ -217,7 +219,7 @@ public class NMSRelighter implements Relighter{
updateBlockLight(this.lightQueue); updateBlockLight(this.lightQueue);
} }
public void sendChunks() { public synchronized void sendChunks() {
Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator(); Iterator<Map.Entry<Long, Integer>> iter = chunksToSend.entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Map.Entry<Long, Integer> entry = iter.next(); Map.Entry<Long, Integer> entry = iter.next();
@ -234,7 +236,7 @@ public class NMSRelighter implements Relighter{
return queue.getOpacity(x, y, z) < 15; return queue.getOpacity(x, y, z) < 15;
} }
public void fixSkyLighting() { public synchronized void fixSkyLighting() {
// Order chunks // Order chunks
ArrayList<RelightSkyEntry> chunksList = new ArrayList<>(skyToRelight.size()); ArrayList<RelightSkyEntry> chunksList = new ArrayList<>(skyToRelight.size());
Iterator<Map.Entry<Long, RelightSkyEntry>> iter = skyToRelight.entrySet().iterator(); Iterator<Map.Entry<Long, RelightSkyEntry>> iter = skyToRelight.entrySet().iterator();