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
This commit is contained in:
piexel committed 2026-11-10 13:02:17 +01:00
1 parent 80ecd143da
commit e2ebc7fe8a
7 files changed
+115 -17

No files matched your search

@@ -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)
})
})
@@ -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
}
}
+3 -2
View File
@@ -65,6 +65,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
const [area, setArea] = useState<WorldRect | null>(null)
const [packRevision, setPackRevision] = useState(0)
const [sceneSummary, setSceneSummary] = useState<string | null>(null)
const [sceneProgress, setSceneProgress] = useState<number | null>(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 ? (
<WorldStudio3D client={client} world={world} mapArea={area} packRevision={packRevision} onSummary={setSceneSummary} tell={tell} />
) : viewId === SAVED_WORLD.id ? (
<SavedWorldStudio client={client} world={world} onSummary={setSceneSummary} tell={tell} />
<SavedWorldStudio client={client} world={world} onSummary={setSceneSummary} onProgress={setSceneProgress} tell={tell} />
) : viewId === NOISE.id ? (
<NoiseStudio client={client} packRevision={packRevision} onSummary={setSceneSummary} tell={tell} />
) : (
@@ -290,7 +291,7 @@ export function MapStudio({ client, world, theme, onDisconnect }: MapStudioProps
</>
)}
</div>
<StatusBar viewLabel={statusLabel(view.label, previewName, showsMap ? null : sceneSummary)} status={showsMap ? status : null} notice={notice} usage={usage} />
<StatusBar viewLabel={statusLabel(view.label, previewName, showsMap ? null : sceneSummary)} status={showsMap ? status : null} notice={notice} usage={usage} progress={showsMap ? null : sceneProgress} />
<HelpDialog open={helpOpen} onOpenChange={setHelpOpen} views={views} />
<ShortcutSettings open={settingsOpen} onOpenChange={setSettingsOpen} views={views} />
</div>
@@ -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<string | null>(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) {
+14 -7
View File
@@ -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 (
<footer className="flex h-6 shrink-0 items-center gap-6 border-t bg-card px-3 text-[11.5px] text-secondary-text tabular-nums">
@@ -31,12 +33,9 @@ export function StatusBar({ viewLabel, status, notice, usage }: StatusBarProps):
)}
</span>
<span className="flex min-w-0 flex-1 items-center justify-center gap-2 truncate">
{notice ?? (drawing ? `Drawing ${status.tilesReady} of ${status.tilesTotal} tiles` : '')}
{notice === null && drawing && (
<span className="h-1 w-24 overflow-hidden rounded-full bg-secondary">
<span className="block h-full bg-primary" style={{ width: `${(status.tilesReady / status.tilesTotal) * 100}%` }} />
</span>
)}
{notice ?? (drawing ? `Drawing ${status.tilesReady} of ${status.tilesTotal} tiles` : progress !== null ? 'Reading' : '')}
{notice === null && drawing && <ProgressBar fraction={status.tilesReady / status.tilesTotal} />}
{notice === null && !drawing && progress !== null && <ProgressBar fraction={progress} />}
</span>
{usage !== null && <UsageReadout usage={usage} />}
{status !== null && (
@@ -49,6 +48,14 @@ export function StatusBar({ viewLabel, status, notice, usage }: StatusBarProps):
)
}
function ProgressBar({ fraction }: { fraction: number }): React.JSX.Element {
return (
<span className="h-1 w-24 overflow-hidden rounded-full bg-secondary">
<span className="block h-full bg-primary" style={{ width: `${fraction * 100}%` }} />
</span>
)
}
/** The server's CPU, 100% per busy thread, and Java heap; each turns warning-coloured at 80%. */
function UsageReadout({ usage }: { usage: ServerUsage }): React.JSX.Element {
return (