Browse Source

IntHashMap for ChunkProviderServer

It's magical! See #10
master
Sam 9 years ago
parent
commit
d98b3b9896
  1. 44
      patches/net/minecraft/world/gen/ChunkProviderServer.java.patch

44
patches/net/minecraft/world/gen/ChunkProviderServer.java.patch

@ -68,6 +68,7 @@
+ public boolean loadChunkOnProvideRequest = MinecraftServer.getServer().cauldronConfig.loadChunkOnRequest.getValue(); // Cauldron - if true, allows mods to force load chunks. to disable, set load-chunk-on-request in cauldron.yml to false + public boolean loadChunkOnProvideRequest = MinecraftServer.getServer().cauldronConfig.loadChunkOnRequest.getValue(); // Cauldron - if true, allows mods to force load chunks. to disable, set load-chunk-on-request in cauldron.yml to false
+ public int initialTick; // Cauldron counter to keep track of when this loader was created + public int initialTick; // Cauldron counter to keep track of when this loader was created
+ public TLongObjectMap<Chunk> loadedChunkHashMap_KC = new TSynchronizedLongObjectMap<Chunk>(new TLongObjectHashMap<Chunk>()); + public TLongObjectMap<Chunk> loadedChunkHashMap_KC = new TSynchronizedLongObjectMap<Chunk>(new TLongObjectHashMap<Chunk>());
+ public ConcurrentHashMap<Integer,Chunk> chunkt_KC = new ConcurrentHashMap<Integer,Chunk>();
+ public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility + public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility
public WorldServer worldObj; public WorldServer worldObj;
private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet(); private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet();
@ -85,7 +86,8 @@
public boolean chunkExists(int p_73149_1_, int p_73149_2_) public boolean chunkExists(int p_73149_1_, int p_73149_2_)
{ {
- return this.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(p_73149_1_, p_73149_2_)); - return this.loadedChunkHashMap.containsItem(ChunkCoordIntPair.chunkXZ2Int(p_73149_1_, p_73149_2_));
+ return this.loadedChunkHashMap_KC.containsKey(LongHash.toLong(p_73149_1_, p_73149_2_)); // CraftBukkit + //return this.loadedChunkHashMap_KC.containsKey(LongHash.toLong(p_73149_1_, p_73149_2_)); // CraftBukkit
+ return this.chunkt_KC.containsKey(chunk_hash(p_73149_1_, p_73149_2_)); //KCauldron Replacement for line above
} }
- public List func_152380_a() - public List func_152380_a()
@ -93,11 +95,17 @@
{ {
return this.loadedChunks; return this.loadedChunks;
} }
+
+ public static int chunk_hash(int x, int y)
+ {
+ return ((x & 0xFFFF) << 16) | (y & 0xFFFF);
+ }
+
public void unloadChunksIfNotNearSpawn(int p_73241_1_, int p_73241_2_) public void unloadChunksIfNotNearSpawn(int p_73241_1_, int p_73241_2_)
{ {
+ // PaperSpigot start - Asynchronous lighting updates + // PaperSpigot start - Asynchronous lighting updates
+ Chunk chunk = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + //Chunk chunk = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+ Chunk chunk = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ if (chunk != null && chunk.worldObj.spigotConfig.useAsyncLighting && (chunk.pendingLightUpdates.get() > 0 || chunk.worldObj.getTotalWorldTime() - chunk.lightUpdateTime < 20)) { + if (chunk != null && chunk.worldObj.spigotConfig.useAsyncLighting && (chunk.pendingLightUpdates.get() > 0 || chunk.worldObj.getTotalWorldTime() - chunk.lightUpdateTime < 20)) {
+ return; + return;
+ } + }
@ -114,7 +122,8 @@
{ {
- this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_))); - this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_)));
+ this.chunksToUnload.add(p_73241_1_, p_73241_2_); + this.chunksToUnload.add(p_73241_1_, p_73241_2_);
+ Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + //Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+ Chunk c = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ +
+ if (c != null) + if (c != null)
+ { + {
@ -130,7 +139,8 @@
- this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_))); - this.chunksToUnload.add(Long.valueOf(ChunkCoordIntPair.chunkXZ2Int(p_73241_1_, p_73241_2_)));
+ // CraftBukkit start + // CraftBukkit start
+ this.chunksToUnload.add(p_73241_1_, p_73241_2_); + this.chunksToUnload.add(p_73241_1_, p_73241_2_);
+ Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_)); + //Chunk c = this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+ Chunk c = this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ +
+ if (c != null) + if (c != null)
+ { + {
@ -159,7 +169,8 @@
- this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition); - this.unloadChunksIfNotNearSpawn(chunk.xPosition, chunk.zPosition);
- } - }
+ public Chunk getChunkIfLoaded(int x, int z) { + public Chunk getChunkIfLoaded(int x, int z) {
+ return this.loadedChunkHashMap_KC.get(LongHash.toLong(x, z)); + //return this.loadedChunkHashMap_KC.get(LongHash.toLong(x, z));
+ return this.chunkt_KC.get(chunk_hash(x,z)); //KCauldron replacement for line above
} }
public Chunk loadChunk(int p_73158_1_, int p_73158_2_) public Chunk loadChunk(int p_73158_1_, int p_73158_2_)
@ -171,7 +182,8 @@
- this.chunksToUnload.remove(Long.valueOf(k)); - this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k); - Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ this.chunksToUnload.remove(par1, par2); + this.chunksToUnload.remove(par1, par2);
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(par1, par2)); + //Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(par1, par2));
+ Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(par1,par2)); //KCauldron replacement for line above
+ boolean newChunk = false; + boolean newChunk = false;
AnvilChunkLoader loader = null; AnvilChunkLoader loader = null;
@ -193,7 +205,8 @@
- this.chunksToUnload.remove(Long.valueOf(k)); - this.chunksToUnload.remove(Long.valueOf(k));
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k); - Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(k);
+ this.chunksToUnload.remove(p_73158_1_, p_73158_2_); + this.chunksToUnload.remove(p_73158_1_, p_73158_2_);
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73158_1_, p_73158_2_)); + //Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73241_1_, p_73241_2_));
+ Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(p_73241_1_, p_73241_2_)); //KCauldron replacement for line above
+ boolean newChunk = false; // CraftBukkit + boolean newChunk = false; // CraftBukkit
if (chunk == null) if (chunk == null)
@ -231,6 +244,7 @@
+ this.loadedChunkHashMap_KC.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); // CraftBukkit + this.loadedChunkHashMap_KC.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); // CraftBukkit
+ this.loadedChunks.add(chunk); // Cauldron - vanilla compatibility + this.loadedChunks.add(chunk); // Cauldron - vanilla compatibility
+ loadingChunks.remove(LongHash.toLong(p_73158_1_, p_73158_2_)); // Cauldron - LongHash + loadingChunks.remove(LongHash.toLong(p_73158_1_, p_73158_2_)); // Cauldron - LongHash
+ this.chunkt_KC.put(chunk_hash(p_73158_1_, p_73158_2_), chunk); //KCauldron - IntHash
+ +
+ if (chunk != null) + if (chunk != null)
+ { + {
@ -276,7 +290,8 @@
- Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(p_73154_1_, p_73154_2_)); - Chunk chunk = (Chunk)this.loadedChunkHashMap.getValueByKey(ChunkCoordIntPair.chunkXZ2Int(p_73154_1_, p_73154_2_));
- return chunk == null ? (!this.worldObj.findingSpawnPoint && !this.loadChunkOnProvideRequest ? this.defaultEmptyChunk : this.loadChunk(p_73154_1_, p_73154_2_)) : chunk; - return chunk == null ? (!this.worldObj.findingSpawnPoint && !this.loadChunkOnProvideRequest ? this.defaultEmptyChunk : this.loadChunk(p_73154_1_, p_73154_2_)) : chunk;
+ // CraftBukkit start + // CraftBukkit start
+ Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73154_1_, p_73154_2_)); + //Chunk chunk = (Chunk) this.loadedChunkHashMap_KC.get(LongHash.toLong(p_73154_1_, p_73154_2_));
+ Chunk chunk = (Chunk) this.chunkt_KC.get(chunk_hash(p_73154_1_, p_73154_2_)); //KCauldron replacement for line above
+ chunk = chunk == null ? (shouldLoadChunk() ? this.loadChunk(p_73154_1_, p_73154_2_) : this.defaultEmptyChunk) : chunk; // Cauldron handle forge server tick events and load the chunk within 5 seconds of the world being loaded (for chunk loaders) + chunk = chunk == null ? (shouldLoadChunk() ? this.loadChunk(p_73154_1_, p_73154_2_) : this.defaultEmptyChunk) : chunk; // Cauldron handle forge server tick events and load the chunk within 5 seconds of the world being loaded (for chunk loaders)
+ +
+ if (chunk == this.defaultEmptyChunk) + if (chunk == this.defaultEmptyChunk)
@ -436,7 +451,7 @@
{ {
- if (!this.chunksToUnload.isEmpty()) - if (!this.chunksToUnload.isEmpty())
+ long chunkcoordinates = this.chunksToUnload.popFirst(); + long chunkcoordinates = this.chunksToUnload.popFirst();
+ Chunk chunk = this.loadedChunkHashMap_KC.get(chunkcoordinates); + Chunk chunk = this.loadedChunkHashMap_KC.get(chunkcoordinates); //Not using the IntMap for this
+ +
+ if (chunk == null) + if (chunk == null)
{ {
@ -493,6 +508,7 @@
- this.loadedChunkHashMap.remove(olong.longValue()); - this.loadedChunkHashMap.remove(olong.longValue());
+ this.loadedChunkHashMap_KC.remove(chunkcoordinates); // CraftBukkit + this.loadedChunkHashMap_KC.remove(chunkcoordinates); // CraftBukkit
+ this.loadedChunks.remove(chunk); // Cauldron - vanilla compatibility + this.loadedChunks.remove(chunk); // Cauldron - vanilla compatibility
+ this.chunkt_KC.remove(chunk_hash(chunk.xCoord,chunk.zCoord)); //KCauldron - IntHashMap
+ ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk); + ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk);
+ if(this.loadedChunkHashMap_KC.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){ + if(this.loadedChunkHashMap_KC.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){
+ DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); + DimensionManager.unloadWorld(this.worldObj.provider.dimensionId);
@ -536,9 +552,11 @@
+ +
+ public long lastAccessed(int x, int z) + public long lastAccessed(int x, int z)
+ { + {
+ long chunkHash = LongHash.toLong(x, z); + //long chunkHash = LongHash.toLong(x, z);
+ if (!loadedChunkHashMap_KC.containsKey(chunkHash)) return 0; + //if (!loadedChunkHashMap_KC.containsKey(chunkHash)) return 0;
+ return loadedChunkHashMap_KC.get(chunkHash).lastAccessedTick; + //return loadedChunkHashMap_KC.get(chunkHash).lastAccessedTick;
+ if (!chunkt_KC.containsKey(chunk_hash(x,z))) return 0;
+ return chunkt_KC.get(chunk_hash(x,z)).lastAccessedTick;
+ } + }
+ +
+ private boolean shouldUnloadChunk(Chunk chunk) + private boolean shouldUnloadChunk(Chunk chunk)

Loading…
Cancel
Save