mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 19:22:08 +00:00
Add height, biome layer and load map views to the studio
- Serve the seven Swing tile views from the bridge - Colour the height view in the app from tile heights
This commit is contained in:
1 parent
8afbff4b42
commit
a8470c8178
6 files changed
+81
-16
No files matched your search
@@ -90,11 +90,26 @@ public final class StudioBridge implements AutoCloseable {
|
|||||||
static final int STATUS_SERVER_ERROR = 500;
|
static final int STATUS_SERVER_ERROR = 500;
|
||||||
static final int STATUS_UNAVAILABLE = 503;
|
static final int STATUS_UNAVAILABLE = 503;
|
||||||
|
|
||||||
|
private static final String VIEW_HEIGHT = "height";
|
||||||
|
private static final String GROUP_WORLD = "WORLD";
|
||||||
|
private static final String GROUP_BIOME_LAYERS = "BIOME_LAYERS";
|
||||||
|
private static final String GROUP_DIAGNOSTICS = "DIAGNOSTICS";
|
||||||
|
|
||||||
private static final List<ViewInfo> VIEWS = List.of(
|
private static final List<ViewInfo> VIEWS = List.of(
|
||||||
new ViewInfo(VIEW_BIOMES, "Biomes", "The biome at each spot, in the biome's colour", "WORLD", "World"),
|
new ViewInfo(VIEW_BIOMES, "Biomes", "The biome at each spot, in the biome's colour", GROUP_WORLD, "World"),
|
||||||
new ViewInfo(VIEW_REGIONS, "Regions", "The region each spot belongs to", "WORLD", "World"),
|
new ViewInfo(VIEW_REGIONS, "Regions", "The region each spot belongs to", GROUP_WORLD, "World"),
|
||||||
|
new ViewInfo(VIEW_HEIGHT, "Height", "Terrain height, from deep water to snowy peaks", GROUP_WORLD, "World"),
|
||||||
new ViewInfo(VIEW_RIVERS, "Rivers", "Streams, rivers, falls, ponds, lakes, sea inlets, grottos and cave pools from the hydrology",
|
new ViewInfo(VIEW_RIVERS, "Rivers", "Streams, rivers, falls, ponds, lakes, sea inlets, grottos and cave pools from the hydrology",
|
||||||
"WORLD", "World"));
|
GROUP_WORLD, "World"),
|
||||||
|
new ViewInfo("land-biomes", "Land biomes", "The land biome each spot would get, also where the sea is", GROUP_BIOME_LAYERS, "Biome layers"),
|
||||||
|
new ViewInfo("sea-biomes", "Sea biomes", "The sea biome each spot would get, also where the land is", GROUP_BIOME_LAYERS, "Biome layers"),
|
||||||
|
new ViewInfo("cave-biomes", "Cave biomes", "The cave biome under each spot", GROUP_BIOME_LAYERS, "Biome layers"),
|
||||||
|
new ViewInfo("object-load", "Object load", "Configuration estimate of object density and chance, not measured performance",
|
||||||
|
GROUP_DIAGNOSTICS, "Diagnostics"),
|
||||||
|
new ViewInfo("decorator-load", "Decorator load", "Configuration estimate of decorator chance and stacks, not measured performance",
|
||||||
|
GROUP_DIAGNOSTICS, "Diagnostics"),
|
||||||
|
new ViewInfo("layer-load", "Layer load", "Configuration estimate of biome layer count, not measured performance",
|
||||||
|
GROUP_DIAGNOSTICS, "Diagnostics"));
|
||||||
|
|
||||||
private final StudioWorld world;
|
private final StudioWorld world;
|
||||||
private final String token;
|
private final String token;
|
||||||
|
|||||||
@@ -74,13 +74,14 @@ final class StudioTiles {
|
|||||||
StudioTile biomesOrRegions(String view, String previewRegion, double startX, double startZ, double blocksPerPixel, int size,
|
StudioTile biomesOrRegions(String view, String previewRegion, double startX, double startZ, double blocksPerPixel, int size,
|
||||||
boolean withHeights, BooleanSupplier cancelled) {
|
boolean withHeights, BooleanSupplier cancelled) {
|
||||||
MapLayer layer = layerOf(view, previewRegion);
|
MapLayer layer = layerOf(view, previewRegion);
|
||||||
MapTileRenderer.TileRender render = renderer.prepareTile(startX, startZ, blocksPerPixel, size, layer, withHeights);
|
boolean heightsWanted = withHeights || layer.type() == TileType.HEIGHT;
|
||||||
|
MapTileRenderer.TileRender render = renderer.prepareTile(startX, startZ, blocksPerPixel, size, layer, heightsWanted);
|
||||||
MapTile tile = render.render(cancelled);
|
MapTile tile = render.render(cancelled);
|
||||||
for (int attempt = 0; !render.complete() && attempt < MAX_FINISH_ATTEMPTS; attempt++) {
|
for (int attempt = 0; !render.complete() && attempt < MAX_FINISH_ATTEMPTS; attempt++) {
|
||||||
pause(cancelled);
|
pause(cancelled);
|
||||||
tile = render.render(cancelled);
|
tile = render.render(cancelled);
|
||||||
}
|
}
|
||||||
return wire(tile, blocksPerPixel, withHeights && tile.hasHeights());
|
return wire(tile, blocksPerPixel, heightsWanted && tile.hasHeights(), layer.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
StudioTile rivers(double startX, double startZ, double blocksPerPixel, int size, BooleanSupplier cancelled) {
|
StudioTile rivers(double startX, double startZ, double blocksPerPixel, int size, BooleanSupplier cancelled) {
|
||||||
@@ -102,13 +103,20 @@ final class StudioTiles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static MapLayer layerOf(String view, String previewRegion) {
|
private static MapLayer layerOf(String view, String previewRegion) {
|
||||||
if ("regions".equals(view)) {
|
return switch (view) {
|
||||||
return previewRegion == null ? MapLayer.regions(PickDisplay.PICKS) : MapLayer.regionPreview(previewRegion, PickDisplay.PICKS);
|
case "regions" -> previewRegion == null ? MapLayer.regions(PickDisplay.PICKS) : MapLayer.regionPreview(previewRegion, PickDisplay.PICKS);
|
||||||
}
|
case "height" -> MapLayer.of(TileType.HEIGHT);
|
||||||
return MapLayer.biomes(PickDisplay.PICKS, false);
|
case "land-biomes" -> MapLayer.of(TileType.BIOME_LAND);
|
||||||
|
case "sea-biomes" -> MapLayer.of(TileType.BIOME_SEA);
|
||||||
|
case "cave-biomes" -> MapLayer.of(TileType.CAVE_LAND);
|
||||||
|
case "object-load" -> MapLayer.of(TileType.OBJECT_LOAD);
|
||||||
|
case "decorator-load" -> MapLayer.of(TileType.DECORATOR_LOAD);
|
||||||
|
case "layer-load" -> MapLayer.of(TileType.LAYER_LOAD);
|
||||||
|
default -> MapLayer.biomes(PickDisplay.PICKS, false);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private StudioTile wire(MapTile tile, double blocksPerPixel, boolean withHeights) {
|
private StudioTile wire(MapTile tile, double blocksPerPixel, boolean withHeights, TileType legendType) {
|
||||||
int size = tile.size();
|
int size = tile.size();
|
||||||
int grid = size + 2;
|
int grid = size + 2;
|
||||||
Labelling labelling = new Labelling();
|
Labelling labelling = new Labelling();
|
||||||
@@ -125,7 +133,7 @@ final class StudioTiles {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<StudioTile.Label> labels = labelling.labels(renderer);
|
List<StudioTile.Label> labels = labelling.labels(renderer, legendType);
|
||||||
return new StudioTile(size, blocksPerPixel, tile.subjectKind().name(), labels, subjects, regions, heights);
|
return new StudioTile(size, blocksPerPixel, tile.subjectKind().name(), labels, subjects, regions, heights);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +164,12 @@ final class StudioTiles {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<StudioTile.Label> labels(MapTileRenderer renderer) {
|
List<StudioTile.Label> labels(MapTileRenderer renderer, TileType legendType) {
|
||||||
List<StudioTile.Label> labels = new ArrayList<>();
|
List<StudioTile.Label> labels = new ArrayList<>();
|
||||||
for (short id : usedLabelIds) {
|
for (short id : usedLabelIds) {
|
||||||
MapLabels.Label label = renderer.labels().label(id);
|
MapLabels.Label label = renderer.labels().label(id);
|
||||||
labels.add(new StudioTile.Label(label.kind().name(), label.key(), label.name(),
|
labels.add(new StudioTile.Label(label.kind().name(), label.key(), label.name(),
|
||||||
renderer.legendColor(label, TileType.BIOME) & RGB));
|
renderer.legendColor(label, legendType) & RGB));
|
||||||
}
|
}
|
||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { BridgeClient, WorldRect } from '../bridge/BridgeClient'
|
import type { BridgeClient, WorldRect } from '../bridge/BridgeClient'
|
||||||
import { gridIndex } from '../bridge/tileDecoding'
|
import { gridIndex } from '../bridge/tileDecoding'
|
||||||
import { NO_LABEL, type BlockSource, type MapLabel, type MapTile, type Marker, type PickDisplay, type WorldInfo } from '../bridge/types'
|
import { NO_LABEL, type BlockSource, type MapLabel, type MapTile, type Marker, type PickDisplay, type WorldInfo } from '../bridge/types'
|
||||||
import { countShares, type PlacedTile, type Share } from './census'
|
import { countShares, heightBandShares, heightsInArea, type PlacedTile, type Share } from './census'
|
||||||
import { blockArt, type BlockArt } from '../scene/blockArt'
|
import { blockArt, type BlockArt } from '../scene/blockArt'
|
||||||
import { hasBlocksAt, mapTileSource, type TileLayer } from './mapTileSource'
|
import { hasBlocksAt, mapTileSource, type TileLayer } from './mapTileSource'
|
||||||
import { drawPlayerArrow } from './playerArrow'
|
import { drawPlayerArrow } from './playerArrow'
|
||||||
@@ -40,6 +40,8 @@ export interface MapListener {
|
|||||||
|
|
||||||
/** The views whose spots a noise picks, so they can draw that noise. */
|
/** The views whose spots a noise picks, so they can draw that noise. */
|
||||||
const PICK_NOISE_VIEWS = new Set(['biomes', 'regions'])
|
const PICK_NOISE_VIEWS = new Set(['biomes', 'regions'])
|
||||||
|
/** The view that colours each spot by its terrain height instead of by what picked it. */
|
||||||
|
const HEIGHT_VIEW = 'height'
|
||||||
|
|
||||||
/** What the map shows at a spot, read from the tiles already drawn. */
|
/** What the map shows at a spot, read from the tiles already drawn. */
|
||||||
export interface SpotSubjects {
|
export interface SpotSubjects {
|
||||||
@@ -235,6 +237,7 @@ export class MapController {
|
|||||||
private style(): TileStyle {
|
private style(): TileStyle {
|
||||||
return {
|
return {
|
||||||
byBlock: this.toggles.blocks,
|
byBlock: this.toggles.blocks,
|
||||||
|
byHeight: this.layer.view === HEIGHT_VIEW,
|
||||||
shading: this.toggles.shading,
|
shading: this.toggles.shading,
|
||||||
regionBorders: this.toggles.regionBorders,
|
regionBorders: this.toggles.regionBorders,
|
||||||
highlight: this.highlight,
|
highlight: this.highlight,
|
||||||
@@ -373,6 +376,9 @@ export class MapController {
|
|||||||
}
|
}
|
||||||
const screen = this.screenArea()
|
const screen = this.screenArea()
|
||||||
const area = { minimumX: screen.minX, minimumZ: screen.minZ, maximumX: screen.maxX, maximumZ: screen.maxZ }
|
const area = { minimumX: screen.minX, minimumZ: screen.minZ, maximumX: screen.maxX, maximumZ: screen.maxZ }
|
||||||
|
if (this.layer.view === HEIGHT_VIEW) {
|
||||||
|
return heightBandShares(heightsInArea(placed, area), this.world.fluidHeight)
|
||||||
|
}
|
||||||
return countShares(placed, area)
|
return countShares(placed, area)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,29 @@ export function countShares(tiles: PlacedTile[], area: WorldArea): Share[] {
|
|||||||
.sort((first, second) => second.fraction - first.fraction)
|
.sort((first, second) => second.fraction - first.fraction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The terrain heights of the pixels of {@code tiles} inside {@code area}, sampled to a bounded count. */
|
||||||
|
export function heightsInArea(tiles: PlacedTile[], area: WorldArea): number[] {
|
||||||
|
const heights: number[] = []
|
||||||
|
const totalPixels = tiles.reduce((sum, placed) => sum + placed.tile.size * placed.tile.size, 0)
|
||||||
|
const stride = Math.max(1, Math.ceil(Math.sqrt(totalPixels / MAXIMUM_COUNTED_PIXELS)))
|
||||||
|
for (const { tile, worldX, worldZ } of tiles) {
|
||||||
|
if (tile.heights === null) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const scale = tile.blocksPerPixel
|
||||||
|
const firstX = Math.max(0, Math.ceil((area.minimumX - worldX) / scale))
|
||||||
|
const endX = Math.min(tile.size, Math.ceil((area.maximumX - worldX) / scale))
|
||||||
|
const firstZ = Math.max(0, Math.ceil((area.minimumZ - worldZ) / scale))
|
||||||
|
const endZ = Math.min(tile.size, Math.ceil((area.maximumZ - worldZ) / scale))
|
||||||
|
for (let pixelZ = firstZ; pixelZ < endZ; pixelZ += stride) {
|
||||||
|
for (let pixelX = firstX; pixelX < endX; pixelX += stride) {
|
||||||
|
heights.push(tile.heights[gridIndex(tile, pixelX, pixelZ)])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return heights
|
||||||
|
}
|
||||||
|
|
||||||
/** The shares of the height bands the {@code heights} fall in, highest band first. */
|
/** The shares of the height bands the {@code heights} fall in, highest band first. */
|
||||||
export function heightBandShares(heights: readonly number[], seaLevel: number): Share[] {
|
export function heightBandShares(heights: readonly number[], seaLevel: number): Share[] {
|
||||||
const counts = new Map<number, number>()
|
const counts = new Map<number, number>()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { gridIndex } from '../bridge/tileDecoding'
|
import { gridIndex } from '../bridge/tileDecoding'
|
||||||
import { NO_BLOCK, NO_LABEL, type MapTile, type PickDisplay, type TileBlocks } from '../bridge/types'
|
import { NO_BLOCK, NO_LABEL, type MapTile, type PickDisplay, type TileBlocks } from '../bridge/types'
|
||||||
import { WATER_SURFACE_COLOR } from '../scene/waterTint'
|
import { WATER_SURFACE_COLOR } from '../scene/waterTint'
|
||||||
import { blend } from './heightColors'
|
import { blend, heightColor } from './heightColors'
|
||||||
|
|
||||||
const WATER_OVER_GROUND = 0.65
|
const WATER_OVER_GROUND = 0.65
|
||||||
|
|
||||||
@@ -15,6 +15,8 @@ export interface Highlight {
|
|||||||
export interface TileStyle {
|
export interface TileStyle {
|
||||||
/** Colour by the block on top of each column instead of by label, where the tile carries its blocks. */
|
/** Colour by the block on top of each column instead of by label, where the tile carries its blocks. */
|
||||||
byBlock: boolean
|
byBlock: boolean
|
||||||
|
/** Colour by the terrain height of each column, from the tile's heights, instead of by label. */
|
||||||
|
byHeight?: boolean
|
||||||
shading: boolean
|
shading: boolean
|
||||||
regionBorders: boolean
|
regionBorders: boolean
|
||||||
highlight: Highlight | null
|
highlight: Highlight | null
|
||||||
@@ -25,7 +27,7 @@ export interface TileStyle {
|
|||||||
|
|
||||||
export function styleKey(style: TileStyle): string {
|
export function styleKey(style: TileStyle): string {
|
||||||
const highlight = style.highlight === null ? '' : `${style.highlight.kind}:${style.highlight.key}`
|
const highlight = style.highlight === null ? '' : `${style.highlight.kind}:${style.highlight.key}`
|
||||||
return `${style.byBlock}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}|${style.pickDisplay}`
|
return `${style.byBlock}|${style.byHeight === true}|${style.shading}|${style.regionBorders}|${highlight}|${style.seaLevel}|${style.pickDisplay}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const UNKNOWN_SUBJECT = 0x5a5c62
|
const UNKNOWN_SUBJECT = 0x5a5c62
|
||||||
@@ -64,10 +66,14 @@ export function stylePixels(tile: MapTile, style: TileStyle): Uint8ClampedArray<
|
|||||||
// The bare noise is read by its brightness, which relief shading would mix up.
|
// The bare noise is read by its brightness, which relief shading would mix up.
|
||||||
const shading = style.shading && heights !== null && !(pickNoise !== null && style.pickDisplay === 'noise')
|
const shading = style.shading && heights !== null && !(pickNoise !== null && style.pickDisplay === 'noise')
|
||||||
const highlighted = highlightCells(tile, style)
|
const highlighted = highlightCells(tile, style)
|
||||||
|
const heightColored = style.byHeight === true && blocks === null && heights !== null
|
||||||
for (let pixelZ = 0; pixelZ < size; pixelZ++) {
|
for (let pixelZ = 0; pixelZ < size; pixelZ++) {
|
||||||
for (let pixelX = 0; pixelX < size; pixelX++) {
|
for (let pixelX = 0; pixelX < size; pixelX++) {
|
||||||
const cell = gridIndex(tile, pixelX, pixelZ)
|
const cell = gridIndex(tile, pixelX, pixelZ)
|
||||||
let color = blocks === null ? labelColor(colors, tile.subjects[cell]) : blockColor(blocks, cell, heights, style.seaLevel)
|
let color = blocks === null ? labelColor(colors, tile.subjects[cell]) : blockColor(blocks, cell, heights, style.seaLevel)
|
||||||
|
if (heightColored) {
|
||||||
|
color = heightColor(heights[cell], style.seaLevel)
|
||||||
|
}
|
||||||
if (pickNoise !== null) {
|
if (pickNoise !== null) {
|
||||||
color = byNoise(color, pickNoise[cell], style.pickDisplay)
|
color = byNoise(color, pickNoise[cell], style.pickDisplay)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ const VIEW_ICONS: Record<string, IdeIconName> = {
|
|||||||
biomes: 'views/biomes',
|
biomes: 'views/biomes',
|
||||||
regions: 'views/regions',
|
regions: 'views/regions',
|
||||||
rivers: 'views/rivers',
|
rivers: 'views/rivers',
|
||||||
|
height: 'shading',
|
||||||
|
'land-biomes': 'views/biomes',
|
||||||
|
'sea-biomes': 'views/biomes',
|
||||||
|
'cave-biomes': 'views/biomes',
|
||||||
|
'object-load': 'views/objects',
|
||||||
|
'decorator-load': 'decoration',
|
||||||
|
'layer-load': 'groups',
|
||||||
caveProfiles: 'views/cave-profiles',
|
caveProfiles: 'views/cave-profiles',
|
||||||
treeProfiles: 'views/tree-profiles',
|
treeProfiles: 'views/tree-profiles',
|
||||||
formationProfiles: 'views/formation-profiles',
|
formationProfiles: 'views/formation-profiles',
|
||||||
|
|||||||
Reference in new issue
Block a user