Skip to content

Commit

Permalink
Remove lazy chunk loading
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Jan 8, 2023
1 parent 289101f commit 1b667db
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 121 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/embeddedt/archaicfix/asm/Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public enum Mixin implements IMixin {
common_core_MixinChunkProviderHell(Side.COMMON, always(), "core.MixinChunkProviderHell"),
common_core_MixinASMData(Side.COMMON, always(), "core.MixinASMData"),
common_core_MixinModCandidate(Side.COMMON, avoid(TargetedMod.COFHCORE), "core.MixinModCandidate"),
common_core_MixinChunkIOExecutor(Side.COMMON, avoid(TargetedMod.COFHCORE), "core.MixinChunkIOExecutor"),
common_core_MixinNetworkDispatcher(Side.COMMON, m -> ArchaicConfig.fixLoginRaceCondition, "core.MixinNetworkDispatcher"),
common_core_MixinNetworkManager(Side.COMMON, m -> ArchaicConfig.fixLoginRaceCondition, "core.MixinNetworkManager"),
common_core_MixinEmbeddedChannel(Side.COMMON, m -> ArchaicConfig.fixLoginRaceCondition, "core.MixinEmbeddedChannel"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ public class ArchaicConfig {
@Config.DefaultStringList({ "Wither", "EnderDragon" })
public static String[] optimizeEntityTickingIgnoreList;

@Config.Comment("Prevent the integrated server from loading chunks when it doesn't necessarily need to. Can greatly improve performance on teleports, etc at the cost of slower chunkloading.")
@Config.DefaultBoolean(false)
public static boolean lazyChunkLoading;

@Config.Comment("Disable OptiFine's version checker.")
@Config.DefaultBoolean(true)
public static boolean disableOFVersionCheck;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@
import java.util.Set;

@Mixin(ChunkProviderServer.class)
public abstract class MixinChunkProviderServer implements ILazyChunkProviderServer {

@Shadow(remap = false) public abstract Chunk originalLoadChunk(int p_73158_1_, int p_73158_2_);
public abstract class MixinChunkProviderServer {

@Shadow public WorldServer worldObj;
private ObjectOpenHashSet<Pair<ChunkCoordIntPair, Runnable>> chunksToLoadSlow = new ObjectOpenHashSet<>();
private ArrayList<Pair<ChunkCoordIntPair, Runnable>> chunksToLoadSlowQueue = new ArrayList<>();
private ObjectOpenHashSet<Pair<ChunkCoordIntPair, Runnable>> chunksToLoadDropQueue = new ObjectOpenHashSet<>();

@Redirect(method = "unloadChunksIfNotNearSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/common/DimensionManager;shouldLoadSpawn(I)Z", remap = false))
private boolean neverLoadSpawn(int dim) {
Expand All @@ -56,68 +51,4 @@ private Chunk populateChunkWithBiomes(IChunkProvider instance, int chunkX, int c
}
return chunk;
}

@Inject(method = "loadChunk(IILjava/lang/Runnable;)Lnet/minecraft/world/chunk/Chunk;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/ChunkProviderServer;originalLoadChunk(II)Lnet/minecraft/world/chunk/Chunk;", remap = false), cancellable = true, remap = false)
private void queueChunkGeneration(int chunkX, int chunkZ, Runnable runnable, CallbackInfoReturnable<Chunk> cir) {
if(ArchaicConfig.lazyChunkLoading && runnable != null) {
cir.setReturnValue(null);
ChunkCoordIntPair c = new ChunkCoordIntPair(chunkX, chunkZ);
val pair= Pair.of(c, runnable);
if(!chunksToLoadSlow.contains(pair)) {
chunksToLoadSlow.add(pair);
chunksToLoadSlowQueue.add(pair);
}
}
}

@Inject(method = "unloadQueuedChunks", at = @At("RETURN"))
private void loadLazyChunks(CallbackInfoReturnable<Boolean> cir) {
if(!ArchaicConfig.lazyChunkLoading)
return;
Profiler profiler = this.worldObj.theProfiler;
profiler.startSection("lazychunks");
if(chunksToLoadDropQueue.size() > 0) {
profiler.startSection("drop");
chunksToLoadSlowQueue.removeIf(k -> chunksToLoadDropQueue.contains(k));
chunksToLoadSlow.removeAll(chunksToLoadDropQueue);
chunksToLoadDropQueue.clear();
profiler.endSection();
}
if(chunksToLoadSlowQueue.size() > 0) {
profiler.startSection("sort");
if(this.worldObj.playerEntities.size() > 0) {
ChunkCoordIntPair[] playerChunks = new ChunkCoordIntPair[this.worldObj.playerEntities.size()];
for(int i = 0; i < this.worldObj.playerEntities.size(); i++) {
EntityPlayer player = (EntityPlayer)this.worldObj.playerEntities.get(i);
playerChunks[i] = new ChunkCoordIntPair(player.chunkCoordX, player.chunkCoordZ);
}
chunksToLoadSlowQueue.sort(new ChunkQueueSorter(playerChunks));
}
profiler.endStartSection("load");
int i;
int amount = Math.min(5, chunksToLoadSlowQueue.size());
for(i = 0; i < amount; i++) {
val chunkPair = chunksToLoadSlowQueue.get(i);
chunksToLoadSlow.remove(chunkPair);
this.originalLoadChunk(chunkPair.getLeft().chunkXPos, chunkPair.getLeft().chunkZPos);
chunkPair.getRight().run();
}
chunksToLoadSlowQueue.subList(0, i).clear();
profiler.endSection();
}
profiler.endSection();
}

@Override
public boolean dropLazyChunk(int x, int z, Runnable runnable) {
if(!ArchaicConfig.lazyChunkLoading)
return false;
ChunkCoordIntPair c = new ChunkCoordIntPair(x, z);
val pair= Pair.of(c, runnable);
if(chunksToLoadSlow.contains(pair)) {
chunksToLoadDropQueue.add(pair);
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,4 @@ private static boolean checkForCollision(World world, Entity instance) {
}
return false;
}

@Inject(method = "findChunksForSpawning", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldServer;getSpawnPoint()Lnet/minecraft/util/ChunkCoordinates;", ordinal = 0))
private void removeUnloadedChunks(WorldServer p_77192_1_, boolean p_77192_2_, boolean p_77192_3_, boolean p_77192_4_, CallbackInfoReturnable<Integer> cir) {
if(!ArchaicConfig.lazyChunkLoading)
return;
Iterator<ChunkCoordIntPair> eligibleChunks = this.eligibleChunksForSpawning.keySet().iterator();
IChunkProvider prov = p_77192_1_.getChunkProvider();
while(eligibleChunks.hasNext()) {
ChunkCoordIntPair pair = eligibleChunks.next();
if(!prov.chunkExists(pair.chunkXPos, pair.chunkZPos))
eligibleChunks.remove();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,4 @@ private void shortenBlockUpdateDistance(CallbackInfoReturnable<Integer> cir) {
cir.setReturnValue(Math.min(cir.getReturnValue(), ArchaicConfig.optimizeBlockTickingDistance));
}
}

@Redirect(method = "func_147456_g", at = @At(value = "INVOKE", target = "Ljava/util/Set;iterator()Ljava/util/Iterator;"))
private Iterator getOnlyLoadedActiveChunks(Set instance) {
if(ArchaicConfig.lazyChunkLoading)
return Iterators.filter((Iterator<ChunkCoordIntPair>)instance.iterator(), pair ->
this.theChunkProviderServer.chunkExists(pair.chunkXPos, pair.chunkZPos)
);
else
return instance.iterator();
}
}

0 comments on commit 1b667db

Please sign in to comment.