mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Time procedural bakes in the studio with a median-of-five meter
Authors could not see what a procedural object costs generation. The Procedural view now bakes the chosen entry five times in the background, keeps the median run, and rates it Light, Moderate or Heavy against a server tick, with each stage's time in the tooltip. SceneView gains isBaked and timeBake (one run, a BakeRun); the studio asks five times so a newer choice stops the rest. No pins moved: generation bakes with BakeProfile.NONE and nothing in packs changed. v3: 9e30508e3 7d240ddf8
This commit is contained in:
1 parent
f3bf0aea4b
commit
76dcab175b
14 files changed
+448
-6
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* One timed bake of everything an entry is built from, as {@link SceneView#timeBake} reports it.
|
||||
*
|
||||
* @param variantCount how many variants the run baked
|
||||
* @param stages the steps a variant is baked in, in order, each with its time added up over every variant
|
||||
*/
|
||||
public record BakeRun(int variantCount, List<Stage> stages) {
|
||||
public BakeRun {
|
||||
Objects.requireNonNull(stages, "stages");
|
||||
if (variantCount < 0) {
|
||||
throw new IllegalArgumentException("A bake run cannot have " + variantCount + " variants");
|
||||
}
|
||||
stages = List.copyOf(stages);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param label what the studio calls the step, such as {@code Paint}
|
||||
* @param nanos how long the step took, in nanoseconds
|
||||
*/
|
||||
public record Stage(String label, long nanos) {
|
||||
public Stage {
|
||||
Objects.requireNonNull(label, "label");
|
||||
if (label.isBlank()) {
|
||||
throw new IllegalArgumentException("A bake stage needs a label");
|
||||
}
|
||||
if (nanos < 0L) {
|
||||
throw new IllegalArgumentException("Bake stage " + label + " took " + nanos + " ns; a time is never negative");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,18 @@ public non-sealed interface SceneView extends StudioView {
|
||||
* @param variant from 0 to the entry's {@link SceneEntry#variants()}, exclusive
|
||||
*/
|
||||
Optional<GeneratedObject> scene(PackWorld world, String key, int variant);
|
||||
|
||||
/** Whether the entries are baked from settings, which costs generation time {@link #timeBake} can measure. */
|
||||
default boolean isBaked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bakes the entry named {@code key} once more the way generation does, without keeping the result, and times each
|
||||
* step. The studio asks several times and keeps the median, so one call is one run. Asked off the server's threads;
|
||||
* empty when the pack has no such entry or the view does not bake.
|
||||
*/
|
||||
default Optional<BakeRun> timeBake(PackWorld world, String key) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.volmit.tooling;
|
||||
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class BakeRunTest {
|
||||
@Test
|
||||
void keepsItsStagesInOrderAndApartFromTheListItWasGiven() {
|
||||
List<BakeRun.Stage> given = new ArrayList<>(List.of(new BakeRun.Stage("Parts", 5L), new BakeRun.Stage("Build", 7L)));
|
||||
BakeRun run = new BakeRun(3, given);
|
||||
given.clear();
|
||||
|
||||
assertEquals(List.of("Parts", "Build"), run.stages().stream().map(BakeRun.Stage::label).toList());
|
||||
assertThrows(UnsupportedOperationException.class, () -> run.stages().clear());
|
||||
}
|
||||
|
||||
@Test
|
||||
void refusesATimeBelowZeroAndAStageWithoutALabel() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new BakeRun.Stage("Parts", -1L));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BakeRun.Stage(" ", 1L));
|
||||
assertThrows(IllegalArgumentException.class, () -> new BakeRun(-1, List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aViewThatDoesNotBakeSaysSoAndTimesNothing() {
|
||||
SceneView plain = new SceneView() {
|
||||
@Override
|
||||
public ResourceId id() {
|
||||
return ResourceId.parse("test:plain");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return "Plain";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Plain";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SceneEntry> entries(PackWorld world) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<GeneratedObject> scene(PackWorld world, String key, int variant) {
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
|
||||
assertFalse(plain.isBaked());
|
||||
assertTrue(plain.timeBake(null, "any").isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user