From 026bd6c41b052d8fde66b9c8e7aab9db16f7c791 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Thu, 17 Oct 2024 17:58:45 +0200 Subject: [PATCH] Fix region-render-tasks equality function not working correctly --- .../bluemap/common/api/RenderManagerImpl.java | 5 +++-- .../common/plugin/commands/Commands.java | 11 +++++------ .../common/rendermanager/MapUpdateTask.java | 10 +++++----- .../rendermanager/TileUpdateStrategy.java | 17 +++++++++++++++++ .../rendermanager/WorldRegionRenderTask.java | 7 +++---- .../de/bluecolored/bluemap/cli/BlueMapCLI.java | 10 +++++----- 6 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 common/src/main/java/de/bluecolored/bluemap/common/rendermanager/TileUpdateStrategy.java diff --git a/common/src/main/java/de/bluecolored/bluemap/common/api/RenderManagerImpl.java b/common/src/main/java/de/bluecolored/bluemap/common/api/RenderManagerImpl.java index bc104e62..ff5671b5 100644 --- a/common/src/main/java/de/bluecolored/bluemap/common/api/RenderManagerImpl.java +++ b/common/src/main/java/de/bluecolored/bluemap/common/api/RenderManagerImpl.java @@ -30,6 +30,7 @@ import de.bluecolored.bluemap.common.plugin.Plugin; import de.bluecolored.bluemap.common.rendermanager.MapPurgeTask; import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask; +import de.bluecolored.bluemap.common.rendermanager.TileUpdateStrategy; import java.util.Collection; @@ -48,13 +49,13 @@ public RenderManagerImpl(BlueMapAPIImpl api, Plugin plugin) { @Override public boolean scheduleMapUpdateTask(BlueMapMap map, boolean force) { BlueMapMapImpl cmap = castMap(map); - return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), s -> force)); + return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), TileUpdateStrategy.fixed(force))); } @Override public boolean scheduleMapUpdateTask(BlueMapMap map, Collection regions, boolean force) { BlueMapMapImpl cmap = castMap(map); - return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), regions, s -> force)); + return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), regions, TileUpdateStrategy.fixed(force))); } @Override diff --git a/common/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java b/common/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java index ba9413df..dde0796c 100644 --- a/common/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java +++ b/common/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java @@ -40,6 +40,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.tree.LiteralCommandNode; import de.bluecolored.bluemap.common.config.ConfigurationException; +import de.bluecolored.bluemap.common.debug.StateDumper; import de.bluecolored.bluemap.common.plugin.Plugin; import de.bluecolored.bluemap.common.plugin.PluginState; import de.bluecolored.bluemap.common.plugin.text.Text; @@ -48,11 +49,9 @@ import de.bluecolored.bluemap.common.rendermanager.*; import de.bluecolored.bluemap.common.serverinterface.CommandSource; import de.bluecolored.bluemap.core.BlueMap; -import de.bluecolored.bluemap.common.debug.StateDumper; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.map.BmMap; import de.bluecolored.bluemap.core.map.renderstate.TileInfoRegion; -import de.bluecolored.bluemap.core.map.renderstate.TileState; import de.bluecolored.bluemap.core.storage.MapStorage; import de.bluecolored.bluemap.core.storage.Storage; import de.bluecolored.bluemap.core.util.Grid; @@ -770,18 +769,18 @@ public int unfreezeCommand(CommandContext context) { } public int forceUpdateCommand(CommandContext context) { - return updateCommand(context, s -> true); + return updateCommand(context, TileUpdateStrategy.FORCE_ALL); } public int fixEdgesCommand(CommandContext context) { - return updateCommand(context, s -> s == TileState.RENDERED_EDGE); + return updateCommand(context, TileUpdateStrategy.FORCE_EDGE); } public int updateCommand(CommandContext context) { - return updateCommand(context, s -> false); + return updateCommand(context, TileUpdateStrategy.FORCE_NONE); } - public int updateCommand(CommandContext context, Predicate force) { + public int updateCommand(CommandContext context, TileUpdateStrategy force) { final CommandSource source = commandSourceInterface.apply(context.getSource()); // parse world/map argument diff --git a/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java b/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java index 53378e41..b425b799 100644 --- a/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java +++ b/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdateTask.java @@ -49,7 +49,7 @@ public MapUpdateTask(BmMap map) { this(map, getRegions(map)); } - public MapUpdateTask(BmMap map, Predicate force) { + public MapUpdateTask(BmMap map, TileUpdateStrategy force) { this(map, getRegions(map), force); } @@ -57,15 +57,15 @@ public MapUpdateTask(BmMap map, Vector2i center, int radius) { this(map, getRegions(map, center, radius)); } - public MapUpdateTask(BmMap map, Vector2i center, int radius, Predicate force) { + public MapUpdateTask(BmMap map, Vector2i center, int radius, TileUpdateStrategy force) { this(map, getRegions(map, center, radius), force); } public MapUpdateTask(BmMap map, Collection regions) { - this(map, regions, s -> false); + this(map, regions, TileUpdateStrategy.FORCE_NONE); } - public MapUpdateTask(BmMap map, Collection regions, Predicate force) { + public MapUpdateTask(BmMap map, Collection regions, TileUpdateStrategy force) { super("Update map '" + map.getId() + "'", createTasks(map, regions, force)); this.map = map; this.regions = Collections.unmodifiableCollection(new ArrayList<>(regions)); @@ -79,7 +79,7 @@ public Collection getRegions() { return regions; } - private static Collection createTasks(BmMap map, Collection regions, Predicate force) { + private static Collection createTasks(BmMap map, Collection regions, TileUpdateStrategy force) { ArrayList regionTasks = new ArrayList<>(regions.size()); regions.forEach(region -> regionTasks.add(new WorldRegionRenderTask(map, region, force))); diff --git a/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/TileUpdateStrategy.java b/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/TileUpdateStrategy.java new file mode 100644 index 00000000..fd604f2e --- /dev/null +++ b/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/TileUpdateStrategy.java @@ -0,0 +1,17 @@ +package de.bluecolored.bluemap.common.rendermanager; + +import de.bluecolored.bluemap.core.map.renderstate.TileState; + +import java.util.function.Predicate; + +public interface TileUpdateStrategy extends Predicate { + + TileUpdateStrategy FORCE_ALL = tileState -> true; + TileUpdateStrategy FORCE_EDGE = tileState -> tileState == TileState.RENDERED_EDGE; + TileUpdateStrategy FORCE_NONE = tileState -> false; + + static TileUpdateStrategy fixed(boolean force) { + return force ? FORCE_ALL : FORCE_NONE; + } + +} diff --git a/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java b/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java index ab728050..3f10fca0 100644 --- a/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java +++ b/common/src/main/java/de/bluecolored/bluemap/common/rendermanager/WorldRegionRenderTask.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.util.Comparator; import java.util.concurrent.TimeUnit; -import java.util.function.Predicate; import static de.bluecolored.bluemap.core.map.renderstate.TileActionResolver.Action.DELETE; import static de.bluecolored.bluemap.core.map.renderstate.TileActionResolver.Action.RENDER; @@ -51,7 +50,7 @@ public class WorldRegionRenderTask implements RenderTask { @Getter private final BmMap map; @Getter private final Vector2i regionPos; - @Getter private final Predicate force; + @Getter private final TileUpdateStrategy force; private Grid regionGrid, chunkGrid, tileGrid; private Vector2i chunkMin, chunkMax, chunksSize; @@ -69,10 +68,10 @@ public WorldRegionRenderTask(BmMap map, Vector2i regionPos) { } public WorldRegionRenderTask(BmMap map, Vector2i regionPos, boolean force) { - this(map, regionPos, s -> force); + this(map, regionPos, TileUpdateStrategy.fixed(force)); } - public WorldRegionRenderTask(BmMap map, Vector2i regionPos, Predicate force) { + public WorldRegionRenderTask(BmMap map, Vector2i regionPos, TileUpdateStrategy force) { this.map = map; this.regionPos = regionPos; this.force = force; 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 370fd22a..afa198ba 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 @@ -38,13 +38,13 @@ import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask; import de.bluecolored.bluemap.common.rendermanager.RenderManager; import de.bluecolored.bluemap.common.rendermanager.RenderTask; +import de.bluecolored.bluemap.common.rendermanager.TileUpdateStrategy; import de.bluecolored.bluemap.common.web.*; import de.bluecolored.bluemap.common.web.http.HttpRequestHandler; import de.bluecolored.bluemap.common.web.http.HttpServer; import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.map.BmMap; -import de.bluecolored.bluemap.core.map.renderstate.TileState; import de.bluecolored.bluemap.core.storage.MapStorage; import de.bluecolored.bluemap.core.util.FileHelper; import org.apache.commons.cli.*; @@ -75,7 +75,7 @@ public class BlueMapCLI { private Path modsFolder = null; - public void renderMaps(BlueMapService blueMap, boolean watch, Predicate force, boolean forceGenerateWebapp, + public void renderMaps(BlueMapService blueMap, boolean watch, TileUpdateStrategy force, boolean forceGenerateWebapp, @Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException { if (blueMap.getConfig().getWebappConfig().isEnabled()) @@ -371,9 +371,9 @@ public static void main(String[] args) { noActions = false; boolean watch = cmd.hasOption("u"); - Predicate force = t -> false; - if (cmd.hasOption("f")) force = t -> true; - else if (cmd.hasOption("e")) force = t -> t == TileState.RENDERED_EDGE; + TileUpdateStrategy force = TileUpdateStrategy.FORCE_NONE; + if (cmd.hasOption("f")) force = TileUpdateStrategy.FORCE_ALL; + else if (cmd.hasOption("e")) force = TileUpdateStrategy.FORCE_EDGE; boolean generateWebappFiles = cmd.hasOption("g"); String mapsToRender = cmd.getOptionValue("m", null); cli.renderMaps(blueMap, watch, force, generateWebappFiles, mapsToRender);