Remove the Swing vision map and noise explorer

The studio app's map and noise views replace them. Gone: VisionGUI,
NoiseExplorerGUI, their render controllers, viewports and palette, their
tests, the iris studio noise command on Bukkit and modded, and the 73
message keys only they used, from the Java constants and every catalog.
The overlays the studio bridge uses for player markers and teleports stay.
This commit is contained in:
piexel committed 2026-11-06 05:15:02 +01:00
1 parent db2962a25e
commit 9c39c564be
41 files changed
+2 -6103

No files matched your search

@@ -1,117 +0,0 @@
package art.arcane.iris.core.gui;
import art.arcane.iris.engine.framework.MeteredCache;
import art.arcane.iris.engine.framework.PreservationRegistry;
import art.arcane.iris.spi.IrisServices;
import art.arcane.volmlib.util.function.NoiseProvider;
import org.junit.Test;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class NoiseExplorerGUITest {
@Test
public void openingInitialSourceBuildsSamplerExactlyOnce() throws Exception {
AtomicInteger factoryCalls = new AtomicInteger();
CountDownLatch firstFactoryCall = new CountDownLatch(1);
CountDownLatch releaseFactory = new CountDownLatch(1);
CountDownLatch duplicateFactoryCall = new CountDownLatch(1);
AtomicReference<NoiseExplorerGUI> explorerReference = new AtomicReference<>();
try {
SwingUtilities.invokeAndWait(() -> {
NoiseExplorerGUI explorer = new NoiseExplorerGUI(sourceSeed -> {
int invocation = factoryCalls.incrementAndGet();
if (invocation == 1) {
firstFactoryCall.countDown();
try {
releaseFactory.await(3L, TimeUnit.SECONDS);
} catch (InterruptedException error) {
Thread.currentThread().interrupt();
}
} else {
duplicateFactoryCall.countDown();
}
return constantSampler();
}, "Test source", 12345L);
explorer.buildSidebar();
explorer.openViewer();
explorerReference.set(explorer);
});
assertTrue(firstFactoryCall.await(3L, TimeUnit.SECONDS));
releaseFactory.countDown();
assertFalse(duplicateFactoryCall.await(300L, TimeUnit.MILLISECONDS));
assertEquals(1, factoryCalls.get());
} finally {
releaseFactory.countDown();
NoiseExplorerGUI explorer = explorerReference.get();
if (explorer != null) {
SwingUtilities.invokeAndWait(explorer::close);
}
}
}
@Test
public void allExecutorsRegisterForPreservationAndCloseWithWindow() throws Exception {
PreservationRegistry previous = IrisServices.getOrNull(PreservationRegistry.class);
RecordingPreservationRegistry preservation = new RecordingPreservationRegistry();
AtomicReference<NoiseExplorerGUI> explorerReference = new AtomicReference<>();
IrisServices.register(PreservationRegistry.class, preservation);
try {
SwingUtilities.invokeAndWait(() -> explorerReference.set(
new NoiseExplorerGUI(sourceSeed -> constantSampler(), "Test source", 12345L)
));
assertEquals(2, preservation.executors.size());
SwingUtilities.invokeAndWait(explorerReference.get()::close);
for (ExecutorService executor : preservation.executors) {
assertTrue(executor.isShutdown());
}
} finally {
NoiseExplorerGUI explorer = explorerReference.get();
if (explorer != null) {
SwingUtilities.invokeAndWait(explorer::close);
}
if (previous == null) {
IrisServices.remove(PreservationRegistry.class);
} else {
IrisServices.register(PreservationRegistry.class, previous);
}
}
}
private static NoiseProvider constantSampler() {
return (x, z) -> 0.5D;
}
private static final class RecordingPreservationRegistry implements PreservationRegistry {
private final List<ExecutorService> executors = new ArrayList<>();
@Override
public void register(Thread thread) {
}
@Override
public void register(ExecutorService service) {
executors.add(service);
}
@Override
public void registerCache(MeteredCache cache) {
}
@Override
public void dereference() {
}
}
}
@@ -1,36 +0,0 @@
package art.arcane.iris.core.gui;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public final class NoisePaletteTest {
@Test
public void invalidSamplesUseVisibleDiagnosticColor() {
assertEquals(NoisePalette.INVALID_COLOR, NoisePalette.TERRAIN.color(Double.NaN));
assertEquals(NoisePalette.INVALID_COLOR, NoisePalette.TERRAIN.color(Double.POSITIVE_INFINITY));
}
@Test
public void paletteClipsValuesToItsDocumentedRange() {
assertEquals(NoisePalette.SIGNED.color(-1D), NoisePalette.SIGNED.color(-10D));
assertEquals(NoisePalette.SIGNED.color(1D), NoisePalette.SIGNED.color(10D));
assertNotEquals(NoisePalette.SIGNED.color(-1D), NoisePalette.SIGNED.color(1D));
}
@Test
public void finiteHotPathAndCachedDisplayColorsMatchCanonicalLookup() {
for (NoisePalette palette : NoisePalette.values()) {
for (int index = -200; index <= 200; index++) {
double value = index / 100D;
assertEquals(palette.color(value), palette.colorFinite(value));
double normalized = (value - palette.minimum()) / (palette.maximum() - palette.minimum());
assertEquals(
palette.colorNormalized(normalized),
palette.displayColorNormalized(normalized).getRGB() & 0xFFFFFF
);
}
}
}
}
@@ -1,413 +0,0 @@
package art.arcane.iris.core.gui;
import art.arcane.volmlib.util.function.NoiseProvider;
import org.junit.Test;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public final class NoiseRenderCoordinatorTest {
@Test
public void adaptiveStepNeverExceedsHardSampleBudget() {
int sampleStep = NoiseRenderCoordinator.sampleStepForBudget(3840, 2160, 400_000L);
assertTrue(sampleStep > 1);
assertTrue(NoiseRenderCoordinator.sampleCount(3840, 2160, sampleStep) <= 400_000L);
assertEquals(1, NoiseRenderCoordinator.sampleStepForBudget(320, 200, 64_000L));
}
@Test
public void timedBudgetStaysSmallForSlowSourcesAndCapsFastSources() {
assertEquals(24_000L, NoiseRenderCoordinator.timeBoundSampleBudget(
18_000L,
2_000D,
500D,
24_000L,
120_000L
));
assertEquals(120_000L, NoiseRenderCoordinator.timeBoundSampleBudget(
18_000L,
10D,
500D,
24_000L,
120_000L
));
}
@Test
public void eachRefinementPassMakesVisibleProgressEvenForSlowSources() {
assertEquals(7, NoiseRenderCoordinator.nextRefinementStep(1440, 770, 7, 24_000L));
assertEquals(2, NoiseRenderCoordinator.nextRefinementStep(1440, 770, 2, 24_000L));
assertEquals(1, NoiseRenderCoordinator.nextRefinementStep(320, 200, 3, 400_000L));
int boundedStep = NoiseRenderCoordinator.nextRefinementStep(3840, 2160, 64, 48_000L);
assertTrue(NoiseRenderCoordinator.sampleCount(3840, 2160, boundedStep) <= 48_000L);
}
@Test
public void sameRevisionRefinementSupersedesAnInFlightPreview() throws Exception {
CountDownLatch previewStarted = new CountDownLatch(1);
CountDownLatch releasePreview = new CountDownLatch(1);
CountDownLatch completed = new CountDownLatch(1);
List<Integer> completedSteps = new ArrayList<>();
AtomicReference<Throwable> failure = new AtomicReference<>();
NoiseRenderCoordinator coordinator = new NoiseRenderCoordinator(2, new NoiseRenderCoordinator.Listener() {
@Override
public void onRenderStarted(NoiseRenderCoordinator.Request request) {
if (request.sampleStep() == 4) {
previewStarted.countDown();
}
}
@Override
public void onRenderCompleted(NoiseRenderCoordinator.Result result) {
completedSteps.add(result.request().sampleStep());
completed.countDown();
}
@Override
public void onRenderFailed(NoiseRenderCoordinator.Request request, Throwable error) {
failure.set(error);
completed.countDown();
}
});
try {
AtomicBoolean firstSample = new AtomicBoolean(true);
NoiseProvider previewSampler = (x, z) -> {
if (firstSample.compareAndSet(true, false)) {
try {
releasePreview.await(3L, TimeUnit.SECONDS);
} catch (InterruptedException error) {
Thread.currentThread().interrupt();
}
}
return 0.25D;
};
NoiseRenderCoordinator.Request preview = new NoiseRenderCoordinator.Request(
7L,
previewSampler,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
64,
32,
4
);
NoiseRenderCoordinator.Request refinement = new NoiseRenderCoordinator.Request(
7L,
(x, z) -> 0.75D,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
64,
32,
2
);
coordinator.request(preview);
assertTrue(previewStarted.await(3L, TimeUnit.SECONDS));
coordinator.request(refinement);
releasePreview.countDown();
assertTrue(completed.await(3L, TimeUnit.SECONDS));
assertEquals(null, failure.get());
assertEquals(List.of(2), completedSteps);
} finally {
releasePreview.countDown();
coordinator.close();
}
}
@Test
public void samplingRunsOffEdtAndStopsWhenRenderCompletes() throws Exception {
CountDownLatch completed = new CountDownLatch(1);
AtomicReference<NoiseRenderCoordinator.Result> result = new AtomicReference<>();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicReference<String> samplingThread = new AtomicReference<>();
AtomicBoolean sampledOnEdt = new AtomicBoolean();
AtomicInteger samples = new AtomicInteger();
NoiseRenderCoordinator coordinator = new NoiseRenderCoordinator(2, new NoiseRenderCoordinator.Listener() {
@Override
public void onRenderStarted(NoiseRenderCoordinator.Request request) {
}
@Override
public void onRenderCompleted(NoiseRenderCoordinator.Result rendered) {
result.set(rendered);
completed.countDown();
}
@Override
public void onRenderFailed(NoiseRenderCoordinator.Request request, Throwable error) {
failure.set(error);
completed.countDown();
}
});
try {
NoiseProvider sampler = (x, z) -> {
samples.incrementAndGet();
samplingThread.compareAndSet(null, Thread.currentThread().getName());
sampledOnEdt.compareAndSet(false, SwingUtilities.isEventDispatchThread());
return x + z;
};
NoiseRenderCoordinator.Request request = new NoiseRenderCoordinator.Request(
1L,
sampler,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.SIGNED,
17,
11,
1
);
SwingUtilities.invokeAndWait(() -> coordinator.request(request));
assertTrue(completed.await(3L, TimeUnit.SECONDS));
assertEquals(null, failure.get());
assertNotNull(result.get());
assertEquals(187, samples.get());
assertFalse(sampledOnEdt.get());
assertTrue(samplingThread.get().startsWith("Iris Noise Renderer"));
int completedSamples = samples.get();
Thread.sleep(150L);
assertEquals(completedSamples, samples.get());
} finally {
coordinator.close();
}
}
@Test
public void samplingTraversesEachBandInRowMajorOrder() throws Exception {
CountDownLatch completed = new CountDownLatch(1);
List<String> coordinates = new ArrayList<>();
AtomicReference<Throwable> failure = new AtomicReference<>();
NoiseRenderCoordinator coordinator = new NoiseRenderCoordinator(1, new NoiseRenderCoordinator.Listener() {
@Override
public void onRenderStarted(NoiseRenderCoordinator.Request request) {
}
@Override
public void onRenderCompleted(NoiseRenderCoordinator.Result result) {
completed.countDown();
}
@Override
public void onRenderFailed(NoiseRenderCoordinator.Request request, Throwable error) {
failure.set(error);
completed.countDown();
}
});
try {
NoiseProvider sampler = (x, z) -> {
coordinates.add(x + "," + z);
return 0.5D;
};
coordinator.request(new NoiseRenderCoordinator.Request(
1L,
sampler,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
6,
4,
2
));
assertTrue(completed.await(3L, TimeUnit.SECONDS));
assertEquals(null, failure.get());
assertEquals(List.of("-2.0,-1.0", "0.0,-1.0", "2.0,-1.0", "-2.0,1.0", "0.0,1.0", "2.0,1.0"), coordinates);
} finally {
coordinator.close();
}
}
@Test
public void newerRevisionDiscardsStaleResult() throws Exception {
CountDownLatch firstSample = new CountDownLatch(1);
CountDownLatch releaseFirst = new CountDownLatch(1);
CountDownLatch latestCompleted = new CountDownLatch(1);
List<Long> completedRevisions = new ArrayList<>();
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicInteger staleSamples = new AtomicInteger();
NoiseRenderCoordinator coordinator = new NoiseRenderCoordinator(1, new NoiseRenderCoordinator.Listener() {
@Override
public void onRenderStarted(NoiseRenderCoordinator.Request request) {
}
@Override
public void onRenderCompleted(NoiseRenderCoordinator.Result result) {
completedRevisions.add(result.request().revision());
if (result.request().revision() == 2L) {
latestCompleted.countDown();
}
}
@Override
public void onRenderFailed(NoiseRenderCoordinator.Request request, Throwable error) {
failure.set(error);
latestCompleted.countDown();
}
});
try {
AtomicBoolean block = new AtomicBoolean(true);
NoiseProvider slowSampler = (x, z) -> {
staleSamples.incrementAndGet();
if (block.compareAndSet(true, false)) {
firstSample.countDown();
while (releaseFirst.getCount() > 0L) {
Thread.onSpinWait();
}
}
return 0.25D;
};
NoiseRenderCoordinator.Request stale = new NoiseRenderCoordinator.Request(
1L,
slowSampler,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
512,
1,
1
);
NoiseRenderCoordinator.Request latest = new NoiseRenderCoordinator.Request(
2L,
(x, z) -> 0.75D,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
512,
1,
1
);
coordinator.request(stale);
assertTrue(firstSample.await(3L, TimeUnit.SECONDS));
coordinator.request(latest);
assertTrue(latestCompleted.await(3L, TimeUnit.SECONDS));
assertEquals(null, failure.get());
assertEquals(List.of(2L), completedRevisions);
assertTrue(staleSamples.get() <= 32);
} finally {
releaseFirst.countDown();
coordinator.close();
}
}
@Test
public void closeReturnsImmediatelyWhenSamplerIgnoresInterruption() throws Exception {
CountDownLatch sampleStarted = new CountDownLatch(1);
AtomicBoolean releaseSampler = new AtomicBoolean();
AtomicBoolean daemonWorker = new AtomicBoolean();
NoiseRenderCoordinator coordinator = new NoiseRenderCoordinator(1, new NoiseRenderCoordinator.Listener() {
@Override
public void onRenderStarted(NoiseRenderCoordinator.Request request) {
}
@Override
public void onRenderCompleted(NoiseRenderCoordinator.Result result) {
}
@Override
public void onRenderFailed(NoiseRenderCoordinator.Request request, Throwable error) {
}
});
try {
coordinator.request(new NoiseRenderCoordinator.Request(
1L,
(x, z) -> {
daemonWorker.set(Thread.currentThread().isDaemon());
sampleStarted.countDown();
while (!releaseSampler.get()) {
Thread.onSpinWait();
}
return 0.5D;
},
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
32,
32,
1
));
assertTrue(sampleStarted.await(1L, TimeUnit.SECONDS));
long started = System.nanoTime();
coordinator.close();
long closeMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started);
assertTrue(closeMillis < 200L);
assertTrue(daemonWorker.get());
} finally {
releaseSampler.set(true);
coordinator.close();
}
}
@Test
public void latestMultiBandViewCompletesAfterThreeInterruptIgnoringGenerations() throws Exception {
CountDownLatch latestCompleted = new CountDownLatch(1);
AtomicReference<Throwable> failure = new AtomicReference<>();
AtomicBoolean releaseStale = new AtomicBoolean();
NoiseRenderCoordinator coordinator = new NoiseRenderCoordinator(2, new NoiseRenderCoordinator.Listener() {
@Override
public void onRenderStarted(NoiseRenderCoordinator.Request request) {
}
@Override
public void onRenderCompleted(NoiseRenderCoordinator.Result result) {
if (result.request().revision() == 4L) {
latestCompleted.countDown();
}
}
@Override
public void onRenderFailed(NoiseRenderCoordinator.Request request, Throwable error) {
failure.set(error);
latestCompleted.countDown();
}
});
try {
for (long revision = 1L; revision <= 3L; revision++) {
CountDownLatch staleStarted = new CountDownLatch(2);
coordinator.request(new NoiseRenderCoordinator.Request(
revision,
(x, z) -> {
staleStarted.countDown();
while (!releaseStale.get()) {
Thread.onSpinWait();
}
return 0.25D;
},
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
8,
4,
1
));
assertTrue(staleStarted.await(1L, TimeUnit.SECONDS));
}
coordinator.request(new NoiseRenderCoordinator.Request(
4L,
(x, z) -> 0.75D,
new NoiseViewport(0D, 0D, 1D),
NoisePalette.TERRAIN,
8,
4,
1
));
assertTrue(latestCompleted.await(3L, TimeUnit.SECONDS));
assertEquals(null, failure.get());
} finally {
releaseStale.set(true);
coordinator.close();
}
}
}
@@ -1,31 +0,0 @@
package art.arcane.iris.core.gui;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public final class NoiseViewportTest {
@Test
public void zoomKeepsCursorWorldPositionFixed() {
NoiseViewport viewport = new NoiseViewport(120D, -35D, 2.5D);
double worldX = viewport.worldX(713D, 1200);
double worldZ = viewport.worldZ(147D, 700);
NoiseViewport zoomed = viewport.zoomAt(713D, 147D, 1200, 700, 0.4D);
assertEquals(worldX, zoomed.worldX(713D, 1200), 0.000000001D);
assertEquals(worldZ, zoomed.worldZ(147D, 700), 0.000000001D);
assertEquals(1D, zoomed.blocksPerPixel(), 0D);
}
@Test
public void panMovesCenterByPixelDeltaAtCurrentScale() {
NoiseViewport viewport = new NoiseViewport(10D, 20D, 2D);
NoiseViewport panned = viewport.panPixels(7D, -3D);
assertEquals(-4D, panned.centerX(), 0D);
assertEquals(26D, panned.centerZ(), 0D);
assertEquals(2D, panned.blocksPerPixel(), 0D);
}
}
@@ -1,263 +0,0 @@
package art.arcane.iris.core.gui;
import art.arcane.iris.engine.framework.render.IrisRenderer;
import art.arcane.iris.engine.framework.render.RenderType;
import org.junit.Test;
import java.awt.image.BufferedImage;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class VisionRenderControllerTest {
@Test
public void visibleTilesAreUniqueAndOrderedCenterFirst() {
VisionRenderController.RenderSpec spec = spec(RenderType.BIOME, 7L, 0D, 0D, 4D, 1440, 792);
List<VisionRenderController.VisibleTile> tiles = VisionRenderController.visibleTiles(spec);
assertEquals(336, tiles.size());
Set<String> coordinates = new HashSet<>();
double previousDistance = -1D;
for (VisionRenderController.VisibleTile tile : tiles) {
assertTrue(coordinates.add(tile.tileX() + ":" + tile.tileZ()));
assertTrue(tile.distanceSquared() >= previousDistance);
previousDistance = tile.distanceSquared();
}
assertEquals(1_376_256L, VisionRenderController.sampleCount(tiles.size()));
}
@Test
public void negativeWorldCoordinatesUseFloorBasedTileOwnership() {
VisionRenderController.RenderSpec spec = spec(RenderType.BIOME, 1L, -32D, -32D, 1D, 1, 1);
List<VisionRenderController.VisibleTile> tiles = VisionRenderController.visibleTiles(spec);
assertEquals(1, tiles.size());
assertEquals(-1L, tiles.get(0).tileX());
assertEquals(-1L, tiles.get(0).tileZ());
}
@Test
public void cacheIdentityContainsOnlyAtlasGenerationModeZoomAndWorldPage() {
VisionRenderController.TileKey baseline = new VisionRenderController.TileKey(4L, RenderType.BIOME, 4D, 8L, 9L);
assertNotEquals(baseline, new VisionRenderController.TileKey(5L, RenderType.BIOME, 4D, 8L, 9L));
assertNotEquals(baseline, new VisionRenderController.TileKey(4L, RenderType.HEIGHT, 4D, 8L, 9L));
assertNotEquals(baseline, new VisionRenderController.TileKey(4L, RenderType.BIOME, 4.5D, 8L, 9L));
assertNotEquals(baseline, new VisionRenderController.TileKey(4L, RenderType.BIOME, 4D, 7L, 9L));
}
@Test
public void everyPublishedPageIsFinalResolutionAndIdenticalRequestsAreCacheHits() throws Exception {
IrisRenderer renderer = mock(IrisRenderer.class);
AtomicInteger calls = new AtomicInteger();
when(renderer.renderStudio(
anyDouble(),
anyDouble(),
anyDouble(),
anyInt(),
any(RenderType.class),
any(BooleanSupplier.class)
)).thenAnswer(invocation -> {
assertEquals(VisionRenderController.TILE_PIXELS, (int) invocation.getArgument(3));
calls.incrementAndGet();
return new BufferedImage(
VisionRenderController.TILE_PIXELS,
VisionRenderController.TILE_PIXELS,
BufferedImage.TYPE_INT_RGB
);
});
VisionRenderController controller = controller(2);
VisionRenderController.RenderSpec spec = spec(renderer, RenderType.BIOME, 1L, 0D, 0D, 4D, 128, 128);
try {
VisionRenderController.Frame first = controller.request(spec);
assertTrue(await(() -> controller.progress(first).ready() == controller.progress(first).total(), 2_000L));
int rendered = calls.get();
VisionRenderController.Frame cached = controller.request(spec);
assertEquals(rendered, calls.get());
assertEquals(controller.progress(cached).total(), controller.progress(cached).ready());
for (VisionRenderController.VisibleTile tile : cached.tiles()) {
assertEquals(VisionRenderController.TILE_PIXELS, controller.image(cached, tile).getWidth());
assertEquals(VisionRenderController.TILE_PIXELS, controller.image(cached, tile).getHeight());
}
} finally {
controller.close();
}
}
@Test
public void smallPanReusesEveryOverlappingWorldPage() throws Exception {
IrisRenderer renderer = exactRenderer();
VisionRenderController controller = controller(2);
try {
VisionRenderController.Frame first = controller.request(spec(renderer, RenderType.BIOME, 1L, 16D, 16D, 4D, 128, 128));
assertTrue(await(() -> controller.progress(first).ready() == controller.progress(first).total(), 2_000L));
Set<VisionRenderController.TileKey> firstKeys = keys(first);
VisionRenderController.Frame panned = controller.request(spec(renderer, RenderType.BIOME, 1L, 20D, 20D, 4D, 128, 128));
assertEquals(firstKeys, keys(panned));
assertEquals(panned.tiles().size(), controller.progress(panned).ready());
for (VisionRenderController.VisibleTile pannedTile : panned.tiles()) {
VisionRenderController.VisibleTile original = tile(first, panned.key(pannedTile));
assertSame(controller.image(first, original), controller.image(panned, pannedTile));
}
} finally {
controller.close();
}
}
@Test
public void newerViewPublishesWithoutWaitingForCancelledQueuedWork() throws Exception {
IrisRenderer renderer = mock(IrisRenderer.class);
CountDownLatch staleStarted = new CountDownLatch(1);
CountDownLatch latestStarted = new CountDownLatch(1);
when(renderer.renderStudio(
anyDouble(),
anyDouble(),
anyDouble(),
anyInt(),
any(RenderType.class),
any(BooleanSupplier.class)
)).thenAnswer(invocation -> {
RenderType type = invocation.getArgument(4);
BooleanSupplier cancelled = invocation.getArgument(5);
if (type == RenderType.REGION) {
staleStarted.countDown();
while (!cancelled.getAsBoolean()) {
Thread.onSpinWait();
}
throw new java.util.concurrent.CancellationException();
}
latestStarted.countDown();
return new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
});
VisionRenderController controller = controller(2);
try {
controller.request(spec(renderer, RenderType.REGION, 1L, 0D, 0D, 4D, 64, 64));
assertTrue(staleStarted.await(1L, TimeUnit.SECONDS));
controller.request(spec(renderer, RenderType.BIOME, 1L, 0D, 0D, 4D, 64, 64));
assertTrue(latestStarted.await(1L, TimeUnit.SECONDS));
} finally {
controller.close();
}
}
private static VisionRenderController controller(int workers) {
return new VisionRenderController(
() -> {
},
new VisionRenderController.RuntimeOptions(workers, 8, false)
);
}
private static IrisRenderer exactRenderer() {
IrisRenderer renderer = mock(IrisRenderer.class);
when(renderer.renderStudio(
anyDouble(),
anyDouble(),
anyDouble(),
anyInt(),
any(RenderType.class),
any(BooleanSupplier.class)
)).thenAnswer(invocation -> new BufferedImage(
invocation.getArgument(3),
invocation.getArgument(3),
BufferedImage.TYPE_INT_RGB
));
return renderer;
}
private static Set<VisionRenderController.TileKey> keys(VisionRenderController.Frame frame) {
Set<VisionRenderController.TileKey> keys = new HashSet<>();
for (VisionRenderController.VisibleTile tile : frame.tiles()) {
keys.add(frame.key(tile));
}
return keys;
}
private static VisionRenderController.VisibleTile tile(
VisionRenderController.Frame frame,
VisionRenderController.TileKey key
) {
for (VisionRenderController.VisibleTile tile : frame.tiles()) {
if (frame.key(tile).equals(key)) {
return tile;
}
}
throw new AssertionError("Missing tile " + key);
}
private static VisionRenderController.RenderSpec spec(
RenderType type,
long revision,
double centerX,
double centerZ,
double blocksPerPixel,
int width,
int height
) {
return new VisionRenderController.RenderSpec(
mock(IrisRenderer.class),
type,
revision,
centerX,
centerZ,
blocksPerPixel,
width,
height
);
}
private static VisionRenderController.RenderSpec spec(
IrisRenderer renderer,
RenderType type,
long revision,
double centerX,
double centerZ,
double blocksPerPixel,
int width,
int height
) {
return new VisionRenderController.RenderSpec(
renderer,
type,
revision,
centerX,
centerZ,
blocksPerPixel,
width,
height
);
}
private static boolean await(BooleanSupplier condition, long timeoutMillis) throws InterruptedException {
long deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
while (System.nanoTime() < deadline) {
if (condition.getAsBoolean()) {
return true;
}
Thread.sleep(5L);
}
return condition.getAsBoolean();
}
}
@@ -1,32 +0,0 @@
package art.arcane.iris.core.gui;
import art.arcane.iris.core.localization.IrisMessages;
import art.arcane.iris.engine.framework.render.RenderType;
import art.arcane.volmlib.util.localization.MessageKey;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
public class VisionRenderTypeTest {
@Test
public void everyRenderTypeHasALocalizedVisionLabel() {
for (RenderType type : RenderType.values()) {
MessageKey key = VisionGUI.modeKey(type);
assertNotNull(type.name(), key);
assertTrueCatalogMember(key);
}
}
@Test
public void teleportCoordinatesFloorAcrossTheNegativeOrigin() {
assertEquals(-1, VisionGUI.floorWorldCoordinate(-0.01D));
assertEquals(0, VisionGUI.floorWorldCoordinate(0.99D));
assertEquals(1, VisionGUI.floorWorldCoordinate(1D));
}
private static void assertTrueCatalogMember(MessageKey key) {
assertSame(key.id(), key, IrisMessages.catalog().key(key.id()));
}
}
@@ -1,33 +0,0 @@
package art.arcane.iris.core.gui;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public final class VisionViewportTest {
@Test
public void granularZoomKeepsTheCursorWorldCoordinateFixed() {
VisionViewport viewport = new VisionViewport(-21_672D, -10_148D, 256D);
double cursorWorldX = viewport.worldX(1_194D, 1_440);
double cursorWorldZ = viewport.worldZ(283D, 792);
VisionViewport zoomed = viewport.zoomAt(1_194D, 283D, 1_440, 792, Math.pow(2D, -0.08D), 1D, 4_096D);
assertEquals(cursorWorldX, zoomed.worldX(1_194D, 1_440), 0.000000001D);
assertEquals(cursorWorldZ, zoomed.worldZ(283D, 792), 0.000000001D);
assertEquals(242.19075756175255D, zoomed.blocksPerPixel(), 0.000000001D);
}
@Test
public void zoomClampingStillKeepsTheCursorAnchored() {
VisionViewport viewport = new VisionViewport(800D, -400D, 2D);
double cursorWorldX = viewport.worldX(925D, 1_200);
double cursorWorldZ = viewport.worldZ(127D, 700);
VisionViewport zoomed = viewport.zoomAt(925D, 127D, 1_200, 700, 0.001D, 1D, 4_096D);
assertEquals(1D, zoomed.blocksPerPixel(), 0D);
assertEquals(cursorWorldX, zoomed.worldX(925D, 1_200), 0.000000001D);
assertEquals(cursorWorldZ, zoomed.worldZ(127D, 700), 0.000000001D);
}
}