remove long chunk mapping
This commit is contained in:
parent
8834e2bdcd
commit
e78878c8cc
5 changed files with 58 additions and 342 deletions
|
@ -1,6 +1,7 @@
|
||||||
package client.world;
|
package client.world;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import client.Client;
|
import client.Client;
|
||||||
|
@ -9,6 +10,7 @@ import client.renderer.particle.EntityFirework;
|
||||||
import common.biome.Biome;
|
import common.biome.Biome;
|
||||||
import common.block.Block;
|
import common.block.Block;
|
||||||
import common.collect.Lists;
|
import common.collect.Lists;
|
||||||
|
import common.collect.Maps;
|
||||||
import common.collect.Sets;
|
import common.collect.Sets;
|
||||||
import common.dimension.Dimension;
|
import common.dimension.Dimension;
|
||||||
import common.entity.Entity;
|
import common.entity.Entity;
|
||||||
|
@ -30,7 +32,6 @@ import common.tileentity.TileEntity;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.util.ChunkPos;
|
import common.util.ChunkPos;
|
||||||
import common.util.ExtMath;
|
import common.util.ExtMath;
|
||||||
import common.util.LongHashMap;
|
|
||||||
import common.util.Vec3;
|
import common.util.Vec3;
|
||||||
import common.util.BlockPos.MutableBlockPos;
|
import common.util.BlockPos.MutableBlockPos;
|
||||||
import common.world.Chunk;
|
import common.world.Chunk;
|
||||||
|
@ -45,7 +46,7 @@ public class WorldClient extends AWorldClient
|
||||||
private final Set<Entity> entityList = Sets.<Entity>newHashSet();
|
private final Set<Entity> entityList = Sets.<Entity>newHashSet();
|
||||||
private final Set<Entity> spawnQueue = Sets.<Entity>newHashSet();
|
private final Set<Entity> spawnQueue = Sets.<Entity>newHashSet();
|
||||||
private final Set<ChunkPos> previousActive = Sets.<ChunkPos>newHashSet();
|
private final Set<ChunkPos> previousActive = Sets.<ChunkPos>newHashSet();
|
||||||
private final LongHashMap<Chunk> chunkMapping = new LongHashMap();
|
private final Map<ChunkPos, Chunk> chunkMapping = Maps.newHashMap();
|
||||||
private final List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
|
private final List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
|
||||||
private final Chunk blankChunk = new EmptyChunk(this);
|
private final Chunk blankChunk = new EmptyChunk(this);
|
||||||
// public final Profiler profiler;
|
// public final Profiler profiler;
|
||||||
|
@ -127,12 +128,13 @@ public class WorldClient extends AWorldClient
|
||||||
|
|
||||||
public void doPreChunk(int x, int z, boolean load)
|
public void doPreChunk(int x, int z, boolean load)
|
||||||
{
|
{
|
||||||
|
ChunkPos pos = new ChunkPos(x, z);
|
||||||
if (load)
|
if (load)
|
||||||
{
|
{
|
||||||
if(this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z)) != null)
|
if(this.chunkMapping.get(pos) != null)
|
||||||
this.doPreChunk(x, z, false);
|
this.doPreChunk(x, z, false);
|
||||||
Chunk chunk = new Chunk(this, x, z);
|
Chunk chunk = new Chunk(this, x, z);
|
||||||
this.chunkMapping.add(LongHashMap.packInt(x, z), chunk);
|
this.chunkMapping.put(pos, chunk);
|
||||||
this.chunkListing.add(chunk);
|
this.chunkListing.add(chunk);
|
||||||
chunk.setLoaded(true);
|
chunk.setLoaded(true);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +145,7 @@ public class WorldClient extends AWorldClient
|
||||||
{
|
{
|
||||||
chunk.onChunkUnload();
|
chunk.onChunkUnload();
|
||||||
}
|
}
|
||||||
this.chunkMapping.remove(LongHashMap.packInt(x, z));
|
this.chunkMapping.remove(pos);
|
||||||
this.chunkListing.remove(chunk);
|
this.chunkListing.remove(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,13 +355,13 @@ public class WorldClient extends AWorldClient
|
||||||
|
|
||||||
public Chunk getChunk(int x, int z)
|
public Chunk getChunk(int x, int z)
|
||||||
{
|
{
|
||||||
Chunk chunk = this.chunkMapping.getValueByKey(LongHashMap.packInt(x, z));
|
Chunk chunk = this.chunkMapping.get(new ChunkPos(x, z));
|
||||||
return chunk == null ? this.blankChunk : chunk;
|
return chunk == null ? this.blankChunk : chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInfo()
|
public String getInfo()
|
||||||
{
|
{
|
||||||
return "Chunk-Cache: M " + this.chunkMapping.getNumHashElements() + ", L " + this.chunkListing.size();
|
return "Chunk-Cache: M " + this.chunkMapping.size() + ", L " + this.chunkListing.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playSound(SoundEvent sound, double x, double y, double z, float volume)
|
public void playSound(SoundEvent sound, double x, double y, double z, float volume)
|
||||||
|
|
|
@ -1,285 +0,0 @@
|
||||||
package common.util;
|
|
||||||
|
|
||||||
public class LongHashMap<V>
|
|
||||||
{
|
|
||||||
private transient LongHashMap.Entry<V>[] hashArray = new LongHashMap.Entry[4096];
|
|
||||||
private transient int numHashElements;
|
|
||||||
private int mask;
|
|
||||||
private int capacity = 3072;
|
|
||||||
private final float percentUseable = 0.75F;
|
|
||||||
private transient volatile int modCount;
|
|
||||||
|
|
||||||
public static long packInt(int x, int z) {
|
|
||||||
return (long)x & 4294967295L | ((long)z & 4294967295L) << 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LongHashMap()
|
|
||||||
{
|
|
||||||
this.mask = this.hashArray.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the hashed key given the original key
|
|
||||||
*/
|
|
||||||
private static int getHashedKey(long originalKey)
|
|
||||||
{
|
|
||||||
return hash((int)(originalKey ^ originalKey >>> 32));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the hash function
|
|
||||||
*/
|
|
||||||
private static int hash(int integer)
|
|
||||||
{
|
|
||||||
integer = integer ^ integer >>> 20 ^ integer >>> 12;
|
|
||||||
return integer ^ integer >>> 7 ^ integer >>> 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the index in the hash given the array length and the hashed key
|
|
||||||
*/
|
|
||||||
private static int getHashIndex(int p_76158_0_, int p_76158_1_)
|
|
||||||
{
|
|
||||||
return p_76158_0_ & p_76158_1_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumHashElements()
|
|
||||||
{
|
|
||||||
return this.numHashElements;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the value from the map given the key
|
|
||||||
*/
|
|
||||||
public V getValueByKey(long p_76164_1_)
|
|
||||||
{
|
|
||||||
int i = getHashedKey(p_76164_1_);
|
|
||||||
|
|
||||||
for (LongHashMap.Entry<V> entry = this.hashArray[getHashIndex(i, this.mask)]; entry != null; entry = entry.nextEntry)
|
|
||||||
{
|
|
||||||
if (entry.key == p_76164_1_)
|
|
||||||
{
|
|
||||||
return entry.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (V)null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsItem(long p_76161_1_)
|
|
||||||
{
|
|
||||||
return this.getEntry(p_76161_1_) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final LongHashMap.Entry<V> getEntry(long p_76160_1_)
|
|
||||||
{
|
|
||||||
int i = getHashedKey(p_76160_1_);
|
|
||||||
|
|
||||||
for (LongHashMap.Entry<V> entry = this.hashArray[getHashIndex(i, this.mask)]; entry != null; entry = entry.nextEntry)
|
|
||||||
{
|
|
||||||
if (entry.key == p_76160_1_)
|
|
||||||
{
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a key-value pair.
|
|
||||||
*/
|
|
||||||
public void add(long p_76163_1_, V p_76163_3_)
|
|
||||||
{
|
|
||||||
int i = getHashedKey(p_76163_1_);
|
|
||||||
int j = getHashIndex(i, this.mask);
|
|
||||||
|
|
||||||
for (LongHashMap.Entry<V> entry = this.hashArray[j]; entry != null; entry = entry.nextEntry)
|
|
||||||
{
|
|
||||||
if (entry.key == p_76163_1_)
|
|
||||||
{
|
|
||||||
entry.value = p_76163_3_;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++this.modCount;
|
|
||||||
this.createKey(i, p_76163_1_, p_76163_3_, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* resizes the table
|
|
||||||
*/
|
|
||||||
private void resizeTable(int p_76153_1_)
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V>[] entry = this.hashArray;
|
|
||||||
int i = entry.length;
|
|
||||||
|
|
||||||
if (i == 1073741824)
|
|
||||||
{
|
|
||||||
this.capacity = Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V>[] entry1 = new LongHashMap.Entry[p_76153_1_];
|
|
||||||
this.copyHashTableTo(entry1);
|
|
||||||
this.hashArray = entry1;
|
|
||||||
this.mask = this.hashArray.length - 1;
|
|
||||||
this.capacity = (int)((float)p_76153_1_ * this.percentUseable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* copies the hash table to the specified array
|
|
||||||
*/
|
|
||||||
private void copyHashTableTo(LongHashMap.Entry<V>[] p_76154_1_)
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V>[] entry = this.hashArray;
|
|
||||||
int i = p_76154_1_.length;
|
|
||||||
|
|
||||||
for (int j = 0; j < entry.length; ++j)
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V> entry1 = entry[j];
|
|
||||||
|
|
||||||
if (entry1 != null)
|
|
||||||
{
|
|
||||||
entry[j] = null;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V> entry2 = entry1.nextEntry;
|
|
||||||
int k = getHashIndex(entry1.hash, i - 1);
|
|
||||||
entry1.nextEntry = p_76154_1_[k];
|
|
||||||
p_76154_1_[k] = entry1;
|
|
||||||
entry1 = entry2;
|
|
||||||
|
|
||||||
if (entry2 == null)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* calls the removeKey method and returns removed object
|
|
||||||
*/
|
|
||||||
public V remove(long p_76159_1_)
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V> entry = this.removeKey(p_76159_1_);
|
|
||||||
return (V)(entry == null ? null : entry.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
final LongHashMap.Entry<V> removeKey(long p_76152_1_)
|
|
||||||
{
|
|
||||||
int i = getHashedKey(p_76152_1_);
|
|
||||||
int j = getHashIndex(i, this.mask);
|
|
||||||
LongHashMap.Entry<V> entry = this.hashArray[j];
|
|
||||||
LongHashMap.Entry<V> entry1;
|
|
||||||
LongHashMap.Entry<V> entry2;
|
|
||||||
|
|
||||||
for (entry1 = entry; entry1 != null; entry1 = entry2)
|
|
||||||
{
|
|
||||||
entry2 = entry1.nextEntry;
|
|
||||||
|
|
||||||
if (entry1.key == p_76152_1_)
|
|
||||||
{
|
|
||||||
++this.modCount;
|
|
||||||
--this.numHashElements;
|
|
||||||
|
|
||||||
if (entry == entry1)
|
|
||||||
{
|
|
||||||
this.hashArray[j] = entry2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
entry.nextEntry = entry2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry1;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry = entry1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return entry1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates the key in the hash table
|
|
||||||
*/
|
|
||||||
private void createKey(int p_76156_1_, long p_76156_2_, V p_76156_4_, int p_76156_5_)
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V> entry = this.hashArray[p_76156_5_];
|
|
||||||
this.hashArray[p_76156_5_] = new LongHashMap.Entry(p_76156_1_, p_76156_2_, p_76156_4_, entry);
|
|
||||||
|
|
||||||
if (this.numHashElements++ >= this.capacity)
|
|
||||||
{
|
|
||||||
this.resizeTable(2 * this.hashArray.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Entry<V>
|
|
||||||
{
|
|
||||||
final long key;
|
|
||||||
V value;
|
|
||||||
LongHashMap.Entry<V> nextEntry;
|
|
||||||
final int hash;
|
|
||||||
|
|
||||||
Entry(int p_i1553_1_, long p_i1553_2_, V p_i1553_4_, LongHashMap.Entry<V> p_i1553_5_)
|
|
||||||
{
|
|
||||||
this.value = p_i1553_4_;
|
|
||||||
this.nextEntry = p_i1553_5_;
|
|
||||||
this.key = p_i1553_2_;
|
|
||||||
this.hash = p_i1553_1_;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final long getKey()
|
|
||||||
{
|
|
||||||
return this.key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final V getValue()
|
|
||||||
{
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean equals(Object p_equals_1_)
|
|
||||||
{
|
|
||||||
if (!(p_equals_1_ instanceof LongHashMap.Entry))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LongHashMap.Entry<V> entry = (LongHashMap.Entry)p_equals_1_;
|
|
||||||
Object object = Long.valueOf(this.getKey());
|
|
||||||
Object object1 = Long.valueOf(entry.getKey());
|
|
||||||
|
|
||||||
if (object == object1 || object != null && object.equals(object1))
|
|
||||||
{
|
|
||||||
Object object2 = this.getValue();
|
|
||||||
Object object3 = entry.getValue();
|
|
||||||
|
|
||||||
if (object2 == object3 || object2 != null && object2.equals(object3))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final int hashCode()
|
|
||||||
{
|
|
||||||
return LongHashMap.getHashedKey(this.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String toString()
|
|
||||||
{
|
|
||||||
return this.getKey() + "=" + this.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -66,7 +66,6 @@ import common.util.ChunkPos;
|
||||||
import common.util.ExtMath;
|
import common.util.ExtMath;
|
||||||
import common.util.FileUtils;
|
import common.util.FileUtils;
|
||||||
import common.util.IntHashMap;
|
import common.util.IntHashMap;
|
||||||
import common.util.LongHashMap;
|
|
||||||
import common.util.NextTickListEntry;
|
import common.util.NextTickListEntry;
|
||||||
import common.util.PortalType;
|
import common.util.PortalType;
|
||||||
import common.util.Position;
|
import common.util.Position;
|
||||||
|
@ -130,15 +129,15 @@ public final class WorldServer extends AWorldServer {
|
||||||
private final TreeSet<NextTickListEntry> ticksNext = new TreeSet();
|
private final TreeSet<NextTickListEntry> ticksNext = new TreeSet();
|
||||||
private final EventList[] queue = new EventList[] {new EventList(), new EventList()};
|
private final EventList[] queue = new EventList[] {new EventList(), new EventList()};
|
||||||
private final List<NextTickListEntry> ticksNow = Lists.<NextTickListEntry>newArrayList();
|
private final List<NextTickListEntry> ticksNow = Lists.<NextTickListEntry>newArrayList();
|
||||||
private final Set<Long> dropped = Collections.<Long>newSetFromMap(new ConcurrentHashMap());
|
private final Set<ChunkPos> dropped = Collections.<ChunkPos>newSetFromMap(new ConcurrentHashMap());
|
||||||
private final LongHashMap<Chunk> chunks = new LongHashMap();
|
private final Map<ChunkPos, Chunk> chunks = Maps.newHashMap();
|
||||||
private final List<Chunk> loaded = Lists.<Chunk>newArrayList();
|
private final List<Chunk> loaded = Lists.<Chunk>newArrayList();
|
||||||
private final Map<ChunkPos, NBTTagCompound> toRemove = new ConcurrentHashMap();
|
private final Map<ChunkPos, NBTTagCompound> toRemove = new ConcurrentHashMap();
|
||||||
private final Set<ChunkPos> pending = Collections.<ChunkPos>newSetFromMap(new ConcurrentHashMap());
|
private final Set<ChunkPos> pending = Collections.<ChunkPos>newSetFromMap(new ConcurrentHashMap());
|
||||||
private final LongHashMap<BlockPos> loaders = new LongHashMap();
|
private final Map<ChunkPos, BlockPos> loaders = Maps.newHashMap();
|
||||||
private final Set<BlockPos> loaderList = Sets.<BlockPos>newHashSet();
|
private final Set<BlockPos> loaderList = Sets.<BlockPos>newHashSet();
|
||||||
private final List<EntityNPC> managed = Lists.<EntityNPC>newArrayList();
|
private final List<EntityNPC> managed = Lists.<EntityNPC>newArrayList();
|
||||||
private final LongHashMap<PlayerInstance> instances = new LongHashMap();
|
private final Map<ChunkPos, PlayerInstance> instances = Maps.newHashMap();
|
||||||
private final List<PlayerInstance> toUpdate = Lists.<PlayerInstance>newArrayList();
|
private final List<PlayerInstance> toUpdate = Lists.<PlayerInstance>newArrayList();
|
||||||
private final List<PlayerInstance> instList = Lists.<PlayerInstance>newArrayList();
|
private final List<PlayerInstance> instList = Lists.<PlayerInstance>newArrayList();
|
||||||
private final Set<EntityTrackerEntry> tracked = Sets.<EntityTrackerEntry>newHashSet();
|
private final Set<EntityTrackerEntry> tracked = Sets.<EntityTrackerEntry>newHashSet();
|
||||||
|
@ -512,12 +511,12 @@ public final class WorldServer extends AWorldServer {
|
||||||
if(!this.debug) {
|
if(!this.debug) {
|
||||||
for(int i = 0; i < 100; ++i) {
|
for(int i = 0; i < 100; ++i) {
|
||||||
if(!this.dropped.isEmpty()) {
|
if(!this.dropped.isEmpty()) {
|
||||||
Long v = (Long)this.dropped.iterator().next();
|
ChunkPos v = this.dropped.iterator().next();
|
||||||
Chunk chunk = (Chunk)this.chunks.getValueByKey(v.longValue());
|
Chunk chunk = this.chunks.get(v);
|
||||||
if(chunk != null) {
|
if(chunk != null) {
|
||||||
chunk.onChunkUnload();
|
chunk.onChunkUnload();
|
||||||
this.saveChunkData(chunk);
|
this.saveChunkData(chunk);
|
||||||
this.chunks.remove(v.longValue());
|
this.chunks.remove(v);
|
||||||
this.loaded.remove(chunk);
|
this.loaded.remove(chunk);
|
||||||
}
|
}
|
||||||
this.dropped.remove(v);
|
this.dropped.remove(v);
|
||||||
|
@ -570,10 +569,10 @@ public final class WorldServer extends AWorldServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addLoader(BlockPos pos) {
|
public boolean addLoader(BlockPos pos) {
|
||||||
long chunk = LongHashMap.packInt(pos.getX() / 16, pos.getZ() / 16);
|
ChunkPos chunk = new ChunkPos(pos.getX() / 16, pos.getZ() / 16);
|
||||||
if(this.loaders.containsItem(chunk))
|
if(this.loaders.containsKey(chunk))
|
||||||
return false;
|
return false;
|
||||||
this.loaders.add(chunk, pos);
|
this.loaders.put(chunk, pos);
|
||||||
this.loaderList.add(pos);
|
this.loaderList.add(pos);
|
||||||
this.loadersModified = true;
|
this.loadersModified = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -584,8 +583,8 @@ public final class WorldServer extends AWorldServer {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public boolean removeLoader(BlockPos pos) {
|
public boolean removeLoader(BlockPos pos) {
|
||||||
long chunk = LongHashMap.packInt(pos.getX() / 16, pos.getZ() / 16);
|
ChunkPos chunk = new ChunkPos(pos.getX() / 16, pos.getZ() / 16);
|
||||||
BlockPos loader = this.loaders.getValueByKey(chunk);
|
BlockPos loader = this.loaders.get(chunk);
|
||||||
if(!pos.equals(loader))
|
if(!pos.equals(loader))
|
||||||
return false;
|
return false;
|
||||||
this.loaders.remove(chunk);
|
this.loaders.remove(chunk);
|
||||||
|
@ -1325,18 +1324,18 @@ public final class WorldServer extends AWorldServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk getChunk(int x, int z) {
|
public Chunk getChunk(int x, int z) {
|
||||||
Chunk chunk = this.chunks.getValueByKey(LongHashMap.packInt(x, z));
|
Chunk chunk = this.chunks.get(new ChunkPos(x, z));
|
||||||
return chunk == null ? this.loadChunk(x, z) : chunk;
|
return chunk == null ? this.loadChunk(x, z) : chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean chunkExists(int x, int z) {
|
private boolean chunkExists(int x, int z) {
|
||||||
return this.chunks.containsItem(LongHashMap.packInt(x, z));
|
return this.chunks.containsKey(new ChunkPos(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropChunk(int x, int z) {
|
public void dropChunk(int x, int z) {
|
||||||
long chunk = LongHashMap.packInt(x, z);
|
ChunkPos chunk = new ChunkPos(x, z);
|
||||||
if(!this.loaders.containsItem(chunk))
|
if(!this.loaders.containsKey(chunk))
|
||||||
this.dropped.add(Long.valueOf(chunk));
|
this.dropped.add(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadForcedChunks() {
|
public void loadForcedChunks() {
|
||||||
|
@ -1352,9 +1351,9 @@ public final class WorldServer extends AWorldServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk loadChunk(int x, int z) {
|
public Chunk loadChunk(int x, int z) {
|
||||||
long id = LongHashMap.packInt(x, z);
|
ChunkPos id = new ChunkPos(x, z);
|
||||||
this.dropped.remove(Long.valueOf(id));
|
this.dropped.remove(id);
|
||||||
Chunk chunk = (Chunk)this.chunks.getValueByKey(id);
|
Chunk chunk = this.chunks.get(id);
|
||||||
|
|
||||||
if(chunk == null) {
|
if(chunk == null) {
|
||||||
if(!this.debug)
|
if(!this.debug)
|
||||||
|
@ -1364,7 +1363,7 @@ public final class WorldServer extends AWorldServer {
|
||||||
chunk = this.generate(x, z);
|
chunk = this.generate(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chunks.add(id, chunk);
|
this.chunks.put(id, chunk);
|
||||||
this.loaded.add(chunk);
|
this.loaded.add(chunk);
|
||||||
chunk.onChunkLoad();
|
chunk.onChunkLoad();
|
||||||
this.popChunk(x, z);
|
this.popChunk(x, z);
|
||||||
|
@ -1652,7 +1651,7 @@ public final class WorldServer extends AWorldServer {
|
||||||
if(!this.loaderList.isEmpty())
|
if(!this.loaderList.isEmpty())
|
||||||
this.loadersModified = true;
|
this.loadersModified = true;
|
||||||
for(BlockPos pos : this.loaderList) {
|
for(BlockPos pos : this.loaderList) {
|
||||||
this.loaders.remove(LongHashMap.packInt(pos.getX() / 16, pos.getZ() / 16));
|
this.loaders.remove(new ChunkPos(pos.getX() / 16, pos.getZ() / 16));
|
||||||
}
|
}
|
||||||
this.loaderList.clear();
|
this.loaderList.clear();
|
||||||
for(Iterator<Entry<String, Position>> iter = this.server.getWarps().entrySet().iterator(); iter.hasNext();) {
|
for(Iterator<Entry<String, Position>> iter = this.server.getWarps().entrySet().iterator(); iter.hasNext();) {
|
||||||
|
@ -1668,11 +1667,11 @@ public final class WorldServer extends AWorldServer {
|
||||||
}));
|
}));
|
||||||
this.exterminated = true;
|
this.exterminated = true;
|
||||||
// this.dataModified = true;
|
// this.dataModified = true;
|
||||||
for(Long v : this.dropped) {
|
for(ChunkPos v : this.dropped) {
|
||||||
Chunk chunk = this.chunks.getValueByKey(v.longValue());
|
Chunk chunk = this.chunks.get(v);
|
||||||
if(chunk != null) {
|
if(chunk != null) {
|
||||||
chunk.onChunkUnload();
|
chunk.onChunkUnload();
|
||||||
this.chunks.remove(v.longValue());
|
this.chunks.remove(v);
|
||||||
this.loaded.remove(chunk);
|
this.loaded.remove(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1681,11 +1680,11 @@ public final class WorldServer extends AWorldServer {
|
||||||
this.loaded.clear();
|
this.loaded.clear();
|
||||||
this.setExterminatedGen();
|
this.setExterminatedGen();
|
||||||
for(Chunk chunk : loaded) {
|
for(Chunk chunk : loaded) {
|
||||||
long pos = LongHashMap.packInt(chunk.xPos, chunk.zPos);
|
ChunkPos pos = new ChunkPos(chunk.xPos, chunk.zPos);
|
||||||
chunk.onChunkUnload();
|
chunk.onChunkUnload();
|
||||||
this.chunks.remove(pos);
|
this.chunks.remove(pos);
|
||||||
chunk = this.generate(chunk.xPos, chunk.zPos);
|
chunk = this.generate(chunk.xPos, chunk.zPos);
|
||||||
this.chunks.add(pos, chunk);
|
this.chunks.put(pos, chunk);
|
||||||
this.loaded.add(chunk);
|
this.loaded.add(chunk);
|
||||||
chunk.onChunkLoad();
|
chunk.onChunkLoad();
|
||||||
chunk.setTerrainPopulated(true);
|
chunk.setTerrainPopulated(true);
|
||||||
|
@ -1764,7 +1763,7 @@ public final class WorldServer extends AWorldServer {
|
||||||
Object[] worlds = server.getWorlds().toArray();
|
Object[] worlds = server.getWorlds().toArray();
|
||||||
for(Object obj : worlds) {
|
for(Object obj : worlds) {
|
||||||
WorldServer world = (WorldServer)obj;
|
WorldServer world = (WorldServer)obj;
|
||||||
chunks += world.chunks.getNumHashElements();
|
chunks += world.chunks.size();
|
||||||
entities += world.entities.size();
|
entities += world.entities.size();
|
||||||
tiles += world.tiles.size();
|
tiles += world.tiles.size();
|
||||||
ticked += world.tickable.size();
|
ticked += world.tickable.size();
|
||||||
|
@ -1864,13 +1863,13 @@ public final class WorldServer extends AWorldServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasPlayerInstance(int chunkX, int chunkZ) {
|
private boolean hasPlayerInstance(int chunkX, int chunkZ) {
|
||||||
long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32;
|
ChunkPos v = new ChunkPos(chunkX, chunkZ);
|
||||||
return this.instances.getValueByKey(v) != null;
|
return this.instances.get(v) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBiomes(int chunkX, int chunkZ) {
|
public boolean updateBiomes(int chunkX, int chunkZ) {
|
||||||
long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32;
|
ChunkPos v = new ChunkPos(chunkX, chunkZ);
|
||||||
PlayerInstance ins = this.instances.getValueByKey(v);
|
PlayerInstance ins = this.instances.get(v);
|
||||||
if(ins == null)
|
if(ins == null)
|
||||||
return false;
|
return false;
|
||||||
Chunk chunk = this.getChunk(chunkX, chunkZ);
|
Chunk chunk = this.getChunk(chunkX, chunkZ);
|
||||||
|
@ -1880,12 +1879,12 @@ public final class WorldServer extends AWorldServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerInstance getPlayerInstance(int chunkX, int chunkZ, boolean create) {
|
private PlayerInstance getPlayerInstance(int chunkX, int chunkZ, boolean create) {
|
||||||
long v = (long)chunkX + 2147483647L | (long)chunkZ + 2147483647L << 32;
|
ChunkPos v = new ChunkPos(chunkX, chunkZ);
|
||||||
PlayerInstance inst = this.instances.getValueByKey(v);
|
PlayerInstance inst = this.instances.get(v);
|
||||||
|
|
||||||
if(inst == null && create) {
|
if(inst == null && create) {
|
||||||
inst = new PlayerInstance(chunkX, chunkZ);
|
inst = new PlayerInstance(chunkX, chunkZ);
|
||||||
this.instances.add(v, inst);
|
this.instances.put(v, inst);
|
||||||
this.instList.add(inst);
|
this.instList.add(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2837,9 +2836,8 @@ public final class WorldServer extends AWorldServer {
|
||||||
player.connection.getLoadedChunkList().remove(this.position);
|
player.connection.getLoadedChunkList().remove(this.position);
|
||||||
|
|
||||||
if(this.watching.isEmpty()) {
|
if(this.watching.isEmpty()) {
|
||||||
long v = (long)this.position.x + 2147483647L | (long)this.position.z + 2147483647L << 32;
|
|
||||||
this.increaseInhabitedTime(chunk);
|
this.increaseInhabitedTime(chunk);
|
||||||
WorldServer.this.instances.remove(v);
|
WorldServer.this.instances.remove(this.position);
|
||||||
WorldServer.this.instList.remove(this);
|
WorldServer.this.instList.remove(this);
|
||||||
|
|
||||||
if(this.updates > 0) {
|
if(this.updates > 0) {
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package server.worldgen;
|
package server.worldgen;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import common.biome.Biome;
|
import common.biome.Biome;
|
||||||
import common.collect.Lists;
|
import common.collect.Lists;
|
||||||
|
import common.collect.Maps;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.util.LongHashMap;
|
import common.util.ChunkPos;
|
||||||
import common.worldgen.BiomeGenerator;
|
import common.worldgen.BiomeGenerator;
|
||||||
import server.worldgen.layer.GenLayer;
|
import server.worldgen.layer.GenLayer;
|
||||||
import server.worldgen.layer.GenLayerAddAreas;
|
import server.worldgen.layer.GenLayerAddAreas;
|
||||||
|
@ -54,7 +56,7 @@ public class BiomeGenLayered implements BiomeGenerator {
|
||||||
|
|
||||||
private final GenLayer genBiomes;
|
private final GenLayer genBiomes;
|
||||||
private final GenLayer biomeIndexLayer;
|
private final GenLayer biomeIndexLayer;
|
||||||
private final LongHashMap<CacheBlock> cacheMap = new LongHashMap();
|
private final Map<ChunkPos, CacheBlock> cacheMap = Maps.newHashMap();
|
||||||
private final List<CacheBlock> cache = Lists.<CacheBlock>newArrayList();
|
private final List<CacheBlock> cache = Lists.<CacheBlock>newArrayList();
|
||||||
private long lastCleanupTime;
|
private long lastCleanupTime;
|
||||||
|
|
||||||
|
@ -125,13 +127,13 @@ public class BiomeGenLayered implements BiomeGenerator {
|
||||||
{
|
{
|
||||||
x = x >> 4;
|
x = x >> 4;
|
||||||
z = z >> 4;
|
z = z >> 4;
|
||||||
long i = LongHashMap.packInt(x, z); // (long)x & 4294967295L | ((long)z & 4294967295L) << 32;
|
ChunkPos pos = new ChunkPos(x, z);
|
||||||
CacheBlock blk = this.cacheMap.getValueByKey(i);
|
CacheBlock blk = this.cacheMap.get(pos);
|
||||||
|
|
||||||
if (blk == null)
|
if (blk == null)
|
||||||
{
|
{
|
||||||
blk = new CacheBlock(x, z);
|
blk = new CacheBlock(x, z);
|
||||||
this.cacheMap.add(i, blk);
|
this.cacheMap.put(pos, blk);
|
||||||
this.cache.add(blk);
|
this.cache.add(blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,8 +158,7 @@ public class BiomeGenLayered implements BiomeGenerator {
|
||||||
if (l > 30000L || l < 0L)
|
if (l > 30000L || l < 0L)
|
||||||
{
|
{
|
||||||
this.cache.remove(k--);
|
this.cache.remove(k--);
|
||||||
long i1 = LongHashMap.packInt(blk.xPosition, blk.zPosition) ; // (long)biomecache$block.xPosition & 4294967295L | ((long)biomecache$block.zPosition & 4294967295L) << 32;
|
this.cacheMap.remove(new ChunkPos(blk.xPosition, blk.zPosition));
|
||||||
this.cacheMap.remove(i1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import common.nbt.NBTTagCompound;
|
||||||
import common.rng.Random;
|
import common.rng.Random;
|
||||||
import common.util.BlockPos;
|
import common.util.BlockPos;
|
||||||
import common.util.ChunkPos;
|
import common.util.ChunkPos;
|
||||||
import common.util.LongHashMap;
|
|
||||||
import common.world.World;
|
import common.world.World;
|
||||||
import server.world.WorldServer;
|
import server.world.WorldServer;
|
||||||
import server.world.WorldServer.WorldSavedData;
|
import server.world.WorldServer.WorldSavedData;
|
||||||
|
@ -19,7 +18,7 @@ import server.worldgen.caves.MapGenBase;
|
||||||
public abstract class MapGenStructure extends MapGenBase
|
public abstract class MapGenStructure extends MapGenBase
|
||||||
{
|
{
|
||||||
private WorldSavedData structureData;
|
private WorldSavedData structureData;
|
||||||
protected Map<Long, StructureStart> structureMap = Maps.<Long, StructureStart>newHashMap();
|
protected Map<ChunkPos, StructureStart> structureMap = Maps.<ChunkPos, StructureStart>newHashMap();
|
||||||
|
|
||||||
public abstract String getStructureName();
|
public abstract String getStructureName();
|
||||||
|
|
||||||
|
@ -34,14 +33,15 @@ public abstract class MapGenStructure extends MapGenBase
|
||||||
return;
|
return;
|
||||||
this.initializeStructureData(worldIn);
|
this.initializeStructureData(worldIn);
|
||||||
|
|
||||||
if (!this.structureMap.containsKey(Long.valueOf(LongHashMap.packInt(chunkX, chunkZ))))
|
ChunkPos pos = new ChunkPos(chunkX, chunkZ);
|
||||||
|
if (!this.structureMap.containsKey(pos))
|
||||||
{
|
{
|
||||||
this.rand.intv();
|
this.rand.intv();
|
||||||
|
|
||||||
if (this.canSpawnStructureAtCoords(chunkX, chunkZ))
|
if (this.canSpawnStructureAtCoords(chunkX, chunkZ))
|
||||||
{
|
{
|
||||||
StructureStart structurestart = this.getStructureStart(chunkX, chunkZ);
|
StructureStart structurestart = this.getStructureStart(chunkX, chunkZ);
|
||||||
this.structureMap.put(Long.valueOf(LongHashMap.packInt(chunkX, chunkZ)), structurestart);
|
this.structureMap.put(pos, structurestart);
|
||||||
this.setStructureStart(chunkX, chunkZ, structurestart);
|
this.setStructureStart(chunkX, chunkZ, structurestart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ public abstract class MapGenStructure extends MapGenBase
|
||||||
|
|
||||||
if (structurestart != null)
|
if (structurestart != null)
|
||||||
{
|
{
|
||||||
this.structureMap.put(Long.valueOf(LongHashMap.packInt(i, j)), structurestart);
|
this.structureMap.put(new ChunkPos(i, j), structurestart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue