diff --git a/core/src/main/java/art/arcane/iris/studio/map/BakeMeter.java b/core/src/main/java/art/arcane/iris/studio/map/BakeMeter.java deleted file mode 100644 index 9e6c53c01..000000000 --- a/core/src/main/java/art/arcane/iris/studio/map/BakeMeter.java +++ /dev/null @@ -1,154 +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 . - */ - -package art.arcane.iris.studio.map; - -import com.formdev.flatlaf.extras.FlatSVGIcon; - -import javax.swing.JComponent; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; - -/** - * IntelliJ's profiler gauge, how heavy the measured bake is, a meter and the time it took, all in the weight's colour. - */ -final class BakeMeter extends JComponent { - private static final long serialVersionUID = 4120925066373218716L; - private static final String PROFILER_ICON = "iris/icons/profiler.svg"; - private static final String TIMING_LABEL = "Timing"; - private static final String WIDEST_TIME = "999 ms"; - private static final int ICON_SIZE = 16; - private static final int GAP = 6; - private static final int BAR_HEIGHT = 4; - private static final int HEIGHT = 20; - - private final FlatSVGIcon icon = new FlatSVGIcon(PROFILER_ICON, ICON_SIZE, ICON_SIZE, BakeMeter.class.getClassLoader()); - private BakeTiming timing; - private boolean timingUnderWay; - - BakeMeter() { - icon.setColorFilter(new FlatSVGIcon.ColorFilter(drawn -> color())); - } - - void showTiming() { - timing = null; - timingUnderWay = true; - setToolTipText("Baking every variant five times over"); - repaint(); - } - - void show(BakeTiming measured) { - timing = measured; - timingUnderWay = false; - setToolTipText(measured.explain()); - repaint(); - } - - void clear() { - timing = null; - timingUnderWay = false; - setToolTipText(null); - repaint(); - } - - @Override - public Dimension getPreferredSize() { - return new Dimension(0, StudioTheme.scale(HEIGHT)); - } - - @Override - protected void paintComponent(Graphics graphics) { - Graphics2D canvas = (Graphics2D) graphics.create(); - try { - canvas.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - canvas.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - icon.paintIcon(this, canvas, 0, (getHeight() - icon.getIconHeight()) / 2); - int labelX = icon.getIconWidth() + StudioTheme.scale(GAP); - int barX = drawLabel(canvas, labelX) + StudioTheme.scale(GAP); - int timeX = getWidth() - timeWidth(canvas); - drawBar(canvas, barX, timeX - StudioTheme.scale(GAP) - barX); - drawTime(canvas, timeX); - } finally { - canvas.dispose(); - } - } - - private Color color() { - return timing == null ? StudioTheme.MUTED_TEXT : weight().color(); - } - - private BakeWeight weight() { - return BakeWeight.of(timing.totalMillis()); - } - - // Returns where the label ends. - private int drawLabel(Graphics2D canvas, int x) { - canvas.setFont(StudioTheme.boldFont()); - FontMetrics metrics = canvas.getFontMetrics(); - canvas.setColor(color()); - canvas.drawString(labelText(), x, baseline(metrics)); - int widestLabelWidth = metrics.stringWidth(TIMING_LABEL); - for (BakeWeight each : BakeWeight.values()) { - widestLabelWidth = Math.max(widestLabelWidth, metrics.stringWidth(each.label())); - } - return x + widestLabelWidth; - } - - private String labelText() { - if (timing != null) { - return weight().label(); - } - return timingUnderWay ? TIMING_LABEL : "—"; - } - - private void drawBar(Graphics2D canvas, int x, int width) { - int barHeight = StudioTheme.scale(BAR_HEIGHT); - int y = (getHeight() - barHeight) / 2; - canvas.setColor(StudioTheme.HOVER_BACKGROUND); - canvas.fillRoundRect(x, y, width, barHeight, barHeight, barHeight); - if (timing == null) { - return; - } - int filledWidth = (int) Math.round(width * BakeWeight.meterFill(timing.totalMillis())); - canvas.setColor(color()); - canvas.fillRoundRect(x, y, Math.max(barHeight, filledWidth), barHeight, barHeight, barHeight); - } - - private int timeWidth(Graphics2D canvas) { - return canvas.getFontMetrics(StudioTheme.smallFont()).stringWidth(WIDEST_TIME); - } - - private void drawTime(Graphics2D canvas, int x) { - if (timing == null) { - return; - } - canvas.setFont(StudioTheme.smallFont()); - FontMetrics metrics = canvas.getFontMetrics(); - String time = BakeTiming.formatMillis(timing.totalMillis()); - canvas.setColor(StudioTheme.SECONDARY_TEXT); - canvas.drawString(time, x + timeWidth(canvas) - metrics.stringWidth(time), baseline(metrics)); - } - - private int baseline(FontMetrics metrics) { - return (getHeight() + metrics.getAscent() - metrics.getDescent()) / 2; - } -} diff --git a/core/src/main/java/art/arcane/iris/studio/map/BakeRun.java b/core/src/main/java/art/arcane/iris/studio/map/BakeRun.java deleted file mode 100644 index 33c9de8d9..000000000 --- a/core/src/main/java/art/arcane/iris/studio/map/BakeRun.java +++ /dev/null @@ -1,25 +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 . - */ - -package art.arcane.iris.studio.map; - -/** - * How long one bake of a procedural object's variants took. - */ -record BakeRun(long totalNanos, int variantCount) { -} diff --git a/core/src/main/java/art/arcane/iris/studio/map/BakeTiming.java b/core/src/main/java/art/arcane/iris/studio/map/BakeTiming.java deleted file mode 100644 index 5713c3635..000000000 --- a/core/src/main/java/art/arcane/iris/studio/map/BakeTiming.java +++ /dev/null @@ -1,71 +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 . - */ - -package art.arcane.iris.studio.map; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Locale; -import java.util.function.BooleanSupplier; -import java.util.function.Supplier; - -/** - * A procedural object's variants baked five times over, keeping the median run. The first run is slow while the JIT - * compiles the baker, and the garbage collector or chunk generation can slow any other, so neither ends up in the middle. - */ -record BakeTiming(BakeRun median) { - private static final int RUN_COUNT = 5; - private static final double NANOS_PER_MILLI = 1_000_000D; - - /** Null when {@code bake} finds nothing to bake, or once the timing is no longer wanted. */ - static BakeTiming measure(Supplier bake, BooleanSupplier stillWanted) { - List runs = new ArrayList<>(); - for (int run = 0; run < RUN_COUNT; run++) { - if (!stillWanted.getAsBoolean()) { - return null; - } - BakeRun measured = bake.get(); - if (measured == null) { - return null; - } - runs.add(measured); - } - runs.sort(Comparator.comparingLong(BakeRun::totalNanos)); - return new BakeTiming(runs.get(runs.size() / 2)); - } - - double totalMillis() { - return median.totalNanos() / NANOS_PER_MILLI; - } - - /** How long the bake took and when world generation pays for it. */ - String explain() { - String variants = median.variantCount() == 1 ? "1 variant" : median.variantCount() + " variants"; - return "" + variants + " in " + formatMillis(totalMillis()) + " · median of " + RUN_COUNT + " runs
" - + "Paid once per pack load, by the first chunk placing it
" - + BakeWeight.scale() + ""; - } - - static String formatMillis(double millis) { - if (millis >= 1000D) { - return String.format(Locale.ROOT, "%.1f s", millis / 1000D); - } - return String.format(Locale.ROOT, millis < 10D ? "%.1f ms" : "%.0f ms", millis); - } -} diff --git a/core/src/main/java/art/arcane/iris/studio/map/BakeWeight.java b/core/src/main/java/art/arcane/iris/studio/map/BakeWeight.java deleted file mode 100644 index 99fb999e2..000000000 --- a/core/src/main/java/art/arcane/iris/studio/map/BakeWeight.java +++ /dev/null @@ -1,74 +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 . - */ - -package art.arcane.iris.studio.map; - -import java.awt.Color; - -/** - * How long a procedural object's bake stalls the chunk that first places it, against a server tick of 50 ms. - */ -enum BakeWeight { - LIGHT("Light", 1D, 50D, StudioTheme.SUCCESS), - MODERATE("Moderate", 50D, 500D, StudioTheme.WARNING), - HEAVY("Heavy", 500D, 5_000D, StudioTheme.ERROR); - - private final String label; - private final double fromMillis; - private final double meterFullAtMillis; - private final Color color; - - BakeWeight(String label, double fromMillis, double meterFullAtMillis, Color color) { - this.label = label; - this.fromMillis = fromMillis; - this.meterFullAtMillis = meterFullAtMillis; - this.color = color; - } - - static BakeWeight of(double millis) { - for (BakeWeight weight : values()) { - if (millis < weight.meterFullAtMillis) { - return weight; - } - } - return HEAVY; - } - - /** - * How full the meter is for a bake of {@code millis}: each weight takes an equal share of the meter, filled on a - * logarithmic scale, since bakes span thousands of times. - */ - static double meterFill(double millis) { - BakeWeight weight = of(millis); - double clamped = Math.clamp(millis, weight.fromMillis, weight.meterFullAtMillis); - double withinWeight = Math.log(clamped / weight.fromMillis) / Math.log(weight.meterFullAtMillis / weight.fromMillis); - return (weight.ordinal() + withinWeight) / values().length; - } - - static String scale() { - return "Light under " + BakeTiming.formatMillis(MODERATE.fromMillis) + ", heavy from " + BakeTiming.formatMillis(HEAVY.fromMillis); - } - - String label() { - return label; - } - - Color color() { - return color; - } -} diff --git a/core/src/main/java/art/arcane/iris/studio/map/LatestMeasurement.java b/core/src/main/java/art/arcane/iris/studio/map/LatestMeasurement.java index 6dbffa27b..790932a6e 100644 --- a/core/src/main/java/art/arcane/iris/studio/map/LatestMeasurement.java +++ b/core/src/main/java/art/arcane/iris/studio/map/LatestMeasurement.java @@ -25,9 +25,7 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import java.util.function.BooleanSupplier; import java.util.function.Consumer; -import java.util.function.Function; import java.util.function.Supplier; /** @@ -50,18 +48,9 @@ final class LatestMeasurement { * measured nothing. */ void measure(Supplier measurement, Consumer show) { - measureUntilSuperseded(stillWanted -> measurement.get(), show); - } - - /** - * Like {@link #measure}, for long measurements that ask {@code stillWanted} between steps and give up once another - * measurement was asked for. - */ - void measureUntilSuperseded(Function measurement, Consumer show) { long requested = generation.incrementAndGet(); - BooleanSupplier stillWanted = () -> requested == generation.get(); worker.execute(() -> { - T result = measureSafely(() -> measurement.apply(stillWanted)); + T result = measureSafely(measurement); EventQueue.invokeLater(() -> { if (requested == generation.get() && result != null) { show.accept(result); diff --git a/core/src/main/java/art/arcane/iris/studio/map/ObjectExplorer.java b/core/src/main/java/art/arcane/iris/studio/map/ObjectExplorer.java index d7e350ed2..3cdf16a0d 100644 --- a/core/src/main/java/art/arcane/iris/studio/map/ObjectExplorer.java +++ b/core/src/main/java/art/arcane/iris/studio/map/ObjectExplorer.java @@ -36,7 +36,6 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.OptionalLong; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -46,9 +45,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicLong; /** - * The map window's Objects and Procedural views: everything its source offers in a folder tree, the chosen one in 3D, - * and what it is made of. A procedural object's variants can also be compared side by side, baked from any seed. - * Inspired by the Procedural Objects workbench. + * The map window's Objects view: everything its source offers in a folder tree, the chosen one in 3D, and what it is + * made of. The variants of an entry can also be compared side by side. Inspired by the Procedural Objects workbench. */ final class ObjectExplorer { private static final String TINT_BIOME = "minecraft:plains"; @@ -63,14 +61,13 @@ final class ObjectExplorer { private final ObjectBrowser browser; private final OrbitViewport viewport = new OrbitViewport("Iris Object Viewer", "Choose an object"); private final ObjectLayerCut layerCut = new ObjectLayerCut(shownLayers -> showLayerCut()); - private final ObjectVariantPicker variantPicker = new ObjectVariantPicker(this::showVariant, this::showSeed, this::toggleComparing); + private final ObjectVariantPicker variantPicker = new ObjectVariantPicker(this::showVariant, this::toggleComparing); private final ObjectVariantGallery gallery = new ObjectVariantGallery(this::openVariant, this::redrawThumbnails); private final CardLayout viewCards = new CardLayout(); private final JPanel views = new JPanel(viewCards); private final JComponent viewWithOverlays; private final ObjectOverviewPanel overview; private final StudioStatusBar statusBar = new StudioStatusBar(); - private final LatestMeasurement bakeTimer = new LatestMeasurement<>("Iris Bake Timer"); private final ExecutorService loader = Executors.newSingleThreadExecutor(runnable -> { Thread thread = new Thread(runnable, "Iris Object Loader"); thread.setDaemon(true); @@ -94,8 +91,6 @@ final class ObjectExplorer { private String shownKey; private List shownVariants = List.of(); private int shownVariantIndex; - private OptionalLong packSeed = OptionalLong.empty(); - private OptionalLong shownSeed = OptionalLong.empty(); private boolean comparingVariants; private long thumbnailsDrawnForRevision = -1; private LoadedObject shown; @@ -107,7 +102,7 @@ final class ObjectExplorer { this.worldId = worldId; this.source = source; this.browser = new ObjectBrowser(source.noun(), this::showObject); - this.overview = new ObjectOverviewPanel(this::showSeeThrough, source.isBaked()); + this.overview = new ObjectOverviewPanel(this::showSeeThrough); views.add(layerCut.floatingOver(viewport), ONE_VARIANT_CARD); views.add(gallery, ALL_VARIANTS_CARD); this.viewWithOverlays = variantPicker.floatingOver(views); @@ -132,7 +127,7 @@ final class ObjectExplorer { /** * The 3D view with the slider that cuts away its top layers, or every variant side by side, under the bar that - * steps through variants and seeds. + * steps through variants. */ JComponent view() { return viewWithOverlays; @@ -182,8 +177,6 @@ final class ObjectExplorer { meshRevision.incrementAndGet(); loader.shutdownNow(); thumbnailPainter.shutdownNow(); - bakeTimer.discardPending(); - bakeTimer.close(); viewport.close(); gallery.close(); } @@ -234,13 +227,12 @@ final class ObjectExplorer { String key = shownKey != null && keys.contains(shownKey) ? shownKey : browser.firstObject(); if (key == null) { viewport.showEmptyState(source.emptyState()); - bakeTimer.discardPending(); overview.clear(); layerCut.showHeight(1); if (comparingVariants) { toggleComparing(); } - showVariantList(List.of(), OptionalLong.empty(), OptionalLong.empty(), 0); + showVariantList(List.of(), 0); return; } browser.select(key); @@ -248,59 +240,35 @@ final class ObjectExplorer { } /** - * Shows the first variant of the entry, baked from the pack's seed. The pack reloading the shown entry keeps the - * variant and the seed being looked at, unless the pack itself now sets another seed. + * Shows the first variant of the entry. The pack reloading the shown entry keeps the variant being looked at. */ private synchronized void showObject(String key) { if (closed) { return; } boolean reloadingShownObject = key.equals(shownKey); - OptionalLong previousPackSeed = packSeed; - OptionalLong exploredSeed = shownSeed; int variantIndex = reloadingShownObject ? shownVariantIndex : 0; shownKey = key; if (!reloadingShownObject) { - variantPicker.forgetTriedSeeds(); - showVariantList(List.of(), OptionalLong.empty(), OptionalLong.empty(), 0); + showVariantList(List.of(), 0); } - long revision = startBaking(key); + long revision = startLoadingVariants(key); loader.execute(() -> { if (closed || revision != objectRevision.get()) { return; } - OptionalLong pack = source.seed(key); - OptionalLong seed = reloadingShownObject && pack.equals(previousPackSeed) ? exploredSeed : pack; - loadVariants(revision, key, pack, seed, variantIndex); - }); - } - - // The seed shows at once, so stepping again continues from it even while this one bakes or fails. - private synchronized void showSeed(long seed) { - if (closed) { - return; - } - String key = shownKey; - OptionalLong pack = packSeed; - int variantIndex = shownVariantIndex; - shownSeed = OptionalLong.of(seed); - variantPicker.showSeed(shownSeed, pack); - long revision = startBaking(key + " with seed " + seed); - loader.execute(() -> { - if (!closed && revision == objectRevision.get()) { - loadVariants(revision, key, pack, OptionalLong.of(seed), variantIndex); - } + loadVariants(revision, key, variantIndex); }); } // On the loader thread. - private void loadVariants(long revision, String key, OptionalLong pack, OptionalLong seed, int preferredIndex) { + private void loadVariants(long revision, String key, int preferredIndex) { if (closed || revision != objectRevision.get()) { return; } try { IrisData data = engine().getData(); - List variants = seed.isPresent() ? source.variants(data, key, seed.getAsLong()) : source.variants(data, key); + List variants = source.variants(data, key); if (variants.isEmpty()) { throw new IllegalStateException("Nothing could be loaded for " + key); } @@ -313,34 +281,19 @@ final class ObjectExplorer { if (closed || revision != objectRevision.get()) { return; } - showVariantList(variants, pack, seed, index); + showVariantList(variants, index); showLoaded(revision, loaded); - timeBake(data, key, seed); }); } catch (RuntimeException error) { publish(() -> showFailure(revision, key, error)); } } - // Off the loader thread, so stepping through variants and seeds never waits on the timing. - private void timeBake(IrisData data, String key, OptionalLong seed) { - if (!source.isBaked() || seed.isEmpty()) { - return; - } - long bakedSeed = seed.getAsLong(); - overview.showTimingBake(); - bakeTimer.measureUntilSuperseded(stillWanted -> BakeTiming.measure(() -> source.timeBake(data, key, bakedSeed), stillWanted), - timing -> publish(() -> overview.showBakeTiming(timing))); - } - - private void showVariantList(List variants, OptionalLong pack, OptionalLong seed, int index) { + private void showVariantList(List variants, int index) { shownVariants = variants; shownVariantIndex = index; - packSeed = pack; - shownSeed = seed; variantListRevision.incrementAndGet(); variantPicker.showVariants(variants.size(), index); - variantPicker.showSeed(seed, pack); if (!comparingVariants) { return; } @@ -448,7 +401,7 @@ final class ObjectExplorer { } private String galleryHeading() { - return String.format(Locale.ROOT, "%s · %d variants%s", shownKey, shownVariants.size(), seedNote()); + return String.format(Locale.ROOT, "%s · %d variants", shownKey, shownVariants.size()); } private static ObjectMesh.Bounds largestSize(List meshes) { @@ -464,7 +417,7 @@ final class ObjectExplorer { } // A new list of variants is on its way, so every thumbnail is outdated, unlike when stepping to another variant. - private long startBaking(String key) { + private long startLoadingVariants(String key) { if (comparingVariants) { gallery.showLoading(); } @@ -481,8 +434,7 @@ final class ObjectExplorer { private LoadedObject load(IrisObject object) { Map blocks = visibleBlocks(object); - ObjectMesh.Bounds extent = ObjectMesh.Bounds.of(blocks.keySet()); - ObjectMesh.Bounds bounds = source.groundY(object).stream().mapToObj(extent::standingOn).findFirst().orElse(extent); + ObjectMesh.Bounds bounds = ObjectMesh.Bounds.of(blocks.keySet()); ObjectMesh mesh = ObjectMesh.build(blocks, this::modelOf, bounds, block -> false); ObjectSummary summary = ObjectSummary.of(object.getLoadKey(), mesh.bounds(), blocks.values(), this::iconOf); return new LoadedObject(blocks, mesh, summary); @@ -518,17 +470,8 @@ final class ObjectExplorer { String cut = layerCut.isCutting() ? String.format(Locale.ROOT, " · showing layers 1-%d of %d", layerCut.shownLayerCount(), layerCut.layerCount()) : ""; - statusBar.showSummary(String.format(Locale.ROOT, "%s%s · %,d blocks · %,d faces drawn%s", - summary.key(), seedNote(), summary.blockCount(), mesh.faceCount(), cut)); - } - - // A seed being tried is not in the pack until its "seed" field says so. - private String seedNote() { - if (shownSeed.isEmpty()) { - return ""; - } - String note = " · seed " + shownSeed.getAsLong(); - return shownSeed.equals(packSeed) ? note : note + " (the pack has " + packSeed.getAsLong() + ")"; + statusBar.showSummary(String.format(Locale.ROOT, "%s · %,d blocks · %,d faces drawn%s", + summary.key(), summary.blockCount(), mesh.faceCount(), cut)); } private synchronized void showSeeThrough(Set blockTypes) { @@ -588,7 +531,6 @@ final class ObjectExplorer { viewport.showMessage("Could not load " + key); gallery.showMessage("Could not load " + key); thumbnailsDrawnForRevision = -1; - bakeTimer.discardPending(); overview.clear(); layerCut.showHeight(1); statusBar.showError(error.getMessage() == null ? error.getClass().getSimpleName() : error.getMessage()); diff --git a/core/src/main/java/art/arcane/iris/studio/map/ObjectMesh.java b/core/src/main/java/art/arcane/iris/studio/map/ObjectMesh.java index c79f8f5cc..6f533e6a3 100644 --- a/core/src/main/java/art/arcane/iris/studio/map/ObjectMesh.java +++ b/core/src/main/java/art/arcane/iris/studio/map/ObjectMesh.java @@ -247,11 +247,6 @@ record ObjectMesh(List solidQuads, List translucentQuads, List this(minX, minY, minZ, maxX, maxY, maxZ, minY); } - /** This extent with the terrain surface at {@code groundY}, so anything below it shows as buried. */ - Bounds standingOn(int groundY) { - return new Bounds(minX, minY, minZ, maxX, maxY, maxZ, groundY); - } - static Bounds of(Iterable positions) { int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; diff --git a/core/src/main/java/art/arcane/iris/studio/map/ObjectOverviewPanel.java b/core/src/main/java/art/arcane/iris/studio/map/ObjectOverviewPanel.java index 97b27e8d6..af8667991 100644 --- a/core/src/main/java/art/arcane/iris/studio/map/ObjectOverviewPanel.java +++ b/core/src/main/java/art/arcane/iris/studio/map/ObjectOverviewPanel.java @@ -72,7 +72,6 @@ final class ObjectOverviewPanel extends JPanel { private final JLabel blockCount = statValue(); private final JLabel blockTypes = statValue(); private final JLabel filled = statValue(); - private final BakeMeter bakeMeter = new BakeMeter(); private final JTextField filterField = new JTextField(); private final DefaultListModel rows = new DefaultListModel<>(); private final JList list = new JList<>(rows) { @@ -89,15 +88,14 @@ final class ObjectOverviewPanel extends JPanel { /** * @param onSeeThroughChanged told which block types to draw see-through whenever the user changes them - * @param showsBakeTime whether the objects are baked, so the time their bake takes is shown */ - ObjectOverviewPanel(Consumer> onSeeThroughChanged, boolean showsBakeTime) { + ObjectOverviewPanel(Consumer> onSeeThroughChanged) { super(new BorderLayout()); this.onSeeThroughChanged = onSeeThroughChanged; setPreferredSize(StudioTheme.scaledSize(PANEL_WIDTH, 0)); setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, StudioTheme.SEPARATOR)); setBackground(StudioTheme.PANEL_BACKGROUND); - add(buildHeader(showsBakeTime), BorderLayout.NORTH); + add(buildHeader(), BorderLayout.NORTH); add(buildBlockList(), BorderLayout.CENTER); } @@ -115,14 +113,6 @@ final class ObjectOverviewPanel extends JPanel { refilter(); } - void showTimingBake() { - bakeMeter.showTiming(); - } - - void showBakeTiming(BakeTiming timing) { - bakeMeter.show(timing); - } - void clear() { summary = null; title.setText(" "); @@ -130,13 +120,12 @@ final class ObjectOverviewPanel extends JPanel { for (JLabel value : List.of(size, blockCount, blockTypes, filled)) { value.setText("—"); } - bakeMeter.clear(); rows.clear(); seeThroughTypes.clear(); showSeeThroughState(); } - private JPanel buildHeader(boolean showsBakeTime) { + private JPanel buildHeader() { JPanel header = new JPanel(); header.setLayout(new BoxLayout(header, BoxLayout.Y_AXIS)); header.setOpaque(false); @@ -156,11 +145,6 @@ final class ObjectOverviewPanel extends JPanel { stats.add(stat("Filled volume", filled)); filled.setToolTipText("How much of the object's bounding box its blocks fill"); header.add(leftAligned(stats)); - if (showsBakeTime) { - JPanel bakeTime = stat("Bake time", bakeMeter); - bakeTime.setBorder(StudioTheme.emptyBorder(4, 0, 4, 0)); - header.add(leftAligned(bakeTime)); - } clear(); return header; } diff --git a/core/src/main/java/art/arcane/iris/studio/map/ObjectSeedChooser.java b/core/src/main/java/art/arcane/iris/studio/map/ObjectSeedChooser.java deleted file mode 100644 index aa0dea240..000000000 --- a/core/src/main/java/art/arcane/iris/studio/map/ObjectSeedChooser.java +++ /dev/null @@ -1,160 +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 . - */ -package art.arcane.iris.studio.map; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.UIManager; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.EventQueue; -import java.util.ArrayList; -import java.util.List; -import java.util.OptionalLong; -import java.util.concurrent.ThreadLocalRandom; -import java.util.function.LongConsumer; - -/** - * Where the seed of a procedural object's variants is chosen: typed in, picked again from the seeds tried on this - * object with the pack's own first, or rerolled at random. It keeps its size whatever it shows, so the bar it sits in - * never shifts under the mouse. - */ -final class ObjectSeedChooser extends JPanel { - private static final long serialVersionUID = 3127745038254406118L; - private static final int FIELD_WIDTH = 120; - private static final int TRIED_SEEDS_KEPT = 12; - // Small enough to read back and type, and far more seeds than anyone tries. - private static final int RANDOM_SEED_BOUND = 1_000_000; - - private final JComboBox seeds = new JComboBox<>(); - private final LongConsumer onSeedChosen; - private final List triedSeedsNewestFirst = new ArrayList<>(); - private OptionalLong packSeed = OptionalLong.empty(); - private long shownSeed; - private boolean showingSeeds; - - /** - * @param onSeedChosen told the seed to bake the variants from whenever the user chooses another one - */ - ObjectSeedChooser(LongConsumer onSeedChosen) { - super(new BorderLayout(StudioTheme.scale(4), 0)); - this.onSeedChosen = onSeedChosen; - setOpaque(false); - JLabel label = new JLabel("Seed"); - label.setFont(StudioTheme.smallFont()); - label.setForeground(StudioTheme.SECONDARY_TEXT); - seeds.setEditable(true); - seeds.setFont(StudioTheme.smallFont()); - seeds.setToolTipText("Type a seed and press Enter, or pick one tried before"); - seeds.setRenderer(new PackSeedMarker()); - seeds.setPreferredSize(new Dimension(StudioTheme.scale(FIELD_WIDTH), seeds.getPreferredSize().height)); - seeds.addActionListener(event -> { - if (!showingSeeds) { - EventQueue.invokeLater(this::chooseEnteredSeed); - } - }); - add(label, BorderLayout.WEST); - add(seeds, BorderLayout.CENTER); - add(StudioToolbar.button("Reroll", "Bake the variants from a random seed", this::reroll), BorderLayout.EAST); - } - - /** Starts a new object's list of tried seeds. */ - void forgetTriedSeeds() { - triedSeedsNewestFirst.clear(); - } - - void showSeed(long shown, OptionalLong pack) { - shownSeed = shown; - packSeed = pack; - if (!isPackSeed(shown)) { - rememberTried(shown); - } - DefaultComboBoxModel choices = new DefaultComboBoxModel<>(); - pack.ifPresent(choices::addElement); - triedSeedsNewestFirst.forEach(choices::addElement); - showingSeeds = true; - try { - seeds.setModel(choices); - seeds.setSelectedItem(shown); - } finally { - showingSeeds = false; - } - } - - private void rememberTried(long seed) { - triedSeedsNewestFirst.remove(seed); - triedSeedsNewestFirst.add(0, seed); - while (triedSeedsNewestFirst.size() > TRIED_SEEDS_KEPT) { - triedSeedsNewestFirst.remove(triedSeedsNewestFirst.size() - 1); - } - } - - // A pick from the list arrives as a seed, anything typed as text. - private void chooseEnteredSeed() { - OptionalLong entered = parse(seeds.getSelectedItem()); - if (entered.isEmpty()) { - UIManager.getLookAndFeel().provideErrorFeedback(seeds); - showSeed(shownSeed, packSeed); - return; - } - if (entered.getAsLong() != shownSeed) { - onSeedChosen.accept(entered.getAsLong()); - } - } - - private static OptionalLong parse(Object entered) { - if (entered instanceof Long seed) { - return OptionalLong.of(seed); - } - try { - return OptionalLong.of(Long.parseLong(String.valueOf(entered).trim())); - } catch (NumberFormatException notASeed) { - return OptionalLong.empty(); - } - } - - private void reroll() { - long seed; - do { - seed = ThreadLocalRandom.current().nextInt(RANDOM_SEED_BOUND); - } while (seed == shownSeed); - onSeedChosen.accept(seed); - } - - private boolean isPackSeed(Object seed) { - return packSeed.isPresent() && seed instanceof Long value && value == packSeed.getAsLong(); - } - - private final class PackSeedMarker extends DefaultListCellRenderer { - private static final long serialVersionUID = -6061513307766393251L; - - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focused) { - super.getListCellRendererComponent(list, value, index, selected, focused); - if (index >= 0 && isPackSeed(value)) { - setText(value + " (pack)"); - } - return this; - } - } -} diff --git a/core/src/main/java/art/arcane/iris/studio/map/ObjectSource.java b/core/src/main/java/art/arcane/iris/studio/map/ObjectSource.java index 8eb0eaa71..c48efc422 100644 --- a/core/src/main/java/art/arcane/iris/studio/map/ObjectSource.java +++ b/core/src/main/java/art/arcane/iris/studio/map/ObjectSource.java @@ -21,12 +21,9 @@ import art.arcane.iris.pack.loading.IrisData; import art.arcane.iris.structure.object.IrisObject; import java.util.List; -import java.util.OptionalInt; -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. + * Where an object explorer gets what it shows: the pack's object files. Called on the explorer's loader thread only. */ interface ObjectSource { /** What one entry is called, such as "object", for the browser's texts. */ @@ -38,34 +35,6 @@ interface ObjectSource { /** The key of every entry, where a slash separates folders. */ List keys(IrisData data); - /** The objects of the entry, one for an object file and one per variant for a procedural object; empty when none load. */ + /** The objects of the entry, one for an object file and one per variant for an entry with variants; empty when none load. */ List variants(IrisData data, String key); - - /** The height, in {@code object}'s own blocks, that the terrain surface meets; empty to stand it on its lowest block. */ - default OptionalInt groundY(IrisObject object) { - return OptionalInt.empty(); - } - - /** The seed the pack bakes the entry's variants from; empty for anything not generated from a seed. */ - default OptionalLong seed(String key) { - return OptionalLong.empty(); - } - - /** The entry's variants as {@code seed} would bake them; only asked of entries that have a seed. */ - default List variants(IrisData data, String key, long seed) { - throw new UnsupportedOperationException(key + " is not generated from a seed"); - } - - /** Whether its entries are baked from settings, which costs world generation time worth measuring. */ - default boolean isBaked() { - return false; - } - - /** - * Bakes the entry's variants from {@code seed} once more and times it; null when the entry is gone. Only asked of - * baked sources, on a thread of its own. - */ - default BakeRun timeBake(IrisData data, String key, long seed) { - throw new UnsupportedOperationException(key + " is not baked"); - } } diff --git a/core/src/main/java/art/arcane/iris/studio/map/ObjectVariantPicker.java b/core/src/main/java/art/arcane/iris/studio/map/ObjectVariantPicker.java index 73a4b182b..d4845cb8d 100644 --- a/core/src/main/java/art/arcane/iris/studio/map/ObjectVariantPicker.java +++ b/core/src/main/java/art/arcane/iris/studio/map/ObjectVariantPicker.java @@ -30,14 +30,11 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.RoundRectangle2D; -import java.util.OptionalLong; import java.util.function.IntConsumer; -import java.util.function.LongConsumer; /** - * A small bar floating at the bottom of the object view that steps through the variants of a procedural object and - * the seeds they are baked from, and switches between one variant in 3D and all of them side by side. It hides itself - * for anything with a single variant and no seed. + * A small bar floating at the bottom of the object view that steps through the variants of an entry and switches + * between one variant in 3D and all of them side by side. It hides itself for anything with a single variant. */ final class ObjectVariantPicker extends JPanel { private static final long serialVersionUID = -2716301839488217455L; @@ -49,20 +46,17 @@ final class ObjectVariantPicker extends JPanel { private final JLabel shownVariant = label(VARIANT_LABEL_WIDTH); private final JComponent variantStepper; - private final ObjectSeedChooser seedChooser; private final JButton compareButton; private final IntConsumer onVariantChosen; private int variantCount; private int shownIndex; - private boolean seeded; private int coveredLeftWidth; /** * @param onVariantChosen told the index of the variant to show whenever the user steps to another one - * @param onSeedChosen told the seed to bake the variants from whenever the user chooses another one * @param onCompareToggled told when the user switches between one variant and all of them */ - ObjectVariantPicker(IntConsumer onVariantChosen, LongConsumer onSeedChosen, Runnable onCompareToggled) { + ObjectVariantPicker(IntConsumer onVariantChosen, Runnable onCompareToggled) { this.onVariantChosen = onVariantChosen; setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); setOpaque(false); @@ -70,12 +64,9 @@ final class ObjectVariantPicker extends JPanel { variantStepper = stepper(shownVariant, StudioToolbar.button("‹", "Previous variant" + VARIANT_SHORTCUT_HINT, () -> stepBy(-1)), StudioToolbar.button("›", "Next variant" + VARIANT_SHORTCUT_HINT, () -> stepBy(1))); - seedChooser = new ObjectSeedChooser(onSeedChosen); compareButton = StudioToolbar.button("", "", onCompareToggled); add(variantStepper); add(Box.createHorizontalStrut(StudioTheme.scale(SECTION_GAP))); - add(seedChooser); - add(Box.createHorizontalStrut(StudioTheme.scale(SECTION_GAP))); add(compareButton); showComparing(false); showVariants(0, 0); @@ -139,21 +130,8 @@ final class ObjectVariantPicker extends JPanel { shownVariant.setText("Variant " + (index + 1) + " of " + count); variantStepper.setVisible(count > 1); compareButton.setVisible(count > 1); - showWhenUseful(); - } - - /** - * Shows the seed the variants are baked from; empty for objects not generated from a seed. - */ - void showSeed(OptionalLong shown, OptionalLong pack) { - seeded = shown.isPresent(); - seedChooser.setVisible(seeded); - shown.ifPresent(seed -> seedChooser.showSeed(seed, pack)); - showWhenUseful(); - } - - void forgetTriedSeeds() { - seedChooser.forgetTriedSeeds(); + setVisible(count > 1); + relayout(); } void showComparing(boolean comparing) { @@ -171,11 +149,6 @@ final class ObjectVariantPicker extends JPanel { onVariantChosen.accept(shownIndex); } - private void showWhenUseful() { - setVisible(variantCount > 1 || seeded); - relayout(); - } - private void relayout() { if (getParent() != null) { getParent().revalidate();