Skip to content

Commit

Permalink
Fix village colors changing on reload local game
Browse files Browse the repository at this point in the history
  • Loading branch information
irtimaled committed Dec 30, 2017
1 parent e744fca commit 08ce096
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion java/com/irtimaled/bbor/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public void playerConnectedToServer(NetworkManager networkManager) {

public void playerDisconnectedFromServer() {
active = false;
villageProcessors.forEach(VillageProcessor::close);
villageProcessors.clear();

if (ConfigManager.keepCacheBetweenSessions.getBoolean()) return;
VillageColorCache.clear();
dimensionCache.clear();
villageProcessors.forEach(VillageProcessor::clear);
}
}
3 changes: 1 addition & 2 deletions java/com/irtimaled/bbor/common/VillageColorCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public static void clear() {
}

private static Color getNextColor() {
++colorIndex;
switch (colorIndex % 6) {
switch (++colorIndex % 6) {
case 0:
return Color.RED;
case 1:
Expand Down
15 changes: 11 additions & 4 deletions java/com/irtimaled/bbor/common/VillageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import java.util.Map;

public class VillageProcessor {
private final World world;
private final DimensionType dimensionType;
private final IVillageEventHandler eventHandler;
private World world;
private DimensionType dimensionType;
private IVillageEventHandler eventHandler;
private BoundingBoxCache boundingBoxCache;
private Map<Integer, BoundingBoxVillage> villageCache = new HashMap<>();
private boolean closed = false;

VillageProcessor(World world, DimensionType dimensionType, IVillageEventHandler eventHandler, BoundingBoxCache boundingBoxCache) {
this.world = world;
Expand All @@ -25,6 +26,8 @@ public class VillageProcessor {
}

synchronized void process() {
if (closed) return;

Map<Integer, BoundingBoxVillage> oldVillages = new HashMap<>(villageCache);
Map<Integer, BoundingBoxVillage> newVillages = new HashMap<>();
VillageCollection villageCollection = world.getVillageCollection();
Expand Down Expand Up @@ -54,7 +57,11 @@ synchronized void process() {
villageCache = newVillages;
}

public void clear() {
public void close() {
closed = true;
world = null;
eventHandler = null;
boundingBoxCache = null;
villageCache.clear();
}
}

0 comments on commit 08ce096

Please sign in to comment.