Simple chunk caching capability for the chunkloader. This will store "dormant" chunks in a
configurable cache, potentially saving the cost of reloading them from disk.
This commit is contained in:
parent
0b68cf93ff
commit
56a87604f6
2 changed files with 64 additions and 4 deletions
|
@ -13,6 +13,8 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
@ -76,6 +78,7 @@ public class ForgeChunkManager
|
|||
private static Map<World, SetMultimap<ChunkCoordIntPair,Ticket>> forcedChunks = Maps.newHashMap();
|
||||
private static BiMap<UUID,Ticket> pendingEntities = HashBiMap.create();
|
||||
|
||||
private static Cache<Long, Chunk> dormantChunkCache;
|
||||
/**
|
||||
* All mods requiring chunkloading need to implement this to handle the
|
||||
* re-registration of chunk tickets at world loading time
|
||||
|
@ -472,18 +475,35 @@ public class ForgeChunkManager
|
|||
"for a mod without an override. This is the maximum number of chunks a single ticket can force.";
|
||||
defaultMaxChunks = maxChunks.getInt(25);
|
||||
|
||||
Property dormantChunkCacheSize = config.getOrCreateIntProperty("dormantChunkCacheSize", "defaults", 0);
|
||||
dormantChunkCacheSize.comment = "Unloaded chunks can first be kept in a dormant cache for quicker\n" +
|
||||
"loading times. Specify the size of that cache here";
|
||||
dormantChunkCache = CacheBuilder.newBuilder().maximumSize(dormantChunkCacheSize.getInt(0)).build();
|
||||
|
||||
Property modOverridesEnabled = config.getOrCreateBooleanProperty("enabled", "defaults", true);
|
||||
modOverridesEnabled.comment = "Are mod overrides enabled?";
|
||||
overridesEnabled = modOverridesEnabled.getBoolean(true);
|
||||
|
||||
config.addCustomCategoryComment("Forge", "Sample mod specific control section.\n" +
|
||||
"Copy this section and rename the with the modid for the mod you wish to override.\n" +
|
||||
"A value of zero in either entry effectively disables any chunkloading capabilities\n" +
|
||||
"for that mod");
|
||||
"Copy this section and rename the with the modid for the mod you wish to override.\n" +
|
||||
"A value of zero in either entry effectively disables any chunkloading capabilities\n" +
|
||||
"for that mod");
|
||||
|
||||
Property sampleTC = config.getOrCreateIntProperty("maximumTicketCount", "Forge", 200);
|
||||
sampleTC.comment = "Maximum ticket count for the mod. Zero disables chunkloading capabilities.";
|
||||
sampleTC = config.getOrCreateIntProperty("maximumChunksPerTicket", "Forge", 25);
|
||||
sampleTC.comment = "Maximum chunks per ticket for the mod.";
|
||||
for (String mod : config.categories.keySet())
|
||||
{
|
||||
if (mod.equals("Forge") || mod.equals("defaults"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Property modTC = config.getOrCreateIntProperty("maximumTicketCount", mod, 200);
|
||||
Property modCPT = config.getOrCreateIntProperty("maximumChunksPerTicket", mod, 25);
|
||||
ticketConstraints.put(mod, modTC.getInt(200));
|
||||
chunkConstraints.put(mod, modCPT.getInt(25));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -560,4 +580,14 @@ public class ForgeChunkManager
|
|||
pendingEntities.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static void putDormantChunk(long coords, Chunk chunk)
|
||||
{
|
||||
dormantChunkCache.put(coords, chunk);
|
||||
}
|
||||
|
||||
public static Chunk fetchDormantChunk(long coords)
|
||||
{
|
||||
return dormantChunkCache.getIfPresent(coords);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,28 @@
|
|||
--- ../src_base/common/net/minecraft/src/ChunkProviderServer.java
|
||||
+++ ../src_work/common/net/minecraft/src/ChunkProviderServer.java
|
||||
@@ -274,6 +274,11 @@
|
||||
@@ -7,6 +7,8 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
+import net.minecraftforge.common.ForgeChunkManager;
|
||||
+
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class ChunkProviderServer implements IChunkProvider
|
||||
@@ -93,7 +95,11 @@
|
||||
|
||||
if (var5 == null)
|
||||
{
|
||||
- var5 = this.safeLoadChunk(par1, par2);
|
||||
+ var5 = ForgeChunkManager.fetchDormantChunk(var3);
|
||||
+ if (var5 == null)
|
||||
+ {
|
||||
+ var5 = this.safeLoadChunk(par1, par2);
|
||||
+ }
|
||||
|
||||
if (var5 == null)
|
||||
{
|
||||
@@ -274,6 +280,11 @@
|
||||
{
|
||||
if (!this.currentServer.canNotSave)
|
||||
{
|
||||
|
@ -12,3 +34,11 @@
|
|||
for (int var1 = 0; var1 < 100; ++var1)
|
||||
{
|
||||
if (!this.chunksToUnload.isEmpty())
|
||||
@@ -286,6 +297,7 @@
|
||||
this.chunksToUnload.remove(var2);
|
||||
this.loadedChunkHashMap.remove(var2.longValue());
|
||||
this.loadedChunks.remove(var3);
|
||||
+ ForgeChunkManager.putDormantChunk(ChunkCoordIntPair.chunkXZ2Int(var3.xPosition, var3.zPosition), var3);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue