mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-22 10:35:16 +01:00
Remove pre-scanning the full map-state on map-initialization
It might take too long on huge maps, and its not absolutely required.
This commit is contained in:
parent
974b367128
commit
d69da892fa
@ -969,8 +969,12 @@ public int mapsCommand(CommandContext<S> context) {
|
|||||||
|
|
||||||
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0World: ",
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0World: ",
|
||||||
TextColor.DARK_GRAY, map.getWorld().getId()));
|
TextColor.DARK_GRAY, map.getWorld().getId()));
|
||||||
|
|
||||||
|
int lastRenderTime = map.getMapTileState().getLastRenderTime();
|
||||||
|
if (lastRenderTime != -1) {
|
||||||
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Last Update: ",
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Last Update: ",
|
||||||
TextColor.DARK_GRAY, helper.formatTime(map.getMapTileState().getLastRenderTime() * 1000L)));
|
TextColor.DARK_GRAY, helper.formatTime(lastRenderTime * 1000L)));
|
||||||
|
}
|
||||||
|
|
||||||
if (frozen)
|
if (frozen)
|
||||||
lines.add(Text.of(TextColor.AQUA, TextFormat.ITALIC, "\u00A0\u00A0\u00A0This map is frozen!"));
|
lines.add(Text.of(TextColor.AQUA, TextFormat.ITALIC, "\u00A0\u00A0\u00A0This map is frozen!"));
|
||||||
|
@ -95,7 +95,6 @@ public BmMap(String id, String name, World world, MapStorage storage, ResourcePa
|
|||||||
|
|
||||||
Logger.global.logDebug("Loading render-state for map '" + id + "'");
|
Logger.global.logDebug("Loading render-state for map '" + id + "'");
|
||||||
this.mapTileState = new MapTileState(storage.tileState());
|
this.mapTileState = new MapTileState(storage.tileState());
|
||||||
this.mapTileState.load();
|
|
||||||
this.mapChunkState = new MapChunkState(storage.chunkState());
|
this.mapChunkState = new MapChunkState(storage.chunkState());
|
||||||
|
|
||||||
if (Thread.interrupted()) throw new InterruptedException();
|
if (Thread.interrupted()) throw new InterruptedException();
|
||||||
|
@ -24,49 +24,21 @@
|
|||||||
*/
|
*/
|
||||||
package de.bluecolored.bluemap.core.map.renderstate;
|
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.storage.GridStorage;
|
||||||
import de.bluecolored.bluemap.core.util.Grid;
|
import de.bluecolored.bluemap.core.util.Grid;
|
||||||
import lombok.Getter;
|
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<TileInfoRegion> {
|
public class MapTileState extends CellStorage<TileInfoRegion> {
|
||||||
|
|
||||||
static final int SHIFT = 5;
|
static final int SHIFT = 5;
|
||||||
public static final Grid GRID = new Grid(1 << SHIFT);
|
public static final Grid GRID = new Grid(1 << SHIFT);
|
||||||
|
|
||||||
@Getter private int lastRenderTime = -1;
|
@Getter private int lastRenderTime = -1;
|
||||||
private final Map<TileState, Integer> chunkStateCounts = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public MapTileState(GridStorage storage) {
|
public MapTileState(GridStorage storage) {
|
||||||
super(storage, TileInfoRegion.class);
|
super(storage, TileInfoRegion.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void load() {
|
|
||||||
lastRenderTime = -1;
|
|
||||||
chunkStateCounts.clear();
|
|
||||||
|
|
||||||
try (Stream<GridStorage.Cell> 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) {
|
public TileInfoRegion.TileInfo get(int x, int z) {
|
||||||
return cell(x >> SHIFT, z >> SHIFT).get(x, 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)
|
if (info.getRenderTime() > lastRenderTime)
|
||||||
lastRenderTime = info.getRenderTime();
|
lastRenderTime = info.getRenderTime();
|
||||||
|
|
||||||
if (old.getState() != info.getState()) {
|
|
||||||
chunkStateCounts.merge(old.getState(), -1, Integer::sum);
|
|
||||||
chunkStateCounts.merge(info.getState(), 1, Integer::sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<TileState, Integer> getChunkStateCounts() {
|
|
||||||
return Collections.unmodifiableMap(chunkStateCounts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected synchronized TileInfoRegion createNewCell() {
|
protected synchronized TileInfoRegion createNewCell() {
|
||||||
TileInfoRegion region = TileInfoRegion.create();
|
return TileInfoRegion.create();
|
||||||
region.populateSummaryMap(chunkStateCounts);
|
|
||||||
return region;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static de.bluecolored.bluemap.core.map.renderstate.MapTileState.SHIFT;
|
import static de.bluecolored.bluemap.core.map.renderstate.MapTileState.SHIFT;
|
||||||
@ -102,13 +101,6 @@ int findLatestRenderTime() {
|
|||||||
.orElse(-1);
|
.orElse(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void populateSummaryMap(Map<TileState, Integer> 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) {
|
private static int index(int x, int z) {
|
||||||
return (z & REGION_MASK) << SHIFT | (x & REGION_MASK);
|
return (z & REGION_MASK) << SHIFT | (x & REGION_MASK);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user