Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Nov 11, 2024
2 parents d7279ce + 58df023 commit 3c34e60
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/1.19.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
&& wget https://api.modrinth.com/maven/maven/modrinth/xaeros-world-map/${{ env.WORLDMAP_VERSION_FABRIC }}_Fabric_${{ env.MINECRAFT_VERSION }}/xaeros-world-map-${{ env.WORLDMAP_VERSION_FABRIC }}_Fabric_${{ env.MINECRAFT_VERSION }}.jar -P run/mods/
- name: Fabric Test
uses: 3arthqu4ke/[email protected].0
uses: 3arthqu4ke/[email protected].1
with:
mc: ${{ env.MINECRAFT_VERSION }}
modloader: fabric
Expand All @@ -100,7 +100,7 @@ jobs:
&& wget https://api.modrinth.com/maven/maven/modrinth/xaeros-world-map/${{ env.WORLDMAP_VERSION_FORGE }}_Forge_${{ env.MINECRAFT_VERSION }}/xaeros-world-map-${{ env.WORLDMAP_VERSION_FORGE }}_Forge_${{ env.MINECRAFT_VERSION }}.jar -P run/mods/
- name: Forge Test
uses: 3arthqu4ke/[email protected].0
uses: 3arthqu4ke/[email protected].1
with:
mc: ${{ env.MINECRAFT_VERSION }}
modloader: forge
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -66,19 +67,23 @@ private void writeHighlightsOutsideWindowToDatabase() {
final List<ChunkHighlightData> 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) {
Expand All @@ -93,12 +98,13 @@ public ListenableFuture<?> writeAllHighlightsToDatabase() {
final List<ChunkHighlightData> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,14 +28,16 @@ private void limitChunksSize() {
if (chunks.size() > maxNumber) {
if (lock.readLock().tryLock(1, TimeUnit.SECONDS)) {
// remove oldest 500 chunks
final List<Long> 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();
}
}
Expand Down

0 comments on commit 3c34e60

Please sign in to comment.