From 99c4c623f8b0969d2cde0a63ab591af6fd8d98a0 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Tue, 15 Jun 2021 00:51:35 +0200 Subject: [PATCH] Tentative fix for occasional crash --- .../common/rendermanager/MapUpdateTask.java | 9 +++++- .../rendermanager/WorldRegionRenderTask.java | 31 +++++-------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java index cdc5bf25..2a040343 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java @@ -76,7 +76,14 @@ public Collection getRegions() { private static Collection createTasks(BmMap map, Collection regions, boolean force) { List tasks = new ArrayList<>(regions.size()); regions.forEach(region -> tasks.add(new WorldRegionRenderTask(map, region, force))); - tasks.sort(WorldRegionRenderTask::compare); + + // get spawn region + World world = map.getWorld(); + Vector2i spawnPoint = world.getSpawnPoint().toVector2(true); + Grid regionGrid = world.getRegionGrid(); + Vector2i spawnRegion = regionGrid.getCell(spawnPoint); + + tasks.sort(WorldRegionRenderTask.defaultComparator(spawnRegion)); return tasks; } diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java index dceaef63..8c681560 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java @@ -31,6 +31,7 @@ import de.bluecolored.bluemap.core.world.World; import java.util.Collection; +import java.util.Comparator; import java.util.TreeSet; public class WorldRegionRenderTask implements RenderTask { @@ -187,30 +188,12 @@ private static int tileComparator(Vector2i v1, Vector2i v2) { return v2.getY() - v1.getY(); } - public static int compare(WorldRegionRenderTask task1, WorldRegionRenderTask task2) { - if (task1.equals(task2)) return 0; - - int comp = task1.map.getId().compareTo(task2.map.getId()); - if (comp != 0) return comp; - - if (task1.map == task2.map) { //should always be true - //sort based on the worlds spawn-point - World world = task1.map.getWorld(); - Vector2i spawnPoint = world.getSpawnPoint().toVector2(true); - Grid regionGrid = world.getRegionGrid(); - - Vector2i spawnRegion = regionGrid.getCell(spawnPoint); - - Vector2i task1Rel = task1.worldRegion.sub(spawnRegion); - Vector2i task2Rel = task2.worldRegion.sub(spawnRegion); - - comp = tileComparator(task1Rel, task2Rel); - } else { - comp = tileComparator(task1.worldRegion, task2.worldRegion); - } - if (comp != 0) return comp; - - return -Boolean.compare(task1.force, task2.force); + public static Comparator defaultComparator(final Vector2i centerRegion) { + return (task1, task2) -> { + Vector2i task1Rel = task1.worldRegion.sub(centerRegion); + Vector2i task2Rel = task2.worldRegion.sub(centerRegion); + return tileComparator(task1Rel, task2Rel); + }; } }