replace ChunkPos with LongHashMap#get(X|Z) in WorldClient

This commit is contained in:
Sen 2025-05-20 12:19:18 +02:00
parent e6d16405c5
commit 3a5a29cf9e
2 changed files with 21 additions and 12 deletions

View file

@ -47,8 +47,8 @@ public class WorldClient extends AWorldClient
private final Set<ChunkPos> previousActive = Sets.<ChunkPos>newHashSet();
private final LongHashMap<Chunk> chunkMapping = new LongHashMap();
private final List<Chunk> chunkListing = Lists.<Chunk>newArrayList();
private final Set<ChunkPos> emptyChunkListing = Sets.<ChunkPos>newHashSet();
private final Set<ChunkPos> nextEmptyChunkListing = Sets.<ChunkPos>newHashSet();
private final Set<Long> emptyChunkListing = Sets.<Long>newHashSet();
private final Set<Long> nextEmptyChunkListing = Sets.<Long>newHashSet();
private final Chunk emptyChunk = new EmptyChunk(this);
// public final Profiler profiler;
protected int lastLightning;
@ -70,23 +70,24 @@ public class WorldClient extends AWorldClient
for(int x = cx - range; x <= cx + range; x++) {
for(int z = cz - range; z <= cz + range; z++) {
long id = LongHashMap.packInt(x, z);
ChunkPos pos = new ChunkPos(x, z);
if(this.chunkMapping.getValueByKey(id) != null) {
if(this.emptyChunkListing.contains(pos)) {
this.emptyChunkListing.remove(pos);
this.nextEmptyChunkListing.add(pos);
if(this.emptyChunkListing.contains(id)) {
this.emptyChunkListing.remove(id);
this.nextEmptyChunkListing.add(id);
}
continue;
}
this.chunkMapping.add(id, this.emptyChunk);
this.emptyChunkListing.remove(pos);
this.nextEmptyChunkListing.add(pos);
this.emptyChunkListing.remove(id);
this.nextEmptyChunkListing.add(id);
this.markBlockRangeForRenderUpdate(x << 4, 0, z << 4, (x << 4) + 15, 512, (z << 4) + 15);
}
}
for(ChunkPos pos : this.emptyChunkListing) {
this.chunkMapping.remove(LongHashMap.packInt(pos.x, pos.z));
this.markBlockRangeForRenderUpdate(pos.x << 4, 0, pos.z << 4, (pos.x << 4) + 15, 512, (pos.z << 4) + 15);
for(Long id : this.emptyChunkListing) {
this.chunkMapping.remove(id);
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.addAll(this.nextEmptyChunkListing);
@ -178,7 +179,7 @@ public class WorldClient extends AWorldClient
chunk.onChunkUnload();
this.chunkMapping.remove(id);
this.chunkListing.remove(chunk);
this.emptyChunkListing.remove(new ChunkPos(x, z));
this.emptyChunkListing.remove(id);
}
if (!load)

View file

@ -13,6 +13,14 @@ public class LongHashMap<V>
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()
{
this.mask = this.hashArray.length - 1;