From 67f1e03f00a9eac44e4c46b548aa58bcdf8357df Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Fri, 18 Sep 2020 11:37:08 +0200 Subject: [PATCH] Do render-sorting based on the spawnpoint or radius-render center --- .../main/java/de/bluecolored/bluemap/common/RenderTask.java | 5 ++++- .../bluemap/common/plugin/commands/CommandHelper.java | 4 +++- .../src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/RenderTask.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/RenderTask.java index 45fb36f5..f4610456 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/RenderTask.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/RenderTask.java @@ -59,13 +59,16 @@ public RenderTask(String name, MapType mapType) { this.renderedTiles = 0; } - public void optimizeQueue() { + public void optimizeQueue(Vector2i center) { //Find a good grid size to match the MCAWorlds chunk-cache size of 500 Vector2d sortGridSize = new Vector2d(20, 20).div(mapType.getTileRenderer().getHiresModelManager().getTileSize().toDouble().div(16)).ceil().max(1, 1); synchronized (renderTiles) { ArrayList tileList = new ArrayList<>(renderTiles); tileList.sort((v1, v2) -> { + v1 = v1.sub(center); + v2 = v2.sub(center); + Vector2i v1SortGridPos = v1.toDouble().div(sortGridSize).floor().toInt(); Vector2i v2SortGridPos = v2.toDouble().div(sortGridSize).floor().toInt(); diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/CommandHelper.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/CommandHelper.java index f69c62b9..64484053 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/CommandHelper.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/CommandHelper.java @@ -123,6 +123,7 @@ public void createMapRenderTask(CommandSource source, MapType map, Vector2i cent source.sendMessage(Text.of(TextColor.GOLD, "Collecting chunks...")); String taskName = "world-render"; + Vector2i renderCenter = map.getWorld().getSpawnPoint().toVector2(true); Predicate filter; if (center == null || blockRadius < 0) { @@ -130,6 +131,7 @@ public void createMapRenderTask(CommandSource source, MapType map, Vector2i cent } else { filter = c -> c.mul(16).distanceSquared(center) <= blockRadius * blockRadius; taskName = "radius-render"; + renderCenter = center; } Collection chunks = map.getWorld().getChunkList(filter); @@ -142,7 +144,7 @@ public void createMapRenderTask(CommandSource source, MapType map, Vector2i cent RenderTask task = new RenderTask(taskName, map); task.addTiles(tiles); - task.optimizeQueue(); + task.optimizeQueue(renderCenter); plugin.getRenderManager().addRenderTask(task); source.sendMessage(Text.of(TextColor.GREEN, tiles.size() + " tiles found! Task created.")); diff --git a/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java b/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java index 07024542..d62864aa 100644 --- a/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java +++ b/implementations/cli/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java @@ -112,10 +112,12 @@ public void renderMaps(BlueMapService blueMap, boolean forceRender, boolean forc if (tiles.isEmpty()) { continue; } + + Vector2i renderCenter = map.getWorld().getSpawnPoint().toVector2(true); RenderTask task = new RenderTask(map.getId(), map); task.addTiles(tiles); - task.optimizeQueue(); + task.optimizeQueue(renderCenter); renderManager.addRenderTask(task); }