From eb93b7d1abdfb6c085276e9341efff0d05e8b070 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Thu, 16 Apr 2020 15:31:33 +0200 Subject: [PATCH] Fix some issues with rendering with map-limits --- .../bluecolored/bluemap/cli/BlueMapCLI.java | 14 ++++++-- .../bluemap/common/plugin/Commands.java | 33 +++--------------- .../bluemap/common/plugin/Plugin.java | 14 ++++++-- .../bluemap/core/world/SlicedWorld.java | 34 ++++++++++++------- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/BlueMapCLI/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java b/BlueMapCLI/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java index 2f65051f..93506a45 100644 --- a/BlueMapCLI/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java +++ b/BlueMapCLI/src/main/java/de/bluecolored/bluemap/cli/BlueMapCLI.java @@ -111,9 +111,17 @@ public void renderMaps() throws IOException { Logger.global.logInfo("Preparing renderer for map '" + mapConfig.getId() + "' ..."); World world = MCAWorld.load(worldFolder.toPath(), UUID.randomUUID(), configManager.getBlockIdConfig(), configManager.getBlockPropertiesConfig(), configManager.getBiomeConfig()); - //slice world to render edges if configured - if (mapConfig.isRenderEdges() && !(mapConfig.getMin().equals(RenderSettings.DEFAULT_MIN) && mapConfig.getMax().equals(RenderSettings.DEFAULT_MAX))) { - world = new SlicedWorld(world, mapConfig.getMin(), mapConfig.getMax()); + //slice world if configured + if (!mapConfig.getMin().equals(RenderSettings.DEFAULT_MIN) || !mapConfig.getMax().equals(RenderSettings.DEFAULT_MAX)) { + if (mapConfig.isRenderEdges()) { + world = new SlicedWorld(world, mapConfig.getMin(), mapConfig.getMax()); + } else { + world = new SlicedWorld( + world, + mapConfig.getMin().min(mapConfig.getMin().sub(2, 2, 2)), // protect from int-overflow + mapConfig.getMax().max(mapConfig.getMax().add(2, 2, 2)) // protect from int-overflow + ); + } } HiresModelManager hiresModelManager = new HiresModelManager( diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Commands.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Commands.java index 988ecd14..2ff70d3c 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Commands.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Commands.java @@ -324,43 +324,19 @@ private Text createPrioritizeTaskText(RenderTask task) { } private void createWorldRenderTask(CommandSource source, World world, Vector2i center, long blockRadius) { - source.sendMessage(Text.of(TextColor.GOLD, "Collecting chunks to render...")); - - String taskName = "world-render"; - - Predicate filter; - if (center == null || blockRadius < 0) { - filter = c -> true; - } else { - filter = c -> c.mul(16).distanceSquared(center) <= blockRadius * blockRadius; - taskName = "radius-render"; - } - - Collection chunks = world.getChunkList(filter); - - source.sendMessage(Text.of(TextColor.GREEN, chunks.size() + " chunks found!")); for (MapType map : bluemap.getMapTypes()) { if (!map.getWorld().getUUID().equals(world.getUUID())) continue; - source.sendMessage(Text.of(TextColor.GOLD, "Collecting tiles for map '" + map.getId() + "'")); - - HiresModelManager hmm = map.getTileRenderer().getHiresModelManager(); - Collection tiles = hmm.getTilesForChunks(chunks); - - RenderTask task = new RenderTask(taskName, map); - task.addTiles(tiles); - task.optimizeQueue(); - bluemap.getRenderManager().addRenderTask(task); - - source.sendMessage(Text.of(TextColor.GREEN, tiles.size() + " tiles found! Task created.")); + createMapRenderTask(source, map, center, blockRadius); } source.sendMessage(Text.of(TextColor.GREEN, "All render tasks created! Use /bluemap to view the progress!")); } private void createMapRenderTask(CommandSource source, MapType map, Vector2i center, long blockRadius) { - source.sendMessage(Text.of(TextColor.GOLD, "Collecting chunks to render...")); + source.sendMessage(Text.of(TextColor.GOLD, "Creating render-task for map: " + map.getId())); + source.sendMessage(Text.of(TextColor.GOLD, "Collecting chunks...")); String taskName = "world-render"; @@ -375,7 +351,7 @@ private void createMapRenderTask(CommandSource source, MapType map, Vector2i cen Collection chunks = map.getWorld().getChunkList(filter); source.sendMessage(Text.of(TextColor.GREEN, chunks.size() + " chunks found!")); - source.sendMessage(Text.of(TextColor.GOLD, "Collecting tiles for map '" + map.getId() + "'")); + source.sendMessage(Text.of(TextColor.GOLD, "Collecting tiles...")); HiresModelManager hmm = map.getTileRenderer().getHiresModelManager(); Collection tiles = hmm.getTilesForChunks(chunks); @@ -386,7 +362,6 @@ private void createMapRenderTask(CommandSource source, MapType map, Vector2i cen bluemap.getRenderManager().addRenderTask(task); source.sendMessage(Text.of(TextColor.GREEN, tiles.size() + " tiles found! Task created.")); - source.sendMessage(Text.of(TextColor.GREEN, "All render tasks created! Use /bluemap to view the progress!")); } private boolean checkLoaded(CommandSource source) { diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java index 9d77676a..8de837c5 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java @@ -175,9 +175,17 @@ public synchronized void load() throws IOException, ParseResourceException { } } - //slice world to render edges if configured - if (mapConfig.isRenderEdges() && !(mapConfig.getMin().equals(RenderSettings.DEFAULT_MIN) && mapConfig.getMax().equals(RenderSettings.DEFAULT_MAX))) { - world = new SlicedWorld(world, mapConfig.getMin(), mapConfig.getMax()); + //slice world if configured + if (!mapConfig.getMin().equals(RenderSettings.DEFAULT_MIN) || !mapConfig.getMax().equals(RenderSettings.DEFAULT_MAX)) { + if (mapConfig.isRenderEdges()) { + world = new SlicedWorld(world, mapConfig.getMin(), mapConfig.getMax()); + } else { + world = new SlicedWorld( + world, + mapConfig.getMin().min(mapConfig.getMin().sub(2, 2, 2)), // protect from int-overflow + mapConfig.getMax().max(mapConfig.getMax().add(2, 2, 2)) // protect from int-overflow + ); + } } HiresModelManager hiresModelManager = new HiresModelManager( diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java index d0a37dfd..b9539463 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/SlicedWorld.java @@ -32,6 +32,7 @@ import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3i; +import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.util.AABB; /** @@ -47,6 +48,8 @@ public SlicedWorld(World world, Vector3i min, Vector3i max) { this.world = world; this.min = min; this.max = max; + + Logger.global.logInfo("Sliced: " + min + max); } @Override @@ -116,23 +119,29 @@ public boolean isChunkGenerated(Vector2i chunkPos) throws IOException { @Override public boolean isAreaGenerated(AABB area) throws IOException { - if (!isInside(blockPosToChunkPos(area.getMin())) && !isInside(blockPosToChunkPos(area.getMax()))) return false; - - return world.isAreaGenerated(area); + return isAreaGenerated(area.getMin(), area.getMax()); } @Override public boolean isAreaGenerated(Vector3i blockMin, Vector3i blockMax) throws IOException { - if (!isInside(blockPosToChunkPos(blockMin)) && !isInside(blockPosToChunkPos(blockMax))) return false; - - return world.isAreaGenerated(blockMin, blockMax); + return isAreaGenerated(blockPosToChunkPos(blockMin), blockPosToChunkPos(blockMax)); } @Override public boolean isAreaGenerated(Vector2i chunkMin, Vector2i chunkMax) throws IOException { - if (!isInside(chunkMin) && !isInside(chunkMax)) return false; + if (!isInside(chunkMin) && + !isInside(chunkMax) && + !isInside(new Vector2i(chunkMin.getX(), chunkMax.getY())) && + !isInside(new Vector2i(chunkMax.getX(), chunkMin.getY())) + ) return false; - return world.isAreaGenerated(chunkMin, chunkMax); + for (int x = chunkMin.getX(); x <= chunkMax.getX(); x++) { + for (int z = chunkMin.getY(); z <= chunkMax.getY(); z++) { + if (!world.isChunkGenerated(new Vector2i(x, z))) return false; + } + } + + return true; } @Override @@ -170,10 +179,11 @@ private boolean isInside(Vector2i chunkPos) { private boolean isInside(int chunkX, int chunkZ) { return - chunkX * 16 >= min.getX() && - chunkX * 16 + 15 <= max.getX() && - chunkZ * 16 >= min.getZ() && - chunkZ * 16 + 15 <= max.getZ(); + chunkX * 16 <= max.getX() && + chunkX * 16 + 15 >= min.getX() && + chunkZ * 16 <= max.getZ() && + chunkZ * 16 + 15 >= min.getZ(); + } private Block createAirBlock(Vector3i pos) {