forked from mirror/BlueMap
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: ",
|
||||
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!"));
|
||||
|
@ -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();
|
||||
|
@ -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<TileInfoRegion> {
|
||||
|
||||
static final int SHIFT = 5;
|
||||
public static final Grid GRID = new Grid(1 << SHIFT);
|
||||
|
||||
@Getter private int lastRenderTime = -1;
|
||||
private final Map<TileState, Integer> chunkStateCounts = new ConcurrentHashMap<>();
|
||||
|
||||
public MapTileState(GridStorage storage) {
|
||||
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) {
|
||||
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<TileState, Integer> getChunkStateCounts() {
|
||||
return Collections.unmodifiableMap(chunkStateCounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized TileInfoRegion createNewCell() {
|
||||
TileInfoRegion region = TileInfoRegion.create();
|
||||
region.populateSummaryMap(chunkStateCounts);
|
||||
return region;
|
||||
return TileInfoRegion.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<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) {
|
||||
return (z & REGION_MASK) << SHIFT | (x & REGION_MASK);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user