From e2ebc7fe8a7848474d2d33678713b9422f0758a3 Mon Sep 17 00:00:00 2001 From: piexel Date: Tue, 10 Nov 2026 13:02:17 +0100 Subject: [PATCH] Show reading progress for saved worlds and read a region's chunks in parallel The saved-world view only said "Reading" with no sense of how far along it was, and the first look at a region read its 1024 chunks one after another. The status bar now shows a bar measured against the most tiles pending since the last idle, and the region's start read uses all cores. v3: 3b899b8d1 --- .../iris/core/studio/saved/SavedRegion.java | 10 ++-- .../core/studio/saved/SavedRegionTest.java | 46 +++++++++++++++++++ .../renderer/src/scene/pendingWork.test.ts | 19 ++++++++ studio/src/renderer/src/scene/pendingWork.ts | 17 +++++++ studio/src/renderer/src/studio/MapStudio.tsx | 5 +- .../renderer/src/studio/SavedWorldStudio.tsx | 14 +++++- studio/src/renderer/src/studio/StatusBar.tsx | 21 ++++++--- 7 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 core/src/test/java/art/arcane/iris/core/studio/saved/SavedRegionTest.java create mode 100644 studio/src/renderer/src/scene/pendingWork.test.ts create mode 100644 studio/src/renderer/src/scene/pendingWork.ts diff --git a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java index a85b79941..de096c236 100644 --- a/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java +++ b/core/src/main/java/art/arcane/iris/core/studio/saved/SavedRegion.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicIntegerArray; +import java.util.stream.IntStream; /** * What the view needs of one region file, 512 by 512 columns: the ground's top block under any water, its block and @@ -95,13 +96,10 @@ final class SavedRegion { return new SavedColumn(groundY[index], waterSurfaceY[index], blocks.get(blockIds[index]), biomes.get(biomeIds[index])); } - /** Reads every chunk not read yet, for what is measured over the whole region. */ + /** Reads every chunk not read yet, on all cores, for what is measured over the whole region. */ void readAll() { - for (int chunkZ = 0; chunkZ < RegionFile.CHUNKS_ACROSS; chunkZ++) { - for (int chunkX = 0; chunkX < RegionFile.CHUNKS_ACROSS; chunkX++) { - readChunk(chunkX, chunkZ); - } - } + IntStream.range(0, CHUNK_COUNT).parallel() + .forEach(chunk -> readChunk(chunk % RegionFile.CHUNKS_ACROSS, chunk / RegionFile.CHUNKS_ACROSS)); } private void readChunk(int chunkX, int chunkZ) { diff --git a/core/src/test/java/art/arcane/iris/core/studio/saved/SavedRegionTest.java b/core/src/test/java/art/arcane/iris/core/studio/saved/SavedRegionTest.java new file mode 100644 index 000000000..67c078447 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/core/studio/saved/SavedRegionTest.java @@ -0,0 +1,46 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 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.core.studio.saved; + +import org.junit.Test; + +import java.util.Optional; +import java.util.concurrent.atomic.AtomicIntegerArray; + +import static org.junit.Assert.assertEquals; + +public class SavedRegionTest { + private static final int CHUNK_COUNT = RegionFile.CHUNKS_ACROSS * RegionFile.CHUNKS_ACROSS; + + @Test + public void readingAllReadsEveryChunkOnceEvenWhenAskedTwice() { + AtomicIntegerArray reads = new AtomicIntegerArray(CHUNK_COUNT); + SavedRegion region = new SavedRegion((chunkX, chunkZ) -> { + reads.incrementAndGet(chunkZ * RegionFile.CHUNKS_ACROSS + chunkX); + return Optional.empty(); + }, block -> true); + + region.readAll(); + region.readAll(); + + for (int chunk = 0; chunk < CHUNK_COUNT; chunk++) { + assertEquals("chunk " + chunk, 1, reads.get(chunk)); + } + } +} diff --git a/studio/src/renderer/src/scene/pendingWork.test.ts b/studio/src/renderer/src/scene/pendingWork.test.ts new file mode 100644 index 000000000..66f5061da --- /dev/null +++ b/studio/src/renderer/src/scene/pendingWork.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from 'vitest' +import { PendingWork } from './pendingWork' + +describe('PendingWork', () => { + it('measures against the most pending since last done', () => { + const work = new PendingWork() + expect(work.completion(200)).toBeCloseTo(0) + expect(work.completion(50)).toBeCloseTo(0.75) + expect(work.completion(0)).toBe(1) + }) + + it('starts over after the work is done', () => { + const work = new PendingWork() + work.completion(200) + work.completion(0) + expect(work.completion(10)).toBeCloseTo(0) + expect(work.completion(5)).toBeCloseTo(0.5) + }) +}) diff --git a/studio/src/renderer/src/scene/pendingWork.ts b/studio/src/renderer/src/scene/pendingWork.ts new file mode 100644 index 000000000..d405659cf --- /dev/null +++ b/studio/src/renderer/src/scene/pendingWork.ts @@ -0,0 +1,17 @@ +/** + * How far along work is when only what is still left is known: measured against the most that was left at once since + * the work was last done. + */ +export class PendingWork { + private mostPending = 0 + + /** @return 0 to 1, where 1 means nothing is left */ + completion(pending: number): number { + if (pending <= 0) { + this.mostPending = 0 + return 1 + } + this.mostPending = Math.max(this.mostPending, pending) + return 1 - pending / this.mostPending + } +} diff --git a/studio/src/renderer/src/studio/MapStudio.tsx b/studio/src/renderer/src/studio/MapStudio.tsx index adb74298d..99e3f6817 100644 --- a/studio/src/renderer/src/studio/MapStudio.tsx +++ b/studio/src/renderer/src/studio/MapStudio.tsx @@ -65,6 +65,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps const [area, setArea] = useState(null) const [packRevision, setPackRevision] = useState(0) const [sceneSummary, setSceneSummary] = useState(null) + const [sceneProgress, setSceneProgress] = useState(null) const loadSceneViews = useCallback(() => client.sceneViews(), [client]) const loadPatternViews = useCallback(() => client.patternViews(), [client]) const sceneViews = useModuleViews(loadSceneViews, packRevision) @@ -235,7 +236,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps ) : viewId === WORLD_3D.id ? ( ) : viewId === SAVED_WORLD.id ? ( - + ) : viewId === NOISE.id ? ( ) : ( @@ -290,7 +291,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps )} - + diff --git a/studio/src/renderer/src/studio/SavedWorldStudio.tsx b/studio/src/renderer/src/studio/SavedWorldStudio.tsx index 137f8ba7c..4c950e936 100644 --- a/studio/src/renderer/src/studio/SavedWorldStudio.tsx +++ b/studio/src/renderer/src/studio/SavedWorldStudio.tsx @@ -1,5 +1,5 @@ import { RotateCw } from 'lucide-react' -import { useEffect, useMemo, useState } from 'react' +import { useEffect, useMemo, useRef, useState } from 'react' import { Button } from '@/components/ui/button' import { ScrollArea } from '@/components/ui/scroll-area' import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group' @@ -10,6 +10,7 @@ import { BlockColors } from '../scene/blockColors' import { BlockLooks } from '../scene/blockLooks' import { BlockModels } from '../scene/blockModels' import { BridgeAssets } from '../scene/BridgeAssets' +import { PendingWork } from '../scene/pendingWork' import { SavedTerrain, type ReadSavedTile, type SavedTerrainColoring } from '../scene/savedTerrain' import { savedTileSource, type SavedLayer } from '../scene/savedTileSource' import { TerrainAtlas } from '../scene/terrainAtlas' @@ -28,11 +29,13 @@ interface SavedWorldStudioProps { /** The studio's own world, whose saved copy is chosen first. */ world: WorldInfo onSummary(summary: string | null): void + /** How far the tiles being read have come, 0 to 1, or null when none are. */ + onProgress(progress: number | null): void tell(message: string): void } /** A world as its region files hold it, in 3D, around the region nearest its origin (v3e's saved world explorer). */ -export function SavedWorldStudio({ client, world, onSummary, tell }: SavedWorldStudioProps): React.JSX.Element { +export function SavedWorldStudio({ client, world, onSummary, onProgress, tell }: SavedWorldStudioProps): React.JSX.Element { const worlds = useSavedWorlds(client, tell) const [chosenId, setChosenId] = useState(null) const chosen = worlds.find((candidate) => candidate.id === chosenId) ?? ownWorldAmong(worlds, world) ?? worlds[0] ?? null @@ -63,6 +66,13 @@ export function SavedWorldStudio({ client, world, onSummary, tell }: SavedWorldS ) const { content, pending } = useTerrainStream(tileSource, COARSEST_SAVED_LEVEL, focus, layer, style, tell) const reading = looking || pending > 0 + const tileWork = useRef(new PendingWork()) + + useEffect(() => { + const completion = tileWork.current.completion(pending) + onProgress(pending > 0 ? completion : null) + }, [pending, onProgress]) + useEffect(() => () => onProgress(null), [onProgress]) useEffect(() => { if (chosen === null || start === null) { diff --git a/studio/src/renderer/src/studio/StatusBar.tsx b/studio/src/renderer/src/studio/StatusBar.tsx index 6a63992cd..1a6fc0b7b 100644 --- a/studio/src/renderer/src/studio/StatusBar.tsx +++ b/studio/src/renderer/src/studio/StatusBar.tsx @@ -10,12 +10,14 @@ interface StatusBarProps { status: MapStatus | null notice: string | null usage: ServerUsage | null + /** How far a scene view's reading has come, 0 to 1, or null when it is not reading. */ + progress: number | null } const NUMBER = new Intl.NumberFormat('en-US') /** What the map shows, what it is busy with, and where the cursor is (v3e StudioStatusBar). */ -export function StatusBar({ viewLabel, status, notice, usage }: StatusBarProps): React.JSX.Element { +export function StatusBar({ viewLabel, status, notice, usage, progress }: StatusBarProps): React.JSX.Element { const drawing = status !== null && status.tilesReady < status.tilesTotal return (