mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Count pregen chunks from the bounds instead of walking them
Totalling by iterating every chunk delays the start of a large pregen. The bounds already give the count in constant time.
Upstream: 73d640943
This commit is contained in:
1 parent
19129c2eb8
commit
f78600be70
3 files changed
+52
-1
No files matched your search
@@ -207,7 +207,7 @@ public class IrisPregenerator {
|
||||
// fires — leaving a phantom job that suppresses spawns and blocks future pregens.
|
||||
try {
|
||||
init();
|
||||
task.iterateAllChunks((_a, _b) -> totalChunks.incrementAndGet());
|
||||
totalChunks.set(task.chunkCount());
|
||||
long startedAt = M.ms();
|
||||
startTime.set(startedAt);
|
||||
rateTracker.reset(startedAt, generated.get());
|
||||
|
||||
@@ -174,6 +174,11 @@ public class PregenTask {
|
||||
return new int[]{bound.minX(), bound.minZ(), bound.maxX(), bound.maxZ()};
|
||||
}
|
||||
|
||||
public long chunkCount() {
|
||||
Bound bound = bounds.chunk();
|
||||
return (long) bound.sizeX() * bound.sizeZ();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface InterleavedChunkConsumer {
|
||||
boolean on(int regionX, int regionZ, int chunkX, int chunkZ, boolean firstChunkInRegion, boolean lastChunkInRegion);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package art.arcane.iris.core.pregenerator;
|
||||
|
||||
import art.arcane.volmlib.util.math.Position2;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PregenTaskChunkCountTest {
|
||||
@Test
|
||||
public void countMatchesTraversalAcrossChunkAndRegionBoundaries() {
|
||||
int[][] areas = {
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 16, 32},
|
||||
{17, -17, 15, 33},
|
||||
{-16, -32, 16, 16},
|
||||
{-513, 511, 32, 17},
|
||||
{512, -512, 512, 256},
|
||||
{PregenTask.MAX_WORLD_BLOCK - 32, 0, 32, 1},
|
||||
{0, -PregenTask.MAX_WORLD_BLOCK + 32, 1, 32}
|
||||
};
|
||||
for (int[] area : areas) {
|
||||
PregenTask task = PregenTask.builder()
|
||||
.center(new Position2(area[0], area[1]))
|
||||
.radiusX(area[2])
|
||||
.radiusZ(area[3])
|
||||
.build();
|
||||
AtomicLong visited = new AtomicLong();
|
||||
|
||||
task.iterateAllChunks((x, z) -> visited.incrementAndGet());
|
||||
|
||||
assertEquals("center=" + area[0] + "," + area[1], visited.get(), task.chunkCount());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 2_000L)
|
||||
public void entireWorldCountUsesLongArithmeticWithoutTraversal() {
|
||||
PregenTask task = PregenTask.builder()
|
||||
.radiusX(PregenTask.MAX_WORLD_BLOCK)
|
||||
.radiusZ(PregenTask.MAX_WORLD_BLOCK)
|
||||
.build();
|
||||
|
||||
assertEquals(14_062_492_500_001L, task.chunkCount());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user