Serve object and procedural views from the studio bridge

- List pack objects and baked procedural objects as scene views
- Time one bake per request for the bake meter
This commit is contained in:
piexel committed 2026-11-15 11:17:34 +01:00
1 parent dd7d838c6b
commit 3532c16906
7 files changed
+178 -7

No files matched your search

@@ -233,6 +233,7 @@ public final class StudioBridge implements AutoCloseable {
case "scenes" -> sendJson(exchange, STATUS_OK, profileViews());
case "scene-entries" -> sendJson(exchange, STATUS_OK, profileEntries(get(exchange).engine(), query));
case "scene" -> sendBytes(exchange, "application/octet-stream", profileScene(get(exchange).engine(), query));
case "scene-bake" -> sendJson(exchange, STATUS_OK, sceneBake(get(exchange).engine(), query));
case "profile-form" -> sendJson(exchange, STATUS_OK, profileForm(get(exchange).engine(), query));
case "noise-sources" -> sendJson(exchange, STATUS_OK, NoiseSources.of(get(exchange).engine()).list());
case "noise-tile" -> sendBytes(exchange, "application/octet-stream", noiseTile(get(exchange).engine(), query));
@@ -410,7 +411,7 @@ public final class StudioBridge implements AutoCloseable {
private static List<SceneViewInfo> profileViews() {
return StudioProfiles.views().stream()
.map(view -> new SceneViewInfo(view.id(), view.label(), view.description(), false, false, false, false, view.sizes(), true))
.map(view -> new SceneViewInfo(view.id(), view.label(), view.description(), false, false, view.isBaked(), false, view.sizes(), view.hasForm()))
.toList();
}
@@ -418,6 +419,14 @@ public final class StudioBridge implements AutoCloseable {
return profileView(query).entries(engine);
}
private static StudioObjects.BakeTiming sceneBake(Engine engine, Query query) {
StudioProfiles.ProfileView view = profileView(query);
if (!view.isBaked()) {
throw new RequestError(STATUS_BAD_REQUEST, "View " + view.id() + " is not baked");
}
return profiling(() -> view.timeBake(engine, query.text("key")));
}
private static ProfileForm.Form profileForm(Engine engine, Query query) {
return profiling(() -> profileView(query).form(engine, query.text("key"), query.prefixed(OVERRIDE_PREFIX)));
}
@@ -0,0 +1,146 @@
/*
* 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.studio.bridge;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.structure.object.IrisObject;
import art.arcane.iris.studio.map.BakeRun;
import art.arcane.iris.studio.map.ObjectSource;
import art.arcane.iris.studio.map.PackObjectSource;
import art.arcane.iris.studio.map.ProceduralObjectSource;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.OptionalLong;
/** The studio's views of the pack's object files and of the procedural objects its biomes and regions bake, as block scenes. */
final class StudioObjects implements StudioProfiles.ProfileView {
static final String OBJECTS = "iris:objects";
static final String PROCEDURAL = "iris:objects/procedural";
private static final String BAKE_STAGE = "Bake";
private final String id;
private final String label;
private final String description;
private final ObjectSource source;
private StudioObjects(String id, String label, String description, ObjectSource source) {
this.id = id;
this.label = label;
this.description = description;
this.source = source;
}
static StudioObjects packObjects() {
return new StudioObjects(OBJECTS, "Objects", "Every object in the pack in 3D, with the blocks it is made of", new PackObjectSource());
}
static StudioObjects proceduralObjects() {
return new StudioObjects(PROCEDURAL, "Procedural",
"Trees, rock formations and more that Iris generates from settings, every variant in 3D", new ProceduralObjectSource());
}
/** One timed bake of a procedural entry, as the studio's bake meter reads it. */
record BakeTiming(int variantCount, List<Stage> stages) {
record Stage(String label, long nanos) {
}
}
@Override
public String id() {
return id;
}
@Override
public String label() {
return label;
}
@Override
public String description() {
return description;
}
@Override
public StudioProfiles.Sizes sizes() {
return null;
}
@Override
public boolean hasForm() {
return false;
}
@Override
public boolean isBaked() {
return source.isBaked();
}
@Override
public List<StudioProfiles.Entry> entries(Engine engine) {
IrisData data = engine.getData();
return source.keys(data).stream()
.sorted(Comparator.naturalOrder())
.map(key -> new StudioProfiles.Entry(key, nameOf(key), folderOf(key), Math.max(1, source.variants(data, key).size())))
.toList();
}
@Override
public ProfileForm.Form form(Engine engine, String key, Map<String, String> overrides) {
throw new NoSuchElementException(id + " has no settings form");
}
@Override
public SceneBlocks scene(Engine engine, String key, int variant, int size, Map<String, String> overrides) {
IrisData data = engine.getData();
source.keys(data);
List<IrisObject> variants = source.variants(data, key);
if (variants.isEmpty()) {
throw new NoSuchElementException("No object " + key);
}
return StudioProfiles.sceneOf(variants.get(Math.floorMod(variant, variants.size())));
}
@Override
public BakeTiming timeBake(Engine engine, String key) {
IrisData data = engine.getData();
source.keys(data);
OptionalLong seed = source.seed(key);
if (seed.isEmpty()) {
throw new NoSuchElementException("No baked entry " + key);
}
BakeRun run = source.timeBake(data, key, seed.getAsLong());
if (run == null) {
throw new NoSuchElementException("No baked entry " + key);
}
return new BakeTiming(run.variantCount(), List.of(new BakeTiming.Stage(BAKE_STAGE, run.totalNanos())));
}
private static String nameOf(String key) {
return key.substring(key.lastIndexOf('/') + 1);
}
private static String folderOf(String key) {
int slash = key.lastIndexOf('/');
return slash < 0 ? "" : key.substring(0, slash);
}
}
@@ -56,7 +56,8 @@ final class StudioProfiles {
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 CaveView(), new TreeView(), new FormationView(), new FluidView(),
StudioObjects.packObjects(), StudioObjects.proceduralObjects());
private StudioProfiles() {
}
@@ -91,6 +92,21 @@ final class StudioProfiles {
ProfileForm.Form form(Engine engine, String key, Map<String, String> overrides);
/** Whether each entry has a settings form; the object views have none. */
default boolean hasForm() {
return true;
}
/** Whether the entries are baked from settings, so their bake can be timed. */
default boolean isBaked() {
return false;
}
/** One timed bake of the entry; only asked of baked views. */
default StudioObjects.BakeTiming timeBake(Engine engine, String key) {
throw new UnsupportedOperationException(id() + " is not baked");
}
SceneBlocks scene(Engine engine, String key, int variant, int size, Map<String, String> overrides) throws IOException;
}
@@ -113,7 +129,7 @@ final class StudioProfiles {
return new Entry(key, readable(key), "Presets", variants);
}
private static SceneBlocks sceneOf(IrisObject object) {
static SceneBlocks sceneOf(IrisObject object) {
SceneBlocks scene = new SceneBlocks();
object.getBlocks().forEach((position, state) -> scene.add(position.getBlockX(), position.getBlockY(), position.getBlockZ(), state.key()));
return scene;
@@ -21,5 +21,5 @@ package art.arcane.iris.studio.map;
/**
* How long one bake of a procedural object's variants took.
*/
record BakeRun(long totalNanos, int variantCount) {
public record BakeRun(long totalNanos, int variantCount) {
}
@@ -28,7 +28,7 @@ import java.util.OptionalLong;
* Where an object explorer gets what it shows: the pack's object files, or the objects Iris generates from settings.
* Both are called on the explorer's loader thread only.
*/
interface ObjectSource {
public interface ObjectSource {
/** What one entry is called, such as "object", for the browser's texts. */
String noun();
@@ -26,7 +26,7 @@ import java.util.List;
/**
* The pack's object files, by their load keys.
*/
final class PackObjectSource implements ObjectSource {
public final class PackObjectSource implements ObjectSource {
private static final int EMPTY_ICON_SIZE = 40;
@Override
@@ -41,7 +41,7 @@ import java.util.OptionalLong;
* The procedural objects the pack's biomes and regions bake, one entry per placement, filed under the biome or region
* that declares it.
*/
final class ProceduralObjectSource implements ObjectSource {
public final class ProceduralObjectSource implements ObjectSource {
private static final int EMPTY_ICON_SIZE = 40;
private static final String BIOME_FOLDER = "biomes";
private static final String REGION_FOLDER = "regions";