From ead09482b16a8ddba1d933f348dacf202b7d6f28 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:15:31 -0800 Subject: [PATCH 1/2] minor cleanup --- .../ChunkHighlightCacheDimensionHandler.java | 28 +++++++++++-------- .../highlights/ChunkHighlightDatabase.java | 3 +- .../highlights/ChunkHighlightLocalCache.java | 17 +++++------ 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightCacheDimensionHandler.java b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightCacheDimensionHandler.java index b94178ac..c07e2cff 100644 --- a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightCacheDimensionHandler.java +++ b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightCacheDimensionHandler.java @@ -50,7 +50,8 @@ private void loadHighlightsInWindow() { ); try { if (lock.writeLock().tryLock(1, TimeUnit.SECONDS)) { - for (final ChunkHighlightData chunk : chunks) { + for (int i = 0; i < chunks.size(); i++) { + final ChunkHighlightData chunk = chunks.get(i); this.chunks.put(chunkPosToLong(chunk.x(), chunk.z()), chunk.foundTime()); } lock.writeLock().unlock(); @@ -66,19 +67,23 @@ private void writeHighlightsOutsideWindowToDatabase() { final List chunksToWrite = new ArrayList<>(); try { if (lock.writeLock().tryLock(1L, TimeUnit.SECONDS)) { - chunks.long2LongEntrySet().removeIf(entry -> { + var minChunkX = regionCoordToChunkCoord(windowRegionX - windowRegionSize); + var maxChunkX = regionCoordToChunkCoord(windowRegionX + windowRegionSize); + var minChunkZ = regionCoordToChunkCoord(windowRegionZ - windowRegionSize); + var maxChunkZ = regionCoordToChunkCoord(windowRegionZ + windowRegionSize); + for (var it = chunks.long2LongEntrySet().iterator(); it.hasNext(); ) { + var entry = it.next(); final long chunkPos = entry.getLongKey(); final int chunkX = ChunkUtils.longToChunkX(chunkPos); final int chunkZ = ChunkUtils.longToChunkZ(chunkPos); - if (chunkX < regionCoordToChunkCoord(windowRegionX - windowRegionSize) - || chunkX > regionCoordToChunkCoord(windowRegionX + windowRegionSize) - || chunkZ < regionCoordToChunkCoord(windowRegionZ - windowRegionSize) - || chunkZ > regionCoordToChunkCoord(windowRegionZ + windowRegionSize)) { + if (chunkX < minChunkX + || chunkX > maxChunkX + || chunkZ < minChunkZ + || chunkZ > maxChunkZ) { chunksToWrite.add(new ChunkHighlightData(chunkX, chunkZ, entry.getLongValue())); - return true; + it.remove(); } - return false; - }); + } lock.writeLock().unlock(); } } catch (final Exception e) { @@ -93,12 +98,13 @@ public ListenableFuture writeAllHighlightsToDatabase() { final List chunksToWrite = new ArrayList<>(chunks.size()); try { if (lock.readLock().tryLock(1, TimeUnit.SECONDS)) { - chunks.long2LongEntrySet().forEach(entry -> { + for (var it = chunks.long2LongEntrySet().iterator(); it.hasNext(); ) { + var entry = it.next(); final long chunkPos = entry.getLongKey(); final int chunkX = ChunkUtils.longToChunkX(chunkPos); final int chunkZ = ChunkUtils.longToChunkZ(chunkPos); chunksToWrite.add(new ChunkHighlightData(chunkX, chunkZ, entry.getLongValue())); - }); + } lock.readLock().unlock(); } } catch (final Exception e) { diff --git a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java index 72fb1837..ceecea8a 100644 --- a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java +++ b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightDatabase.java @@ -3,7 +3,6 @@ import com.google.common.collect.Lists; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.Level; -import org.rfresh.sqlite.JDBC; import xaero.map.WorldMap; import xaeroplus.XaeroPlus; import xaeroplus.feature.render.highlights.db.DatabaseMigrator; @@ -31,7 +30,7 @@ public ChunkHighlightDatabase(String worldId, String databaseName) { try { // workaround for other mods that might have forced the JDBC drivers to be init // before we are on the classpath - var jdbcClass = JDBC.class; + var jdbcClass = org.rfresh.sqlite.JDBC.class; final Path dbPath = WorldMap.saveFolder.toPath().resolve(worldId).resolve(databaseName + ".db"); boolean shouldRunMigrations = dbPath.toFile().exists(); diff --git a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightLocalCache.java b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightLocalCache.java index 7d1caf91..4ee2d362 100644 --- a/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightLocalCache.java +++ b/common/src/main/java/xaeroplus/feature/render/highlights/ChunkHighlightLocalCache.java @@ -1,11 +1,10 @@ package xaeroplus.feature.render.highlights; +import it.unimi.dsi.fastutil.longs.Long2LongMap; import xaeroplus.XaeroPlus; -import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; public class ChunkHighlightLocalCache extends ChunkHighlightBaseCacheHandler { private static final int maxNumber = 5000; @@ -29,14 +28,16 @@ private void limitChunksSize() { if (chunks.size() > maxNumber) { if (lock.readLock().tryLock(1, TimeUnit.SECONDS)) { // remove oldest 500 chunks - final List toRemove = chunks.long2LongEntrySet().stream() - .sorted(Map.Entry.comparingByValue()) - .limit(500) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); + var toRemove = chunks.long2LongEntrySet().stream() + .sorted(Map.Entry.comparingByValue()) + .limit(500) + .mapToLong(Long2LongMap.Entry::getLongKey) + .toArray(); lock.readLock().unlock(); if (lock.writeLock().tryLock(1, TimeUnit.SECONDS)) { - toRemove.forEach(l -> chunks.remove((long) l)); + for (int i = 0; i < toRemove.length; i++) { + chunks.remove(toRemove[i]); + } lock.writeLock().unlock(); } } From 58df0238541b9266d0964c9b7e46c5182b0dff65 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:34:44 -0800 Subject: [PATCH 2/2] update deps --- .github/workflows/1.20.1.yml | 4 ++-- buildSrc/build.gradle.kts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/1.20.1.yml b/.github/workflows/1.20.1.yml index e56035fb..5a8cd247 100644 --- a/.github/workflows/1.20.1.yml +++ b/.github/workflows/1.20.1.yml @@ -79,7 +79,7 @@ jobs: && wget https://api.modrinth.com/maven/maven/modrinth/xaeros-world-map/${{ env.WORLDMAP_VERSION_FABRIC }}_Fabric_1.20/xaeros-world-map-${{ env.WORLDMAP_VERSION_FABRIC }}_Fabric_1.20.jar -P run/mods/ - name: Fabric Test - uses: 3arthqu4ke/mc-runtime-test@2.4.0 + uses: 3arthqu4ke/mc-runtime-test@2.4.1 with: mc: ${{ env.MINECRAFT_VERSION }} modloader: fabric @@ -100,7 +100,7 @@ jobs: && wget https://api.modrinth.com/maven/maven/modrinth/xaeros-world-map/${{ env.WORLDMAP_VERSION_FORGE }}_Forge_1.20/xaeros-world-map-${{ env.WORLDMAP_VERSION_FORGE }}_Forge_1.20.jar -P run/mods/ - name: Forge Test - uses: 3arthqu4ke/mc-runtime-test@2.4.0 + uses: 3arthqu4ke/mc-runtime-test@2.4.1 with: mc: ${{ env.MINECRAFT_VERSION }} modloader: forge diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6e42c039..ce2db947 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -13,6 +13,6 @@ repositories { dependencies { implementation("architectury-plugin:architectury-plugin.gradle.plugin:3.4-SNAPSHOT") implementation("dev.architectury:architectury-loom:1.7-SNAPSHOT") - implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.3") + implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.5") }