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

@@ -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) {
@@ -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 <https://www.gnu.org/licenses/>.
*/
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));
}
}
}