mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Drop the studio cave view and use weighted entries in cave tests
- Remove the cave profile view and its preview, whose config listed caves removed - Build test regions and biomes from weighted entries - Retake the pack schema digest
This commit is contained in:
1 parent
1f27af6938
commit
424d8d8f51
5 files changed
+7
-241
No files matched your search
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 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.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisEngineMantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Carves one cave profile with the engine's own carver over a square of flat ground, in a mantle of its own so the
|
||||
* world's is left alone, and says which blocks it opened.
|
||||
*/
|
||||
public final class CaveProfilePreview {
|
||||
private static final int CHUNK_BLOCKS = 16;
|
||||
private static final int CHUNK_COLUMNS = CHUNK_BLOCKS * CHUNK_BLOCKS;
|
||||
private static final int PREFETCH_CHUNKS = 0;
|
||||
private static final int ACCESS_CHUNKS = 1;
|
||||
|
||||
private CaveProfilePreview() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The carved space of a square, {@code size} blocks across and a whole number of chunks, from {@code bottomY} up to
|
||||
* and including {@code surfaceY}, both in engine-local Y (0 is the bottom of the dimension).
|
||||
*
|
||||
* @return one flag per block, {@code (y - bottomY) * size² + z * size + x}
|
||||
*/
|
||||
public static boolean[] carve(Engine engine, IrisCaveProfile profile, int originX, int size, int bottomY, int surfaceY)
|
||||
throws IOException {
|
||||
int height = surfaceY - bottomY + 1;
|
||||
boolean[] carved = new boolean[height * size * size];
|
||||
Path folder = Files.createTempDirectory("iris-cave-preview");
|
||||
Mantle<Matter> mantle = IrisEngineMantle.createMantle(engine, folder, engine::getData);
|
||||
try {
|
||||
IrisCaveCarver3D carver = new IrisCaveCarver3D(engine, profile);
|
||||
int[] surface = new int[CHUNK_COLUMNS];
|
||||
Arrays.fill(surface, surfaceY);
|
||||
double[] weights = new double[CHUNK_COLUMNS];
|
||||
Arrays.fill(weights, 1D);
|
||||
int firstChunkX = Math.floorDiv(originX, CHUNK_BLOCKS);
|
||||
int chunks = size / CHUNK_BLOCKS;
|
||||
for (int chunkZ = 0; chunkZ < chunks; chunkZ++) {
|
||||
for (int chunkX = 0; chunkX < chunks; chunkX++) {
|
||||
int worldChunkX = firstChunkX + chunkX;
|
||||
try (MantleWriter writer = new MantleWriter(engine.getMantle(), mantle, worldChunkX, chunkZ, PREFETCH_CHUNKS, ACCESS_CHUNKS, false)) {
|
||||
carver.carve(writer, worldChunkX, chunkZ, weights, 0D, 0D, null, surface);
|
||||
}
|
||||
readCarved(mantle, carved, worldChunkX, chunkZ, chunkX, chunkZ, size, bottomY, surfaceY);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
mantle.close();
|
||||
deleteQuietly(folder);
|
||||
}
|
||||
return carved;
|
||||
}
|
||||
|
||||
private static void readCarved(Mantle<Matter> mantle, boolean[] carved, int worldChunkX, int worldChunkZ, int chunkX, int chunkZ,
|
||||
int size, int bottomY, int surfaceY) {
|
||||
for (int y = bottomY; y <= surfaceY; y++) {
|
||||
for (int z = 0; z < CHUNK_BLOCKS; z++) {
|
||||
for (int x = 0; x < CHUNK_BLOCKS; x++) {
|
||||
MatterCavern cavern = mantle.get(worldChunkX * CHUNK_BLOCKS + x, y, worldChunkZ * CHUNK_BLOCKS + z, MatterCavern.class);
|
||||
if (cavern == null) {
|
||||
continue;
|
||||
}
|
||||
int cell = (y - bottomY) * size * size + (chunkZ * CHUNK_BLOCKS + z) * size + chunkX * CHUNK_BLOCKS + x;
|
||||
carved[cell] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteQuietly(Path folder) {
|
||||
try (Stream<Path> paths = Files.walk(folder)) {
|
||||
paths.sorted(Comparator.reverseOrder()).forEach(path -> path.toFile().delete());
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,17 +18,12 @@
|
||||
|
||||
package art.arcane.iris.studio.bridge;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormation;
|
||||
import art.arcane.iris.generation.decoration.formation.IrisFormationProfile;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisProceduralTree;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisTreeProfile;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
|
||||
import art.arcane.iris.generation.mantle.CaveProfilePreview;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -46,17 +41,16 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The views of the config profiles Iris v4 has: cave profiles, tree profiles, formation profiles and fluid profiles.
|
||||
* The views of the config profiles Iris v4 has: tree profiles, formation profiles and fluid profiles.
|
||||
* Each lists what the pack has of its kind, shows its settings as a form and draws it as blocks, so the studio's scene
|
||||
* viewer can show them. Values typed into a form only change the preview.
|
||||
*/
|
||||
final class StudioProfiles {
|
||||
static final String CAVES = "caveProfiles";
|
||||
static final String TREES = "treeProfiles";
|
||||
static final String FORMATIONS = "formationProfiles";
|
||||
static final String FLUIDS = "fluidProfiles";
|
||||
|
||||
private static final List<ProfileView> VIEWS = List.of(new CaveView(), new TreeView(), new FormationView(), new FluidView(),
|
||||
private static final List<ProfileView> VIEWS = List.of(new TreeView(), new FormationView(), new FluidView(),
|
||||
StudioObjects.packObjects(), StudioObjects.proceduralObjects());
|
||||
|
||||
private StudioProfiles() {
|
||||
@@ -142,129 +136,6 @@ final class StudioProfiles {
|
||||
return variants.get(Math.floorMod(variant, variants.size()));
|
||||
}
|
||||
|
||||
// Caves ------------------------------------------------------------------------------------------------------
|
||||
|
||||
private static final class CaveView implements ProfileView {
|
||||
private static final Sizes SIZES = new Sizes(List.of(64, 128, 256), 128);
|
||||
private static final int VARIANTS = 4;
|
||||
private static final int VARIANT_SPACING_BLOCKS = 4096;
|
||||
private static final int SURFACE_ABOVE_SEA_BLOCKS = 48;
|
||||
private static final int MAX_DEPTH_BLOCKS = 160;
|
||||
private static final String DIMENSION_KEY = "dimension";
|
||||
private static final String REGION_PREFIX = "region/";
|
||||
private static final String BIOME_PREFIX = "biome/";
|
||||
private static final String[] DEPTH_BANDS = {"minecraft:yellow_concrete", "minecraft:lime_concrete", "minecraft:light_blue_concrete",
|
||||
"minecraft:purple_concrete"};
|
||||
private static final int[][] NEIGHBOURS = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return CAVES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Cave profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "The carved space of each enabled cave profile of the dimension, its regions and its biomes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sizes sizes() {
|
||||
return SIZES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entry> entries(Engine engine) {
|
||||
IrisData data = engine.getData();
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
if (dimension.getCaveProfile().isEnabled()) {
|
||||
entries.add(new Entry(DIMENSION_KEY, dimension.getName(), "Dimension", VARIANTS));
|
||||
}
|
||||
for (IrisRegion region : data.getRegionLoader().loadAll(data.getRegionLoader().getPossibleKeys())) {
|
||||
if (region != null && region.getCaveProfile().isEnabled()) {
|
||||
entries.add(new Entry(REGION_PREFIX + region.getLoadKey(), region.getName(), "Regions", VARIANTS));
|
||||
}
|
||||
}
|
||||
for (IrisBiome biome : data.getBiomeLoader().loadAll(data.getBiomeLoader().getPossibleKeys())) {
|
||||
if (biome != null && biome.getCaveProfile().isEnabled()) {
|
||||
entries.add(new Entry(BIOME_PREFIX + biome.getLoadKey(), biome.getName(), "Biomes", VARIANTS));
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileForm.Form form(Engine engine, String key, Map<String, String> overrides) {
|
||||
IrisCaveProfile profile = ProfileForm.withOverrides(profileOf(engine, key), overrides);
|
||||
return ProfileForm.of("Cave profile", profile, Set.of(), overrides, List.of("Values typed here change the preview only"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneBlocks scene(Engine engine, String key, int variant, int size, Map<String, String> overrides) throws IOException {
|
||||
IrisCaveProfile profile = ProfileForm.withOverrides(profileOf(engine, key), overrides);
|
||||
int surfaceY = Math.min(engine.getHeight() - 1, engine.getDimension().getFluidHeight() + SURFACE_ABOVE_SEA_BLOCKS);
|
||||
int bottomY = Math.max(0, Math.max((int) Math.floor(profile.getVerticalRange().getMin()), surfaceY - MAX_DEPTH_BLOCKS));
|
||||
boolean[] carved = CaveProfilePreview.carve(engine, profile, Math.floorMod(variant, VARIANTS) * VARIANT_SPACING_BLOCKS, size, bottomY, surfaceY);
|
||||
return outsideOf(carved, size, surfaceY - bottomY + 1);
|
||||
}
|
||||
|
||||
private static IrisCaveProfile profileOf(Engine engine, String key) {
|
||||
IrisData data = engine.getData();
|
||||
IrisCaveProfile profile = null;
|
||||
if (DIMENSION_KEY.equals(key)) {
|
||||
profile = engine.getDimension().getCaveProfile();
|
||||
} else if (key.startsWith(REGION_PREFIX)) {
|
||||
IrisRegion region = data.getRegionLoader().load(key.substring(REGION_PREFIX.length()));
|
||||
profile = region == null ? null : region.getCaveProfile();
|
||||
} else if (key.startsWith(BIOME_PREFIX)) {
|
||||
IrisBiome biome = data.getBiomeLoader().load(key.substring(BIOME_PREFIX.length()));
|
||||
profile = biome == null ? null : biome.getCaveProfile();
|
||||
}
|
||||
if (profile == null) {
|
||||
throw new NoSuchElementException("No cave profile " + key);
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
// Only the carved blocks on the outside of the space are kept, as the inside could not be seen.
|
||||
private static SceneBlocks outsideOf(boolean[] carved, int size, int height) {
|
||||
SceneBlocks scene = new SceneBlocks();
|
||||
for (int y = 0; y < height; y++) {
|
||||
String band = DEPTH_BANDS[Math.min(DEPTH_BANDS.length - 1, (height - 1 - y) * DEPTH_BANDS.length / height)];
|
||||
for (int z = 0; z < size; z++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
if (carved[cellOf(x, y, z, size)] && touchesRock(carved, x, y, z, size, height)) {
|
||||
scene.add(x, y, z, band);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return scene;
|
||||
}
|
||||
|
||||
private static boolean touchesRock(boolean[] carved, int x, int y, int z, int size, int height) {
|
||||
for (int[] step : NEIGHBOURS) {
|
||||
int nx = x + step[0];
|
||||
int ny = y + step[1];
|
||||
int nz = z + step[2];
|
||||
boolean inside = nx >= 0 && ny >= 0 && nz >= 0 && nx < size && ny < height && nz < size;
|
||||
if (!inside || !carved[cellOf(nx, ny, nz, size)]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int cellOf(int x, int y, int z, int size) {
|
||||
return (y * size + z) * size + x;
|
||||
}
|
||||
}
|
||||
|
||||
// Trees ------------------------------------------------------------------------------------------------------
|
||||
|
||||
private static final class TreeView implements ProfileView {
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import art.arcane.iris.generation.stream.BakedDoubleStream;
|
||||
import art.arcane.iris.generation.stream.BakedStream;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.generation.terrain.IrisRegionEntry;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.testsupport.FakeHydrology;
|
||||
@@ -136,7 +137,7 @@ public class MantleCarvingComponentBakedFieldTest {
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
MantleCarvingComponent component = new MantleCarvingComponent(engineMantle);
|
||||
IrisDimension dimension = new IrisDimension().setCaves(new KList<>("dimension-cave")).setRegions(new KList<>("region"));
|
||||
IrisDimension dimension = new IrisDimension().setCaves(new KList<>("dimension-cave")).setRegions(IrisRegionEntry.plainList("region"));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getWorld()).thenReturn(IrisWorld.builder().minHeight(0).maxHeight(WORLD_HEIGHT).build());
|
||||
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ public class IrisDimensionReachableBiomesTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void includesTheBiomesOfCavesTheDimensionTheRegionsAndTheReachableBiomesList() {
|
||||
IrisDimension dimension = new IrisDimension().setRegions(new KList<>("reachable")).setCaves(new KList<>("dimension-cave"));
|
||||
IrisRegion reachable = new IrisRegion().setLandBiomes(new KList<>("land")).setCaves(new KList<>("region-cave"));
|
||||
IrisDimension dimension = new IrisDimension().setRegions(IrisRegionEntry.plainList("reachable")).setCaves(new KList<>("dimension-cave"));
|
||||
IrisRegion reachable = new IrisRegion().setLandBiomes(IrisBiomeEntry.plainList("land")).setCaves(new KList<>("region-cave"));
|
||||
IrisBiome land = biome("land").setCaves(new KList<>("biome-cave", "plain-cave", "ghost"));
|
||||
IrisBiome unlisted = biome("unlisted-cave-biome");
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "47f81b4efc4e3f3784aca3fdc2e5960ecdcdd459778653d44e04125280fd29e2";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "c239643581ab715407f9684d4d8f6fb626c132c64742026f14bbf74fe2cf5b18";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
Reference in new issue
Block a user