Fix region-render-tasks equality function not working correctly

This commit is contained in:
Lukas Rieger (Blue) 2024-10-17 17:58:45 +02:00
parent d9a0850cba
commit 026bd6c41b
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
6 changed files with 38 additions and 22 deletions

View File

@ -30,6 +30,7 @@
import de.bluecolored.bluemap.common.plugin.Plugin; import de.bluecolored.bluemap.common.plugin.Plugin;
import de.bluecolored.bluemap.common.rendermanager.MapPurgeTask; import de.bluecolored.bluemap.common.rendermanager.MapPurgeTask;
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask; import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
import de.bluecolored.bluemap.common.rendermanager.TileUpdateStrategy;
import java.util.Collection; import java.util.Collection;
@ -48,13 +49,13 @@ public RenderManagerImpl(BlueMapAPIImpl api, Plugin plugin) {
@Override @Override
public boolean scheduleMapUpdateTask(BlueMapMap map, boolean force) { public boolean scheduleMapUpdateTask(BlueMapMap map, boolean force) {
BlueMapMapImpl cmap = castMap(map); BlueMapMapImpl cmap = castMap(map);
return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), s -> force)); return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), TileUpdateStrategy.fixed(force)));
} }
@Override @Override
public boolean scheduleMapUpdateTask(BlueMapMap map, Collection<Vector2i> regions, boolean force) { public boolean scheduleMapUpdateTask(BlueMapMap map, Collection<Vector2i> regions, boolean force) {
BlueMapMapImpl cmap = castMap(map); 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 @Override

View File

@ -40,6 +40,7 @@
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.bluecolored.bluemap.common.config.ConfigurationException; 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.Plugin;
import de.bluecolored.bluemap.common.plugin.PluginState; import de.bluecolored.bluemap.common.plugin.PluginState;
import de.bluecolored.bluemap.common.plugin.text.Text; import de.bluecolored.bluemap.common.plugin.text.Text;
@ -48,11 +49,9 @@
import de.bluecolored.bluemap.common.rendermanager.*; import de.bluecolored.bluemap.common.rendermanager.*;
import de.bluecolored.bluemap.common.serverinterface.CommandSource; import de.bluecolored.bluemap.common.serverinterface.CommandSource;
import de.bluecolored.bluemap.core.BlueMap; 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.logger.Logger;
import de.bluecolored.bluemap.core.map.BmMap; import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.map.renderstate.TileInfoRegion; 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.MapStorage;
import de.bluecolored.bluemap.core.storage.Storage; import de.bluecolored.bluemap.core.storage.Storage;
import de.bluecolored.bluemap.core.util.Grid; import de.bluecolored.bluemap.core.util.Grid;
@ -770,18 +769,18 @@ public int unfreezeCommand(CommandContext<S> context) {
} }
public int forceUpdateCommand(CommandContext<S> context) { public int forceUpdateCommand(CommandContext<S> context) {
return updateCommand(context, s -> true); return updateCommand(context, TileUpdateStrategy.FORCE_ALL);
} }
public int fixEdgesCommand(CommandContext<S> context) { public int fixEdgesCommand(CommandContext<S> context) {
return updateCommand(context, s -> s == TileState.RENDERED_EDGE); return updateCommand(context, TileUpdateStrategy.FORCE_EDGE);
} }
public int updateCommand(CommandContext<S> context) { public int updateCommand(CommandContext<S> context) {
return updateCommand(context, s -> false); return updateCommand(context, TileUpdateStrategy.FORCE_NONE);
} }
public int updateCommand(CommandContext<S> context, Predicate<TileState> force) { public int updateCommand(CommandContext<S> context, TileUpdateStrategy force) {
final CommandSource source = commandSourceInterface.apply(context.getSource()); final CommandSource source = commandSourceInterface.apply(context.getSource());
// parse world/map argument // parse world/map argument

View File

@ -49,7 +49,7 @@ public MapUpdateTask(BmMap map) {
this(map, getRegions(map)); this(map, getRegions(map));
} }
public MapUpdateTask(BmMap map, Predicate<TileState> force) { public MapUpdateTask(BmMap map, TileUpdateStrategy force) {
this(map, getRegions(map), force); this(map, getRegions(map), force);
} }
@ -57,15 +57,15 @@ public MapUpdateTask(BmMap map, Vector2i center, int radius) {
this(map, getRegions(map, center, radius)); this(map, getRegions(map, center, radius));
} }
public MapUpdateTask(BmMap map, Vector2i center, int radius, Predicate<TileState> force) { public MapUpdateTask(BmMap map, Vector2i center, int radius, TileUpdateStrategy force) {
this(map, getRegions(map, center, radius), force); this(map, getRegions(map, center, radius), force);
} }
public MapUpdateTask(BmMap map, Collection<Vector2i> regions) { public MapUpdateTask(BmMap map, Collection<Vector2i> regions) {
this(map, regions, s -> false); this(map, regions, TileUpdateStrategy.FORCE_NONE);
} }
public MapUpdateTask(BmMap map, Collection<Vector2i> regions, Predicate<TileState> force) { public MapUpdateTask(BmMap map, Collection<Vector2i> regions, TileUpdateStrategy force) {
super("Update map '" + map.getId() + "'", createTasks(map, regions, force)); super("Update map '" + map.getId() + "'", createTasks(map, regions, force));
this.map = map; this.map = map;
this.regions = Collections.unmodifiableCollection(new ArrayList<>(regions)); this.regions = Collections.unmodifiableCollection(new ArrayList<>(regions));
@ -79,7 +79,7 @@ public Collection<Vector2i> getRegions() {
return regions; return regions;
} }
private static Collection<RenderTask> createTasks(BmMap map, Collection<Vector2i> regions, Predicate<TileState> force) { private static Collection<RenderTask> createTasks(BmMap map, Collection<Vector2i> regions, TileUpdateStrategy force) {
ArrayList<WorldRegionRenderTask> regionTasks = new ArrayList<>(regions.size()); ArrayList<WorldRegionRenderTask> regionTasks = new ArrayList<>(regions.size());
regions.forEach(region -> regionTasks.add(new WorldRegionRenderTask(map, region, force))); regions.forEach(region -> regionTasks.add(new WorldRegionRenderTask(map, region, force)));

View File

@ -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<TileState> {
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;
}
}

View File

@ -42,7 +42,6 @@
import java.io.IOException; import java.io.IOException;
import java.util.Comparator; import java.util.Comparator;
import java.util.concurrent.TimeUnit; 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.DELETE;
import static de.bluecolored.bluemap.core.map.renderstate.TileActionResolver.Action.RENDER; 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 BmMap map;
@Getter private final Vector2i regionPos; @Getter private final Vector2i regionPos;
@Getter private final Predicate<TileState> force; @Getter private final TileUpdateStrategy force;
private Grid regionGrid, chunkGrid, tileGrid; private Grid regionGrid, chunkGrid, tileGrid;
private Vector2i chunkMin, chunkMax, chunksSize; private Vector2i chunkMin, chunkMax, chunksSize;
@ -69,10 +68,10 @@ public WorldRegionRenderTask(BmMap map, Vector2i regionPos) {
} }
public WorldRegionRenderTask(BmMap map, Vector2i regionPos, boolean force) { 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<TileState> force) { public WorldRegionRenderTask(BmMap map, Vector2i regionPos, TileUpdateStrategy force) {
this.map = map; this.map = map;
this.regionPos = regionPos; this.regionPos = regionPos;
this.force = force; this.force = force;

View File

@ -38,13 +38,13 @@
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask; import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
import de.bluecolored.bluemap.common.rendermanager.RenderManager; import de.bluecolored.bluemap.common.rendermanager.RenderManager;
import de.bluecolored.bluemap.common.rendermanager.RenderTask; 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.*;
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler; import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
import de.bluecolored.bluemap.common.web.http.HttpServer; import de.bluecolored.bluemap.common.web.http.HttpServer;
import de.bluecolored.bluemap.core.BlueMap; import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.map.BmMap; 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.storage.MapStorage;
import de.bluecolored.bluemap.core.util.FileHelper; import de.bluecolored.bluemap.core.util.FileHelper;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
@ -75,7 +75,7 @@ public class BlueMapCLI {
private Path modsFolder = null; private Path modsFolder = null;
public void renderMaps(BlueMapService blueMap, boolean watch, Predicate<TileState> force, boolean forceGenerateWebapp, public void renderMaps(BlueMapService blueMap, boolean watch, TileUpdateStrategy force, boolean forceGenerateWebapp,
@Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException { @Nullable String mapsToRender) throws ConfigurationException, IOException, InterruptedException {
if (blueMap.getConfig().getWebappConfig().isEnabled()) if (blueMap.getConfig().getWebappConfig().isEnabled())
@ -371,9 +371,9 @@ public static void main(String[] args) {
noActions = false; noActions = false;
boolean watch = cmd.hasOption("u"); boolean watch = cmd.hasOption("u");
Predicate<TileState> force = t -> false; TileUpdateStrategy force = TileUpdateStrategy.FORCE_NONE;
if (cmd.hasOption("f")) force = t -> true; if (cmd.hasOption("f")) force = TileUpdateStrategy.FORCE_ALL;
else if (cmd.hasOption("e")) force = t -> t == TileState.RENDERED_EDGE; else if (cmd.hasOption("e")) force = TileUpdateStrategy.FORCE_EDGE;
boolean generateWebappFiles = cmd.hasOption("g"); boolean generateWebappFiles = cmd.hasOption("g");
String mapsToRender = cmd.getOptionValue("m", null); String mapsToRender = cmd.getOptionValue("m", null);
cli.renderMaps(blueMap, watch, force, generateWebappFiles, mapsToRender); cli.renderMaps(blueMap, watch, force, generateWebappFiles, mapsToRender);