mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Show caves as a form with area sizes, and in the 3D world
The Caves view drops its node graph. Each cave file is one form beside the scene, with a section for the cave, its tunnel, its cavern and the pillars. A section the file lacks says "(unset)" and typing a value writes it. EditableSceneView.showsNodes() lets a view ask for this. Scenes can now be built at a size the studio picks. SceneView.sizes() lists them, and scene() and parts() take a SceneRequest with the key, variant and size. Caves offer 64 to 512 blocks across. The preview sends only the carved blocks on the outside of the space, so 512 stays light. The 3D world gets a Caves toggle. It generates the chunks of a 128, 256 or 512 square around the middle of the view and draws every air block under the terrain top, coloured by height band, with a legend.
This commit is contained in:
1 parent
e862a80615
commit
263f5baa3c
28 files changed
+958
-222
No files matched your search
@@ -63,6 +63,8 @@ import com.volmit.tooling.PatternEntry;
|
||||
import com.volmit.tooling.BakeRun;
|
||||
import com.volmit.tooling.BlockParts;
|
||||
import com.volmit.tooling.SceneEntry;
|
||||
import com.volmit.tooling.SceneRequest;
|
||||
import com.volmit.tooling.SceneSizes;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -81,6 +83,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -109,6 +112,9 @@ public final class StudioBridge implements AutoCloseable {
|
||||
private static final int TOKEN_BYTES = 24;
|
||||
private static final int DEFAULT_TILE_SIZE = 128;
|
||||
private static final int LARGEST_TILE_SIZE = 512;
|
||||
private static final int DEFAULT_CAVES_SIZE = 256;
|
||||
// 1,024 chunks, generated in seconds on half the cores.
|
||||
private static final int LARGEST_CAVES_SIZE = 512;
|
||||
// A procedural object's file is a few kilobytes; this leaves room for any pack file without holding a flood.
|
||||
private static final int LARGEST_BODY_BYTES = 4 * 1024 * 1024;
|
||||
private static final double SMALLEST_BLOCKS_PER_PIXEL = 1D / 16D;
|
||||
@@ -261,6 +267,7 @@ public final class StudioBridge implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
case "tile-cancel" -> cancelTile(exchange, query);
|
||||
case "caves" -> answerAside(exchange, () -> sendBytes(exchange, "application/octet-stream", caves(get(exchange), query)));
|
||||
case "hover" -> sendJson(exchange, STATUS_OK, hover(get(exchange).engine(), query));
|
||||
case "picks" -> sendJson(exchange, STATUS_OK, picks(get(exchange).engine(), query));
|
||||
case "regions" -> sendJson(exchange, STATUS_OK, regions(get(exchange).engine()));
|
||||
@@ -374,9 +381,27 @@ public final class StudioBridge implements AutoCloseable {
|
||||
private static List<SceneViewInfo> sceneViews(Engine engine) {
|
||||
StudioEditors editors = StudioEditors.of(engine);
|
||||
StudioScenes scenes = StudioScenes.of(engine);
|
||||
return scenes.views().stream()
|
||||
.map(view -> new SceneViewInfo(view.id(), view.label(), view.description(), editors.edits(view.id()), editors.edits(view.id()) && editors.creates(view.id()), scenes.isBaked(view.id()), scenes.hasParts(view.id())))
|
||||
.toList();
|
||||
return scenes.views().stream().map(view -> {
|
||||
boolean editable = editors.edits(view.id());
|
||||
SceneSizesWire sizes = scenes.sizes(view.id()).map(SceneSizesWire::of).orElse(null);
|
||||
return new SceneViewInfo(view.id(), view.label(), view.description(), editable, editable && editors.creates(view.id()),
|
||||
editable && editors.showsNodes(view.id()), scenes.isBaked(view.id()), scenes.hasParts(view.id()), sizes);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// A view with sizes is asked at one of them, the one it opens with when the studio names none.
|
||||
private static SceneRequest sceneRequest(StudioScenes scenes, Query query) {
|
||||
String viewId = query.text("view");
|
||||
SceneRequest bare = SceneRequest.of(query.text("key"), query.whole("variant", 0));
|
||||
Optional<SceneSizes> sizes = scenes.sizes(viewId);
|
||||
if (sizes.isEmpty()) {
|
||||
return bare;
|
||||
}
|
||||
int size = query.whole("size", sizes.get().opening());
|
||||
if (!sizes.get().offers(size)) {
|
||||
throw new RequestError(STATUS_BAD_REQUEST, "View " + viewId + " builds scenes " + sizes.get().blocksAcross() + " blocks across, not " + size);
|
||||
}
|
||||
return new SceneRequest(bare.key(), bare.variant(), OptionalInt.of(size));
|
||||
}
|
||||
|
||||
private static StudioEditors.EditorState sceneFile(Engine engine, Query query) throws IOException {
|
||||
@@ -479,7 +504,8 @@ public final class StudioBridge implements AutoCloseable {
|
||||
String key = query.text("key");
|
||||
Optional<GeneratedObject> scene;
|
||||
try {
|
||||
scene = StudioScenes.of(engine).scene(query.text("view"), key, query.whole("variant", 0));
|
||||
StudioScenes scenes = StudioScenes.of(engine);
|
||||
scene = scenes.scene(query.text("view"), sceneRequest(scenes, query));
|
||||
} catch (NoSuchElementException unknown) {
|
||||
throw new RequestError(STATUS_NOT_FOUND, unknown.getMessage());
|
||||
}
|
||||
@@ -488,12 +514,12 @@ public final class StudioBridge implements AutoCloseable {
|
||||
|
||||
private static byte[] sceneParts(Engine engine, Query query) {
|
||||
String key = query.text("key");
|
||||
int variant = query.whole("variant", 0);
|
||||
try {
|
||||
StudioScenes scenes = StudioScenes.of(engine);
|
||||
GeneratedObject scene = scenes.scene(query.text("view"), key, variant)
|
||||
SceneRequest request = sceneRequest(scenes, query);
|
||||
GeneratedObject scene = scenes.scene(query.text("view"), request)
|
||||
.orElseThrow(() -> new RequestError(STATUS_NOT_FOUND, "No scene " + key));
|
||||
BlockParts parts = scenes.parts(query.text("view"), key, variant)
|
||||
BlockParts parts = scenes.parts(query.text("view"), request)
|
||||
.orElseThrow(() -> new RequestError(STATUS_NOT_FOUND, "No parts for " + key));
|
||||
return SceneEncoding.encodeParts(scene, parts);
|
||||
} catch (NoSuchElementException unknown) {
|
||||
@@ -637,6 +663,19 @@ public final class StudioBridge implements AutoCloseable {
|
||||
return MapTileEncoding.encode(tile, gson, StudioBridge::pluginLookOf);
|
||||
}
|
||||
|
||||
// Generates every chunk of the square, so a request the studio dropped is let go of as a tile is.
|
||||
private byte[] caves(StudioWorld.Session session, Query query) {
|
||||
Engine engine = session.engine();
|
||||
int size = query.whole("size", DEFAULT_CAVES_SIZE);
|
||||
if (size < 1 || size > LARGEST_CAVES_SIZE) {
|
||||
throw new RequestError(STATUS_BAD_REQUEST, "A square of caves is 1 to " + LARGEST_CAVES_SIZE + " blocks across");
|
||||
}
|
||||
AtomicBoolean dropped = query.has("request") ? droppedFlagOf(query.text("request")) : new AtomicBoolean();
|
||||
BooleanSupplier cancelled = () -> dropped.get() || closed || engine.isClosing() || engine.isClosed();
|
||||
GeneratedObject caves = session.renderer().cavesAround(query.whole("x", 0), query.whole("z", 0), size, cancelled);
|
||||
return SceneEncoding.encode(caves, gson);
|
||||
}
|
||||
|
||||
// A tile with blocks waits a minute or more on chunks generated on threads of their own; waiting on the bridge's
|
||||
// few threads, a handful of them would leave none for the studio's other requests.
|
||||
private void answerAside(HttpExchange exchange, Answer answer) {
|
||||
@@ -882,7 +921,15 @@ public final class StudioBridge implements AutoCloseable {
|
||||
}
|
||||
|
||||
/** A scene view as the studio lists it; {@code editable} when its entries can be edited as nodes, {@code creatable} when they can also be created and deleted, {@code baked} when their bake can be timed, {@code parts} when the blocks of a scene can be told by the part that placed them. */
|
||||
private record SceneViewInfo(String id, String label, String description, boolean editable, boolean creatable, boolean baked, boolean parts) {
|
||||
/** @param sizes null when the view's entries each have a size of their own */
|
||||
private record SceneViewInfo(String id, String label, String description, boolean editable, boolean creatable, boolean nodes,
|
||||
boolean baked, boolean parts, SceneSizesWire sizes) {
|
||||
}
|
||||
|
||||
private record SceneSizesWire(List<Integer> blocksAcross, int opening) {
|
||||
static SceneSizesWire of(SceneSizes sizes) {
|
||||
return new SceneSizesWire(sizes.blocksAcross(), sizes.opening());
|
||||
}
|
||||
}
|
||||
|
||||
private record UsesBody(List<String> files) {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.studio.map;
|
||||
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
/**
|
||||
* The caves of a square of generated chunks: every air block under the terrain's top, whichever stage carved it. The
|
||||
* space is drawn as blocks, as the Caves view draws one cave, and only its outside is kept, as the inside could not be
|
||||
* seen. Each block takes the colour of the band of heights it lies in, so caves stacked over each other tell apart.
|
||||
* Chunks are added from several threads at once.
|
||||
*/
|
||||
final class CaveSpace {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int CHUNK_BLOCKS = 1 << CHUNK_SHIFT;
|
||||
private static final int CHUNK_MASK = CHUNK_BLOCKS - 1;
|
||||
private static final int[][] NEIGHBOURS = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
/** The colours from high to low, a band each, the last reaching to the world's bottom; the studio's legend mirrors them. */
|
||||
private static final List<Band> BANDS = List.of(
|
||||
new Band(64, new BlockState("minecraft:yellow_concrete")),
|
||||
new Band(32, new BlockState("minecraft:orange_concrete")),
|
||||
new Band(0, new BlockState("minecraft:red_concrete")),
|
||||
new Band(-32, new BlockState("minecraft:magenta_concrete")),
|
||||
new Band(-64, new BlockState("minecraft:purple_concrete")),
|
||||
new Band(Integer.MIN_VALUE, new BlockState("minecraft:blue_concrete")));
|
||||
|
||||
private final int minChunkX;
|
||||
private final int minChunkZ;
|
||||
private final int chunksAcross;
|
||||
private final int height;
|
||||
private final int minWorldY;
|
||||
private final Map<Long, BitSet> openByChunk = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* @param height how many blocks tall the world is
|
||||
* @param minWorldY the world Y of its bottom block
|
||||
*/
|
||||
CaveSpace(int minChunkX, int minChunkZ, int chunksAcross, int height, int minWorldY) {
|
||||
this.minChunkX = minChunkX;
|
||||
this.minChunkZ = minChunkZ;
|
||||
this.chunksAcross = chunksAcross;
|
||||
this.height = height;
|
||||
this.minWorldY = minWorldY;
|
||||
}
|
||||
|
||||
/** @param terrainY the height of the terrain's top block in each column, by its x and z in the chunk */
|
||||
void add(int chunkX, int chunkZ, Hunk<PlatformBlockState> blocks, IntBinaryOperator terrainY) {
|
||||
BitSet open = new BitSet(CHUNK_BLOCKS * height * CHUNK_BLOCKS);
|
||||
for (int z = 0; z < CHUNK_BLOCKS; z++) {
|
||||
for (int x = 0; x < CHUNK_BLOCKS; x++) {
|
||||
int top = Math.min(terrainY.applyAsInt(x, z), height - 1);
|
||||
for (int y = 0; y <= top; y++) {
|
||||
PlatformBlockState block = blocks.get(x, y, z);
|
||||
if (block == null || block.isAir()) {
|
||||
open.set(cellOf(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
openByChunk.put(keyOf(chunkX, chunkZ), open);
|
||||
}
|
||||
|
||||
/** The outside of the space, its anchor at the middle of the square's bottom; chunks never added hold no caves. */
|
||||
GeneratedObject scene() {
|
||||
List<ObjectBlock> blocks = new ArrayList<>();
|
||||
int across = chunksAcross * CHUNK_BLOCKS;
|
||||
int lowest = height;
|
||||
int highest = -1;
|
||||
for (Map.Entry<Long, BitSet> chunk : openByChunk.entrySet()) {
|
||||
int chunkX = (int) (chunk.getKey() >> Integer.SIZE);
|
||||
int chunkZ = (int) (long) chunk.getKey();
|
||||
int sceneMinX = (chunkX - minChunkX) * CHUNK_BLOCKS;
|
||||
int sceneMinZ = (chunkZ - minChunkZ) * CHUNK_BLOCKS;
|
||||
BitSet open = chunk.getValue();
|
||||
for (int cell = open.nextSetBit(0); cell >= 0; cell = open.nextSetBit(cell + 1)) {
|
||||
int x = sceneMinX + (cell & CHUNK_MASK);
|
||||
int z = sceneMinZ + ((cell >> CHUNK_SHIFT) & CHUNK_MASK);
|
||||
int y = cell >> (2 * CHUNK_SHIFT);
|
||||
if (touchesRock(x, y, z)) {
|
||||
blocks.add(new ObjectBlock(new BlockPosition(x, y, z), colourAt(y + minWorldY)));
|
||||
lowest = Math.min(lowest, y);
|
||||
highest = Math.max(highest, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockBox bounds = highest < 0 ? new BlockBox(0, 0, 0, across, 1, across) : new BlockBox(0, lowest, 0, across, highest + 1, across);
|
||||
return new GeneratedObject(bounds, new BlockPosition(across / 2, bounds.minY(), across / 2), blocks, List.of());
|
||||
}
|
||||
|
||||
static BlockState colourAt(int worldY) {
|
||||
for (Band band : BANDS) {
|
||||
if (worldY >= band.lowestY()) {
|
||||
return band.colour();
|
||||
}
|
||||
}
|
||||
return BANDS.getLast().colour();
|
||||
}
|
||||
|
||||
// Beside a chunk never added, or past the square's side, counts as rock, so a cave cut off there shows its cut.
|
||||
private boolean touchesRock(int sceneX, int y, int sceneZ) {
|
||||
for (int[] step : NEIGHBOURS) {
|
||||
if (!isOpen(sceneX + step[0], y + step[1], sceneZ + step[2])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isOpen(int sceneX, int y, int sceneZ) {
|
||||
int across = chunksAcross * CHUNK_BLOCKS;
|
||||
if (sceneX < 0 || sceneZ < 0 || sceneX >= across || sceneZ >= across || y < 0 || y >= height) {
|
||||
return false;
|
||||
}
|
||||
BitSet open = openByChunk.get(keyOf(minChunkX + (sceneX >> CHUNK_SHIFT), minChunkZ + (sceneZ >> CHUNK_SHIFT)));
|
||||
return open != null && open.get(cellOf(sceneX & CHUNK_MASK, y, sceneZ & CHUNK_MASK));
|
||||
}
|
||||
|
||||
private static int cellOf(int x, int y, int z) {
|
||||
return x | z << CHUNK_SHIFT | y << (2 * CHUNK_SHIFT);
|
||||
}
|
||||
|
||||
private static long keyOf(int chunkX, int chunkZ) {
|
||||
return ((long) chunkX << Integer.SIZE) | (chunkZ & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
/** @param lowestY the world Y of the band's lowest block */
|
||||
private record Band(int lowestY, BlockState colour) {
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ByteMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ByteMaps;
|
||||
@@ -523,18 +524,45 @@ final class GeneratedChunks implements ColumnTops {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The caves of the square of chunks {@code chunksAcross} wide from chunk ({@code minChunkX}, {@code minChunkZ}),
|
||||
* each chunk generated anew, as a block scene: see {@link CaveSpace}. A chunk that fails to generate holds no caves.
|
||||
*
|
||||
* @throws CancellationException as soon as {@code cancelled} answers true
|
||||
*/
|
||||
GeneratedObject cavesIn(int minChunkX, int minChunkZ, int chunksAcross, BooleanSupplier cancelled) {
|
||||
CaveSpace space = new CaveSpace(minChunkX, minChunkZ, chunksAcross, engine.getHeight(), engine.getMinHeight());
|
||||
List<Future<?>> generating = new ArrayList<>();
|
||||
for (int chunkZ = minChunkZ; chunkZ < minChunkZ + chunksAcross; chunkZ++) {
|
||||
for (int chunkX = minChunkX; chunkX < minChunkX + chunksAcross; chunkX++) {
|
||||
int x = chunkX;
|
||||
int z = chunkZ;
|
||||
ChunkTask task = new ChunkTask(() -> {
|
||||
if (!cancelled.getAsBoolean()) {
|
||||
space.add(x, z, generateBlocksUnchecked(x, z), terrainYOf(x, z));
|
||||
}
|
||||
}, 1D);
|
||||
GENERATORS.execute(task);
|
||||
generating.add(task);
|
||||
}
|
||||
}
|
||||
try {
|
||||
for (Future<?> task : generating) {
|
||||
awaitUnlessCancelled(task, cancelled);
|
||||
}
|
||||
} catch (CancellationException stopped) {
|
||||
generating.forEach(task -> task.cancel(false));
|
||||
throw stopped;
|
||||
}
|
||||
return space.scene();
|
||||
}
|
||||
|
||||
/** @param reachedBeside the cells along the chunk's sides the open air of the chunks beside it reaches, with its light */
|
||||
private ChunkTop generate(long key, Int2ByteMap reachedBeside) throws Exception {
|
||||
int chunkX = (int) (key >> Integer.SIZE);
|
||||
int chunkZ = (int) key;
|
||||
int height = engine.getHeight();
|
||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(BLOCKS_ACROSS, height, BLOCKS_ACROSS);
|
||||
Hunk<PlatformBiome> biomes = Hunk.newArrayHunk(BLOCKS_ACROSS, height, BLOCKS_ACROSS);
|
||||
try (GenerationSessionLease lease = engine.acquireGenerationLease(LEASE_NAME);
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
engine.getGeneration().generate(chunkX << CHUNK_SHIFT, chunkZ << CHUNK_SHIFT, blocks, biomes, false, lease.sessionId());
|
||||
}
|
||||
IntBinaryOperator terrainY = (x, z) -> engine.getHeight((chunkX << CHUNK_SHIFT) + x, (chunkZ << CHUNK_SHIFT) + z, true);
|
||||
Hunk<PlatformBlockState> blocks = generateBlocks(chunkX, chunkZ);
|
||||
IntBinaryOperator terrainY = terrainYOf(chunkX, chunkZ);
|
||||
int fluidHeight = engine.getDimension().getFluidHeight();
|
||||
ChunkCells cells = ChunkCells.of(blocks, terrainY, fluidHeight, this::seenByPlayers, reachedBeside);
|
||||
ColumnRuns[] runs = new ColumnRuns[ColumnRuns.MOST_LEVEL];
|
||||
@@ -544,6 +572,30 @@ final class GeneratedChunks implements ColumnTops {
|
||||
return new ChunkTop(topsOf(blocks, terrainY, this::seenByPlayers), VisibleBlocks.of(cells, reachedBeside), runs, reachedBeside);
|
||||
}
|
||||
|
||||
// The chunk runs through the world's own stages into memory; nothing is placed in the world.
|
||||
private Hunk<PlatformBlockState> generateBlocks(int chunkX, int chunkZ) throws Exception {
|
||||
int height = engine.getHeight();
|
||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(BLOCKS_ACROSS, height, BLOCKS_ACROSS);
|
||||
Hunk<PlatformBiome> biomes = Hunk.newArrayHunk(BLOCKS_ACROSS, height, BLOCKS_ACROSS);
|
||||
try (GenerationSessionLease lease = engine.acquireGenerationLease(LEASE_NAME);
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
engine.getGeneration().generate(chunkX << CHUNK_SHIFT, chunkZ << CHUNK_SHIFT, blocks, biomes, false, lease.sessionId());
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private Hunk<PlatformBlockState> generateBlocksUnchecked(int chunkX, int chunkZ) {
|
||||
try {
|
||||
return generateBlocks(chunkX, chunkZ);
|
||||
} catch (Exception failed) {
|
||||
throw new CompletionException(failed);
|
||||
}
|
||||
}
|
||||
|
||||
private IntBinaryOperator terrainYOf(int chunkX, int chunkZ) {
|
||||
return (x, z) -> engine.getHeight((chunkX << CHUNK_SHIFT) + x, (chunkZ << CHUNK_SHIFT) + z, true);
|
||||
}
|
||||
|
||||
// A plugin's block can be solid on the server where players see grass they walk through.
|
||||
private PlatformBlockState seenByPlayers(PlatformBlockState block) {
|
||||
return seenByKey.computeIfAbsent(block.key(), key -> {
|
||||
|
||||
@@ -24,6 +24,7 @@ import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrayList;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
|
||||
|
||||
@@ -40,6 +41,7 @@ import java.util.function.BooleanSupplier;
|
||||
|
||||
/** Draws {@link MapTile}s of one engine's world. Safe to use from several threads; each tile is drawn on its caller's. */
|
||||
public final class MapTileRenderer {
|
||||
private static final int CHUNK_BLOCKS = 16;
|
||||
private final Engine engine;
|
||||
private final GeneratedChunks generated;
|
||||
|
||||
@@ -73,6 +75,23 @@ public final class MapTileRenderer {
|
||||
: renderView(layer, grid, blocksPerPixel, extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* The caves of the chunks generated in memory over a square {@code blocksAcross} wide around ({@code centerX},
|
||||
* {@code centerZ}), widened to whole chunks: every air block under the terrain's top, drawn as blocks coloured by
|
||||
* height, as {@link CaveSpace} tells.
|
||||
*
|
||||
* @throws CancellationException as soon as {@code cancelled} answers true
|
||||
*/
|
||||
public GeneratedObject cavesAround(int centerX, int centerZ, int blocksAcross, BooleanSupplier cancelled) {
|
||||
if (blocksAcross < 1) {
|
||||
throw new IllegalArgumentException("A square of caves is at least a block across");
|
||||
}
|
||||
int chunksAcross = Math.ceilDiv(blocksAcross, CHUNK_BLOCKS);
|
||||
int minChunkX = Math.floorDiv(centerX - (blocksAcross / 2), CHUNK_BLOCKS);
|
||||
int minChunkZ = Math.floorDiv(centerZ - (blocksAcross / 2), CHUNK_BLOCKS);
|
||||
return generated.cavesIn(minChunkX, minChunkZ, chunksAcross, cancelled);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code tile}, drawn from ({@code startX}, {@code startZ}), with the block on top of each of its columns from
|
||||
* {@code source}, and the solid blocks raised above it. Where the tile carries heights they become the heights of
|
||||
|
||||
@@ -119,6 +119,11 @@ public final class StudioEditors {
|
||||
return save(viewId, key, file, text);
|
||||
}
|
||||
|
||||
/** Whether the studio shows the files of {@code viewId} as nodes, rather than as one node's settings beside the scene. */
|
||||
public boolean showsNodes(String viewId) {
|
||||
return views.ask(viewId, "tell whether its files show as nodes", EditableSceneView::showsNodes);
|
||||
}
|
||||
|
||||
/** Whether entries of {@code viewId} can be created and removed from the studio. */
|
||||
public boolean creates(String viewId) {
|
||||
return views.ask(viewId, "tell whether entries are created", view -> view.creation().isPresent());
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.tooling.BakeRun;
|
||||
import com.volmit.tooling.BlockParts;
|
||||
import com.volmit.tooling.SceneEntry;
|
||||
import com.volmit.tooling.SceneRequest;
|
||||
import com.volmit.tooling.SceneSizes;
|
||||
import com.volmit.tooling.SceneView;
|
||||
|
||||
import java.util.List;
|
||||
@@ -55,8 +57,13 @@ public final class StudioScenes {
|
||||
*
|
||||
* @throws NoSuchElementException when no module registered a scene view {@code viewId}
|
||||
*/
|
||||
public Optional<GeneratedObject> scene(String viewId, String key, int variant) {
|
||||
return views.ask(viewId, "build " + key, view -> view.scene(views.world(), key, variant));
|
||||
public Optional<GeneratedObject> scene(String viewId, SceneRequest request) {
|
||||
return views.ask(viewId, "build " + request.key(), view -> view.scene(views.world(), request));
|
||||
}
|
||||
|
||||
/** @throws NoSuchElementException when no module registered a scene view {@code viewId} */
|
||||
public Optional<SceneSizes> sizes(String viewId) {
|
||||
return views.ask(viewId, "tell its sizes", SceneView::sizes);
|
||||
}
|
||||
|
||||
/** @throws NoSuchElementException when no module registered a scene view {@code viewId} */
|
||||
@@ -70,8 +77,8 @@ public final class StudioScenes {
|
||||
*
|
||||
* @throws NoSuchElementException when no module registered a scene view {@code viewId}
|
||||
*/
|
||||
public Optional<BlockParts> parts(String viewId, String key, int variant) {
|
||||
return views.ask(viewId, "find the parts of " + key, view -> view.parts(views.world(), key, variant));
|
||||
public Optional<BlockParts> parts(String viewId, SceneRequest request) {
|
||||
return views.ask(viewId, "find the parts of " + request.key(), view -> view.parts(views.world(), request));
|
||||
}
|
||||
|
||||
/** @throws NoSuchElementException when no module registered a scene view {@code viewId} */
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package art.arcane.iris.core.studio.map;
|
||||
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CaveSpaceTest {
|
||||
private static final int HEIGHT = 32;
|
||||
private static final int MIN_WORLD_Y = -16;
|
||||
private static final int TERRAIN_TOP = 20;
|
||||
private static final IntBinaryOperator FLAT_TERRAIN = (x, z) -> TERRAIN_TOP;
|
||||
private static final PlatformBlockState STONE = block("minecraft:stone", false);
|
||||
private static final PlatformBlockState AIR = block("minecraft:air", true);
|
||||
|
||||
@Test
|
||||
public void aHollowUnderTheTerrainShowsItsOutsideOnly() {
|
||||
CaveSpace space = new CaveSpace(0, 0, 1, HEIGHT, MIN_WORLD_Y);
|
||||
Hunk<PlatformBlockState> chunk = stoneUpToTerrain();
|
||||
hollow(chunk, 5, 5, 5, 3);
|
||||
|
||||
space.add(0, 0, chunk, FLAT_TERRAIN);
|
||||
Set<BlockPosition> kept = positionsOf(space.scene());
|
||||
|
||||
assertEquals("a 3 block cube without its middle", 26, kept.size());
|
||||
assertFalse(kept.contains(new BlockPosition(6, 6, 6)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theAirAboveTheTerrainIsNoCave() {
|
||||
CaveSpace space = new CaveSpace(0, 0, 1, HEIGHT, MIN_WORLD_Y);
|
||||
|
||||
space.add(0, 0, stoneUpToTerrain(), FLAT_TERRAIN);
|
||||
|
||||
assertTrue(space.scene().blocks().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCaveAcrossAChunkEdgeHasNoWallThere() {
|
||||
CaveSpace space = new CaveSpace(0, 0, 2, HEIGHT, MIN_WORLD_Y);
|
||||
Hunk<PlatformBlockState> west = stoneUpToTerrain();
|
||||
Hunk<PlatformBlockState> east = stoneUpToTerrain();
|
||||
hollow(west, 13, 5, 5, 3);
|
||||
hollow(east, 0, 5, 5, 3);
|
||||
|
||||
space.add(0, 0, west, FLAT_TERRAIN);
|
||||
space.add(1, 0, east, FLAT_TERRAIN);
|
||||
Set<BlockPosition> kept = positionsOf(space.scene());
|
||||
|
||||
assertFalse("the middle of the hollow on the west side of the edge", kept.contains(new BlockPosition(15, 6, 6)));
|
||||
assertFalse("the middle of the hollow on the east side of the edge", kept.contains(new BlockPosition(16, 6, 6)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eachBandOfHeightsHasItsColour() {
|
||||
assertEquals("minecraft:yellow_concrete", CaveSpace.colourAt(80).key());
|
||||
assertEquals("minecraft:red_concrete", CaveSpace.colourAt(0).key());
|
||||
assertEquals("minecraft:magenta_concrete", CaveSpace.colourAt(-1).key());
|
||||
assertEquals("minecraft:blue_concrete", CaveSpace.colourAt(-200).key());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSceneStandsOnItsLowestCave() {
|
||||
CaveSpace space = new CaveSpace(0, 0, 1, HEIGHT, MIN_WORLD_Y);
|
||||
Hunk<PlatformBlockState> chunk = stoneUpToTerrain();
|
||||
hollow(chunk, 5, 4, 5, 2);
|
||||
|
||||
space.add(0, 0, chunk, FLAT_TERRAIN);
|
||||
GeneratedObject scene = space.scene();
|
||||
|
||||
assertEquals(4, scene.bounds().minY());
|
||||
assertEquals(6, scene.bounds().maxY());
|
||||
for (ObjectBlock block : scene.blocks()) {
|
||||
assertEquals(CaveSpace.colourAt(block.position().y() + MIN_WORLD_Y), block.state());
|
||||
}
|
||||
}
|
||||
|
||||
private static Hunk<PlatformBlockState> stoneUpToTerrain() {
|
||||
Hunk<PlatformBlockState> chunk = Hunk.newArrayHunk(16, HEIGHT, 16);
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
chunk.set(x, y, z, y <= TERRAIN_TOP ? STONE : AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
private static void hollow(Hunk<PlatformBlockState> chunk, int minX, int minY, int minZ, int across) {
|
||||
for (int y = minY; y < minY + across; y++) {
|
||||
for (int z = minZ; z < minZ + across; z++) {
|
||||
for (int x = minX; x < Math.min(16, minX + across); x++) {
|
||||
chunk.set(x, y, z, AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<BlockPosition> positionsOf(GeneratedObject scene) {
|
||||
Set<BlockPosition> positions = new HashSet<>();
|
||||
scene.blocks().forEach(block -> positions.add(block.position()));
|
||||
return positions;
|
||||
}
|
||||
|
||||
private static PlatformBlockState block(String key, boolean air) {
|
||||
PlatformBlockState block = mock(PlatformBlockState.class);
|
||||
when(block.key()).thenReturn(key);
|
||||
when(block.isAir()).thenReturn(air);
|
||||
return block;
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,20 @@ package art.arcane.iris.modules.carve;
|
||||
|
||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.modules.carve.field.CavePart;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.tooling.BlockParts;
|
||||
import com.volmit.tooling.GraphNode;
|
||||
import com.volmit.tooling.JsonText;
|
||||
import com.volmit.tooling.NodeGraph;
|
||||
import com.volmit.tooling.SceneEntry;
|
||||
import com.volmit.tooling.SceneRequest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -28,6 +29,9 @@ public class CaveScenesTest {
|
||||
"cavern": {"size": 40, "height": 18, "coverage": 0.2, "pillars": {"spacing": 14, "thickness": 4}}}
|
||||
""";
|
||||
private static final String TUNNELS_ONLY = "{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"stretch\": 48}}";
|
||||
private static final String TUNNEL_BLOCK = "minecraft:light_blue_concrete";
|
||||
private static final String CAVERN_BLOCK = "minecraft:orange_concrete";
|
||||
private static final int[][] NEIGHBOURS = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
private final CaveScenes view = new CaveScenes();
|
||||
private final CarveTestWorld world = new CarveTestWorld()
|
||||
@@ -45,50 +49,78 @@ public class CaveScenesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSceneIsTheCarvedSpaceAndEveryBlockBelongsToAPart() {
|
||||
GeneratedObject scene = view.scene(world, "deep/mixed", 0).orElseThrow();
|
||||
BlockParts parts = view.parts(world, "deep/mixed", 0).orElseThrow();
|
||||
public void tunnelsAndCavernsShowInTheirOwnColours() {
|
||||
GeneratedObject scene = scene("deep/mixed", 0, 128);
|
||||
|
||||
assertFalse(scene.blocks().isEmpty());
|
||||
Set<Integer> partsSeen = new HashSet<>();
|
||||
Set<String> colours = new HashSet<>();
|
||||
scene.blocks().forEach(block -> colours.add(block.state().key()));
|
||||
assertEquals(Set.of(TUNNEL_BLOCK, CAVERN_BLOCK), colours);
|
||||
}
|
||||
|
||||
// The inside of the carved space could not be seen, so it is left out: every block kept touches rock or the side.
|
||||
@Test
|
||||
public void onlyTheOutsideOfTheCarvedSpaceIsKept() {
|
||||
GeneratedObject scene = scene("deep/mixed", 0, 64);
|
||||
|
||||
Set<BlockPosition> kept = new HashSet<>();
|
||||
scene.blocks().forEach(block -> kept.add(block.position()));
|
||||
for (ObjectBlock block : scene.blocks()) {
|
||||
int part = parts.partAt(block.position());
|
||||
assertNotEquals(BlockParts.NO_PART, part);
|
||||
partsSeen.add(part);
|
||||
assertTrue(block.position() + " is inside the carved space", touchesSomethingNotKept(block.position(), kept, scene));
|
||||
}
|
||||
assertEquals(Set.of(CavePart.TUNNEL.ordinal(), CavePart.CAVERN.ordinal()), partsSeen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSceneIsAsWideAsTheSizeAskedFor() {
|
||||
assertEquals(64, scene("tunnels", 0, 64).bounds().maxX());
|
||||
assertEquals(256, scene("tunnels", 0, 256).bounds().maxX());
|
||||
assertEquals(128, view.scene(world, SceneRequest.of("tunnels", 0)).orElseThrow().bounds().maxX());
|
||||
assertTrue("a size the view does not offer", view.scene(world, new SceneRequest("tunnels", 0, OptionalInt.of(100))).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eachVariantIsTheCaveSomewhereElse() {
|
||||
GeneratedObject first = view.scene(world, "tunnels", 0).orElseThrow();
|
||||
GeneratedObject first = scene("tunnels", 0, 128);
|
||||
|
||||
assertEquals(first.blocks(), view.scene(world, "tunnels", 0).orElseThrow().blocks());
|
||||
assertNotEquals(first.blocks(), view.scene(world, "tunnels", 1).orElseThrow().blocks());
|
||||
assertTrue(view.scene(world, "tunnels", CavePreview.VARIANTS).isEmpty());
|
||||
assertTrue(view.scene(world, "missing", 0).isEmpty());
|
||||
assertEquals(first.blocks(), scene("tunnels", 0, 128).blocks());
|
||||
assertNotEquals(first.blocks(), scene("tunnels", 1, 128).blocks());
|
||||
assertTrue(view.scene(world, request("tunnels", CavePreview.VARIANTS, 128)).isEmpty());
|
||||
assertTrue(view.scene(world, request("missing", 0, 128)).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCaveFileReadsAsACaveWithItsTunnelAndCavernAndPillars() {
|
||||
public void aCaveFileIsOneNodeWithASectionForEachPart() {
|
||||
NodeGraph graph = view.graph(world, "deep/mixed", JsonText.parse(MIXED));
|
||||
|
||||
assertFalse(view.showsNodes());
|
||||
GraphNode cave = graph.roots().getFirst();
|
||||
assertEquals("mixed", cave.title());
|
||||
GraphNode tunnel = cave.children().get(0).node();
|
||||
GraphNode cavern = cave.children().get(1).node();
|
||||
assertEquals("Tunnel", tunnel.title());
|
||||
assertEquals(CavePart.TUNNEL.ordinal(), tunnel.part().getAsInt());
|
||||
assertEquals(CavePart.CAVERN.ordinal(), cavern.part().getAsInt());
|
||||
assertEquals("Pillars", cavern.children().getFirst().node().title());
|
||||
assertTrue(cave.children().isEmpty());
|
||||
assertEquals(List.of("Cave", "Tunnel", "Cavern", "Pillars"), cave.settings().stream().map(GraphNode.NodeSettings::title).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anUnwrittenPartIsShownSoSettingItWritesIt() {
|
||||
public void anUnwrittenPartHasASectionSoSettingItWritesIt() {
|
||||
NodeGraph graph = view.graph(world, "tunnels", JsonText.parse(TUNNELS_ONLY));
|
||||
|
||||
GraphNode cavern = graph.roots().getFirst().children().get(1).node();
|
||||
assertEquals("Cavern (unset)", cavern.title());
|
||||
assertTrue("a cavern the cave does not have draws nothing", cavern.part().isEmpty());
|
||||
assertEquals(List.of("Cave", "Tunnel", "Cavern (unset)", "Pillars (unset)"),
|
||||
graph.roots().getFirst().settings().stream().map(GraphNode.NodeSettings::title).toList());
|
||||
}
|
||||
|
||||
private GeneratedObject scene(String key, int variant, int size) {
|
||||
return view.scene(world, request(key, variant, size)).orElseThrow();
|
||||
}
|
||||
|
||||
private static SceneRequest request(String key, int variant, int size) {
|
||||
return new SceneRequest(key, variant, OptionalInt.of(size));
|
||||
}
|
||||
|
||||
private static boolean touchesSomethingNotKept(BlockPosition position, Set<BlockPosition> kept, GeneratedObject scene) {
|
||||
for (int[] step : NEIGHBOURS) {
|
||||
BlockPosition beside = new BlockPosition(position.x() + step[0], position.y() + step[1], position.z() + step[2]);
|
||||
if (!scene.bounds().contains(beside.x(), beside.y(), beside.z()) || !kept.contains(beside)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user