ChunkGrid improvements

This commit is contained in:
Lukas Rieger (Blue) 2025-01-19 22:36:50 +01:00
parent 05e12c5a74
commit d1a36e5816
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6
2 changed files with 17 additions and 12 deletions

View File

@ -5,6 +5,7 @@
import com.github.benmanes.caffeine.cache.LoadingCache;
import de.bluecolored.bluemap.core.BlueMap;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.util.Grid;
import de.bluecolored.bluemap.core.util.Vector2iCache;
import de.bluecolored.bluemap.core.util.WatchService;
import de.bluecolored.bluemap.core.world.ChunkConsumer;
@ -25,6 +26,9 @@
@RequiredArgsConstructor
public class ChunkGrid<T> {
private static final Grid CHUNK_GRID = new Grid(16);
private static final Grid REGION_GRID = new Grid(32).multiply(CHUNK_GRID);
private static final Vector2iCache VECTOR_2_I_CACHE = new Vector2iCache();
private final ChunkLoader<T> chunkLoader;
@ -45,6 +49,14 @@ public class ChunkGrid<T> {
.expireAfterAccess(1, TimeUnit.MINUTES)
.build(this::loadChunk);
public Grid getChunkGrid() {
return CHUNK_GRID;
}
public Grid getRegionGrid() {
return REGION_GRID;
}
public T getChunk(int x, int z) {
return getChunk(VECTOR_2_I_CACHE.get(x, z));
}
@ -61,10 +73,6 @@ private Region<T> getRegion(Vector2i pos) {
return regionCache.get(pos);
}
public void iterateChunks(int minX, int minZ, int maxX, int maxZ, ChunkConsumer<T> chunkConsumer) {
}
public void preloadRegionChunks(int x, int z, Predicate<Vector2i> chunkFilter) {
try {
getRegion(x, z).iterateAllChunks(new ChunkConsumer<>() {
@ -81,7 +89,7 @@ public void accept(int chunkX, int chunkZ, T chunk) {
}
});
} catch (IOException ex) {
Logger.global.logDebug("Unexpected exception trying to load preload region (x:" + x + ", z:" + z + "): " + ex);
Logger.global.logDebug("Unexpected exception trying to load preload region ('%s' -> x:%d, z:%d): %s".formatted(regionFolder, x, z, ex));
}
}
@ -101,7 +109,7 @@ public Collection<Vector2i> listRegions() {
.filter(Objects::nonNull)
.toList();
} catch (IOException ex) {
Logger.global.logError("Failed to list regions for folder: '" + regionFolder + "'", ex);
Logger.global.logError("Failed to list regions from: '%s'".formatted(regionFolder), ex);
return List.of();
}
}
@ -158,7 +166,7 @@ private T loadChunk(int x, int z) {
}
}
Logger.global.logDebug("Unexpected exception trying to load chunk (x:" + x + ", z:" + z + "): " + loadException);
Logger.global.logDebug("Unexpected exception trying to load chunk ('%s' -> x:%d, z:%d): %s".formatted(regionFolder, x, z, loadException));
return chunkLoader.erroredChunk();
}

View File

@ -63,9 +63,6 @@
@ToString
public class MCAWorld implements World {
private static final Grid CHUNK_GRID = new Grid(16);
private static final Grid REGION_GRID = new Grid(32).multiply(CHUNK_GRID);
private final String id;
private final Path worldFolder;
private final Key dimension;
@ -116,12 +113,12 @@ public String getName() {
@Override
public Grid getChunkGrid() {
return CHUNK_GRID;
return blockChunkGrid.getChunkGrid();
}
@Override
public Grid getRegionGrid() {
return REGION_GRID;
return blockChunkGrid.getRegionGrid();
}
@Override