replace ChunkPos with LongHashMap#get(X|Z) in WorldClient
This commit is contained in:
parent
e6d16405c5
commit
3a5a29cf9e
2 changed files with 21 additions and 12 deletions
|
@ -47,8 +47,8 @@ public class WorldClient extends AWorldClient
|
||||||
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 LongHashMap<Chunk> chunkMapping = new LongHashMap();
|
||||||
private final List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
|
private final List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
|
||||||
private final Set<ChunkPos> emptyChunkListing = Sets.<ChunkPos>newHashSet();
|
private final Set<Long> emptyChunkListing = Sets.<Long>newHashSet();
|
||||||
private final Set<ChunkPos> nextEmptyChunkListing = Sets.<ChunkPos>newHashSet();
|
private final Set<Long> nextEmptyChunkListing = Sets.<Long>newHashSet();
|
||||||
private final Chunk emptyChunk = new EmptyChunk(this);
|
private final Chunk emptyChunk = new EmptyChunk(this);
|
||||||
// public final Profiler profiler;
|
// public final Profiler profiler;
|
||||||
protected int lastLightning;
|
protected int lastLightning;
|
||||||
|
@ -70,23 +70,24 @@ public class WorldClient extends AWorldClient
|
||||||
for(int x = cx - range; x <= cx + range; x++) {
|
for(int x = cx - range; x <= cx + range; x++) {
|
||||||
for(int z = cz - range; z <= cz + range; z++) {
|
for(int z = cz - range; z <= cz + range; z++) {
|
||||||
long id = LongHashMap.packInt(x, z);
|
long id = LongHashMap.packInt(x, z);
|
||||||
ChunkPos pos = new ChunkPos(x, z);
|
|
||||||
if(this.chunkMapping.getValueByKey(id) != null) {
|
if(this.chunkMapping.getValueByKey(id) != null) {
|
||||||
if(this.emptyChunkListing.contains(pos)) {
|
if(this.emptyChunkListing.contains(id)) {
|
||||||
this.emptyChunkListing.remove(pos);
|
this.emptyChunkListing.remove(id);
|
||||||
this.nextEmptyChunkListing.add(pos);
|
this.nextEmptyChunkListing.add(id);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.chunkMapping.add(id, this.emptyChunk);
|
this.chunkMapping.add(id, this.emptyChunk);
|
||||||
this.emptyChunkListing.remove(pos);
|
this.emptyChunkListing.remove(id);
|
||||||
this.nextEmptyChunkListing.add(pos);
|
this.nextEmptyChunkListing.add(id);
|
||||||
this.markBlockRangeForRenderUpdate(x << 4, 0, z << 4, (x << 4) + 15, 512, (z << 4) + 15);
|
this.markBlockRangeForRenderUpdate(x << 4, 0, z << 4, (x << 4) + 15, 512, (z << 4) + 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(ChunkPos pos : this.emptyChunkListing) {
|
for(Long id : this.emptyChunkListing) {
|
||||||
this.chunkMapping.remove(LongHashMap.packInt(pos.x, pos.z));
|
this.chunkMapping.remove(id);
|
||||||
this.markBlockRangeForRenderUpdate(pos.x << 4, 0, pos.z << 4, (pos.x << 4) + 15, 512, (pos.z << 4) + 15);
|
int x = LongHashMap.getX(id);
|
||||||
|
int z = LongHashMap.getZ(id);
|
||||||
|
this.markBlockRangeForRenderUpdate(x << 4, 0, z << 4, (x << 4) + 15, 512, (z << 4) + 15);
|
||||||
}
|
}
|
||||||
this.emptyChunkListing.clear();
|
this.emptyChunkListing.clear();
|
||||||
this.emptyChunkListing.addAll(this.nextEmptyChunkListing);
|
this.emptyChunkListing.addAll(this.nextEmptyChunkListing);
|
||||||
|
@ -178,7 +179,7 @@ public class WorldClient extends AWorldClient
|
||||||
chunk.onChunkUnload();
|
chunk.onChunkUnload();
|
||||||
this.chunkMapping.remove(id);
|
this.chunkMapping.remove(id);
|
||||||
this.chunkListing.remove(chunk);
|
this.chunkListing.remove(chunk);
|
||||||
this.emptyChunkListing.remove(new ChunkPos(x, z));
|
this.emptyChunkListing.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load)
|
if (!load)
|
||||||
|
|
|
@ -13,6 +13,14 @@ public class LongHashMap<V>
|
||||||
return (long)x & 4294967295L | ((long)z & 4294967295L) << 32;
|
return (long)x & 4294967295L | ((long)z & 4294967295L) << 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getX(long v) {
|
||||||
|
return (int)(v & 4294967295L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getZ(long v) {
|
||||||
|
return (int)(v >> 32);
|
||||||
|
}
|
||||||
|
|
||||||
public LongHashMap()
|
public LongHashMap()
|
||||||
{
|
{
|
||||||
this.mask = this.hashArray.length - 1;
|
this.mask = this.hashArray.length - 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue