From d69da892fa1602805d411d4f4647b384a91eab96 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Sat, 3 Aug 2024 09:45:09 +0200 Subject: [PATCH] Remove pre-scanning the full map-state on map-initialization It might take too long on huge maps, and its not absolutely required. --- .../common/plugin/commands/Commands.java | 8 +++- .../bluecolored/bluemap/core/map/BmMap.java | 1 - .../core/map/renderstate/MapTileState.java | 41 +------------------ .../core/map/renderstate/TileInfoRegion.java | 8 ---- 4 files changed, 7 insertions(+), 51 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java index e54122a8..ba9413df 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/Commands.java @@ -969,8 +969,12 @@ public int mapsCommand(CommandContext context) { lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0World: ", TextColor.DARK_GRAY, map.getWorld().getId())); - lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Last Update: ", - TextColor.DARK_GRAY, helper.formatTime(map.getMapTileState().getLastRenderTime() * 1000L))); + + int lastRenderTime = map.getMapTileState().getLastRenderTime(); + if (lastRenderTime != -1) { + lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Last Update: ", + TextColor.DARK_GRAY, helper.formatTime(lastRenderTime * 1000L))); + } if (frozen) lines.add(Text.of(TextColor.AQUA, TextFormat.ITALIC, "\u00A0\u00A0\u00A0This map is frozen!")); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java index 3b9120ce..fcc34a5a 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java @@ -95,7 +95,6 @@ public BmMap(String id, String name, World world, MapStorage storage, ResourcePa Logger.global.logDebug("Loading render-state for map '" + id + "'"); this.mapTileState = new MapTileState(storage.tileState()); - this.mapTileState.load(); this.mapChunkState = new MapChunkState(storage.chunkState()); if (Thread.interrupted()) throw new InterruptedException(); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/MapTileState.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/MapTileState.java index 1dbc87a3..28cbd043 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/MapTileState.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/MapTileState.java @@ -24,49 +24,21 @@ */ package de.bluecolored.bluemap.core.map.renderstate; -import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.storage.GridStorage; import de.bluecolored.bluemap.core.util.Grid; import lombok.Getter; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Stream; - public class MapTileState extends CellStorage { static final int SHIFT = 5; public static final Grid GRID = new Grid(1 << SHIFT); @Getter private int lastRenderTime = -1; - private final Map chunkStateCounts = new ConcurrentHashMap<>(); public MapTileState(GridStorage storage) { super(storage, TileInfoRegion.class); } - public synchronized void load() { - lastRenderTime = -1; - chunkStateCounts.clear(); - - try (Stream stream = getStorage().stream()) { - stream.forEach(cell -> { - TileInfoRegion region = cell(cell.getX(), cell.getZ()); - lastRenderTime = Math.max(lastRenderTime, region.findLatestRenderTime()); - region.populateSummaryMap(chunkStateCounts); - }); - } catch (IOException e) { - Logger.global.logError("Failed to load render-state regions", e); - } - } - - public synchronized void reset() { - super.reset(); - load(); - } - public TileInfoRegion.TileInfo get(int x, int z) { return cell(x >> SHIFT, z >> SHIFT).get(x, z); } @@ -77,23 +49,12 @@ public synchronized TileInfoRegion.TileInfo set(int x, int z, TileInfoRegion.Til if (info.getRenderTime() > lastRenderTime) lastRenderTime = info.getRenderTime(); - if (old.getState() != info.getState()) { - chunkStateCounts.merge(old.getState(), -1, Integer::sum); - chunkStateCounts.merge(info.getState(), 1, Integer::sum); - } - return old; } - public Map getChunkStateCounts() { - return Collections.unmodifiableMap(chunkStateCounts); - } - @Override protected synchronized TileInfoRegion createNewCell() { - TileInfoRegion region = TileInfoRegion.create(); - region.populateSummaryMap(chunkStateCounts); - return region; + return TileInfoRegion.create(); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java index 9c41178d..475da710 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/renderstate/TileInfoRegion.java @@ -37,7 +37,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import java.util.Map; import java.util.Objects; import static de.bluecolored.bluemap.core.map.renderstate.MapTileState.SHIFT; @@ -102,13 +101,6 @@ int findLatestRenderTime() { .orElse(-1); } - void populateSummaryMap(Map map) { - for (int i = 0; i < TILES_PER_REGION; i++) { - TileState tileState = tileStates[i]; - map.merge(tileState, 1, Integer::sum); - } - } - private static int index(int x, int z) { return (z & REGION_MASK) << SHIFT | (x & REGION_MASK); }