Skip to content

Commit

Permalink
Add hidden config to disable checking for removed regions on map-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Jan 29, 2025
1 parent 9d14653 commit 526d587
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class MapConfig implements MapSettings {
private boolean enableFreeFlightView = true;
private boolean enableHires = true;

private boolean checkForRemovedRegions = true;

private String storage = "file";

private boolean ignoreMissingLightData = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,35 @@ private static Collection<Vector2i> getRegions(BmMap map, Vector2i center, int r

// also update regions that are present as map-tile-state files (they might have been rendered before but deleted now)
// (a little hacky as we are operating on raw tile-state files -> maybe find a better way?)
Grid tileGrid = map.getHiresModelManager().getTileGrid();
Grid cellGrid = MapTileState.GRID.multiply(tileGrid);
try (Stream<GridStorage.Cell> stream = map.getStorage().tileState().stream()) {
stream
.filter(c -> {
// filter out files that are fully UNKNOWN/NOT_GENERATED
// this avoids unnecessarily converting UNKNOWN tiles into NOT_GENERATED tiles on force-updates
try (CompressedInputStream in = c.read()) {
if (in == null) return false;
TileState[] states = TileInfoRegion.loadPalette(in.decompress());
for (TileState state : states) {
if (
state != TileState.UNKNOWN &&
state != TileState.NOT_GENERATED
) return true;
if (map.getMapSettings().isCheckForRemovedRegions()) {
Grid tileGrid = map.getHiresModelManager().getTileGrid();
Grid cellGrid = MapTileState.GRID.multiply(tileGrid);
try (Stream<GridStorage.Cell> stream = map.getStorage().tileState().stream()) {
stream
.filter(c -> {
// filter out files that are fully UNKNOWN/NOT_GENERATED
// this avoids unnecessarily converting UNKNOWN tiles into NOT_GENERATED tiles on force-updates
try (CompressedInputStream in = c.read()) {
if (in == null) return false;
TileState[] states = TileInfoRegion.loadPalette(in.decompress());
for (TileState state : states) {
if (
state != TileState.UNKNOWN &&
state != TileState.NOT_GENERATED
) return true;
}
return false;
} catch (IOException ignore) {
return true;
}
return false;
} catch (IOException ignore) {
return true;
}
})
.map(c -> new Vector2i(c.getX(), c.getZ()))
.flatMap(v -> cellGrid.getIntersecting(v, regionGrid).stream())
.filter(regionRadiusFilter)
.forEach(regions::add);
} catch (IOException ex) {
Logger.global.logError("Failed to load map tile state!", ex);
})
.map(c -> new Vector2i(c.getX(), c.getZ()))
.flatMap(v -> cellGrid.getIntersecting(v, regionGrid).stream())
.filter(regionRadiusFilter)
.forEach(regions::add);
} catch (IOException ex) {
Logger.global.logError("Failed to load map tile state!", ex);
}
}

return regions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public interface MapSettings extends RenderSettings {

boolean isEnableHires();

boolean isCheckForRemovedRegions();

@Override
default boolean isSaveHiresLayer() {
return isEnableHires();
Expand Down

0 comments on commit 526d587

Please sign in to comment.