Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
- Loading branch information
Showing
5 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/common/me/nallar/tickthreading/minecraft/ChunkGarbageCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.nallar.tickthreading.minecraft; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import net.minecraft.entity.player.EntityPlayerMP; | ||
import net.minecraft.profiler.Profiler; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.world.ChunkCoordIntPair; | ||
import net.minecraft.world.WorldServer; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.gen.ChunkProviderServer; | ||
|
||
public class ChunkGarbageCollector { | ||
public static Profiler profiler = MinecraftServer.getServer().theProfiler; | ||
|
||
public static void garbageCollect(WorldServer worldServer) { | ||
profiler.startSection("chunkGC"); | ||
int viewDistance = MinecraftServer.getServer().getConfigurationManager().getViewDistance(); | ||
ChunkProviderServer chunkProvider = worldServer.theChunkProviderServer; | ||
Set<Long> chunksToUnload = new HashSet<Long>(); | ||
for (Chunk chunk : chunkProvider.getLoadedChunks()) { | ||
chunksToUnload.add(ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition)); | ||
} | ||
|
||
for (Object player_ : worldServer.playerEntities) { | ||
EntityPlayerMP player = (EntityPlayerMP) player_; | ||
int cX = (int) player.managedPosX >> 4; | ||
int cZ = (int) player.managedPosZ >> 4; | ||
int minX = cX - viewDistance; | ||
int maxX = cX + viewDistance; | ||
int minZ = cZ - viewDistance; | ||
int maxZ = cZ + viewDistance; | ||
for (int x = minX; x <= maxX; x++) { | ||
for (int z = minZ; z <= maxZ; z++) { | ||
chunksToUnload.remove(ChunkCoordIntPair.chunkXZ2Int(x, z)); | ||
} | ||
} | ||
} | ||
|
||
chunkProvider.getChunksToUnloadSet().addAll(chunksToUnload); | ||
profiler.endSection(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0357b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering - would Chunk GC interfere with TTs new chunk cache since it keeps x amount loaded away from a player?
0357b22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.