mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +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
+1
-1
@@ -46,7 +46,7 @@ types that carry them and lists what the Iris adapter still owes.
|
||||
| Dense chunk output | `Hunk<T>`, `GenerationContext.blocks`, reference `ArrayHunk<T>` |
|
||||
| Positions, boxes and faces | `com.volmit.geometry`: `BlockPosition`, `BlockBox`, `BlockFace` |
|
||||
| Sparse geometry | `GeneratedObject` |
|
||||
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
|
||||
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `BakeRun` (`Stage`), `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
|
||||
| Commands of a module | `com.volmit.tooling`: `ToolingRegistry.registerCommand`, immutable `Command` (`named`, `alias`, `describe`, `child`, `argument`, `runs`, `openToEveryone`), typed `Argument` (`word`, `text`, `integer`, `decimal`, `flag`, `choice`, `resource`, `registered`, `orElse`, `suggesting`), `CommandAction`, `CommandContext` (`get`, `sender`, `pack`, `world`, `platform`), plain-text `Sender`, `ToolPack` (`edit` with `PackEdit`, `outputFolder`, `objects` with `ObjectCodec`), host `CommandRegistration` in `FeatureCatalog.commands()` |
|
||||
| Buffered placement writes | `PlacementRequest`, `PlacementAccess`, host-owned `PlacementEdit` |
|
||||
| Typed generation and persistent storage | `mantle` package |
|
||||
|
||||
@@ -518,6 +518,9 @@ final class RuinScenes implements SceneView {
|
||||
- A `SceneView` lists entries (`SceneEntry`) and gives each variant's blocks as a `GeneratedObject`, drawn in 3D. A
|
||||
`PatternView` lists entries (`PatternEntry`) and gives the blocks one lays over a `PatternArea` at a depth as a
|
||||
`BlockPattern`, drawn from above. `StudioView` is sealed to these two kinds: the studio draws nothing else.
|
||||
- A `SceneView` whose entries are baked from settings says so (`isBaked`) and times a bake on request (`timeBake`, a
|
||||
`BakeRun` with a time per stage). One call is one run; the studio asks five times off the server's threads and keeps
|
||||
the median.
|
||||
- A view's id is the module's id or starts with it and `/`. A second view with an id already registered fails the
|
||||
pack load, naming both modules.
|
||||
- The studio asks from its own threads, several at once, for a world of the pack it shows. A view keeps what it
|
||||
|
||||
@@ -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