Skip to content

Commit

Permalink
Remove obsolete chunk merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 23, 2021
1 parent 3220190 commit 71fe262
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,12 @@ public ChunkCache(GeyserSession session) {
chunks = cache ? new Long2ObjectOpenHashMap<>() : null;
}

public Column addToCache(Column chunk) {
public void addToCache(Column chunk) {
if (!cache) {
return chunk;
return;
}

long chunkPosition = MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ());
Column existingChunk;
if (chunk.getBiomeData() == null // Only consider merging columns if the new chunk isn't a full chunk
&& (existingChunk = chunks.getOrDefault(chunkPosition, null)) != null) { // Column is already present in cache, we can merge with existing
boolean changed = false;
for (int i = 0; i < chunk.getChunks().length; i++) { // The chunks member is final, so chunk.getChunks() will probably be inlined and then completely optimized away
if (chunk.getChunks()[i] != null) {
existingChunk.getChunks()[i] = chunk.getChunks()[i];
changed = true;
}
}
return changed ? existingChunk : null;
} else {
chunks.put(chunkPosition, chunk);
return chunk;
}
chunks.put(MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ()), chunk);
}

public Column getChunk(int chunkX, int chunkZ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ public void translate(ServerChunkDataPacket packet, GeyserSession session) {
ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().getPosition().toInt());
}

// Merge received column with cache on network thread
Column mergedColumn = session.getChunkCache().addToCache(packet.getColumn());
if (mergedColumn == null) { // There were no changes?!?
return;
}
session.getChunkCache().addToCache(packet.getColumn());
Column column = packet.getColumn();

GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
try {
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, mergedColumn);
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column);
ChunkSection[] sections = chunkData.getSections();

// Find highest section
Expand Down Expand Up @@ -90,7 +87,7 @@ public void translate(ServerChunkDataPacket packet, GeyserSession session) {
(section != null ? section : session.getBlockTranslator().getEmptyChunkSection()).writeToNetwork(byteBuf);
}

byteBuf.writeBytes(BiomeTranslator.toBedrockBiome(mergedColumn.getBiomeData())); // Biomes - 256 bytes
byteBuf.writeBytes(BiomeTranslator.toBedrockBiome(column.getBiomeData())); // Biomes - 256 bytes
byteBuf.writeByte(0); // Border blocks - Edu edition only
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now

Expand All @@ -109,8 +106,8 @@ public void translate(ServerChunkDataPacket packet, GeyserSession session) {
LevelChunkPacket levelChunkPacket = new LevelChunkPacket();
levelChunkPacket.setSubChunksLength(sectionCount);
levelChunkPacket.setCachingEnabled(false);
levelChunkPacket.setChunkX(mergedColumn.getX());
levelChunkPacket.setChunkZ(mergedColumn.getZ());
levelChunkPacket.setChunkX(column.getX());
levelChunkPacket.setChunkZ(column.getZ());
levelChunkPacket.setData(payload);
session.sendUpstreamPacket(levelChunkPacket);
} catch (Exception ex) {
Expand Down

0 comments on commit 71fe262

Please sign in to comment.