mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Remove obsolete chunk merging
This commit is contained in:
parent
3220190904
commit
71fe2621fc
2 changed files with 9 additions and 27 deletions
|
@ -46,27 +46,12 @@ public class ChunkCache {
|
||||||
chunks = cache ? new Long2ObjectOpenHashMap<>() : null;
|
chunks = cache ? new Long2ObjectOpenHashMap<>() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Column addToCache(Column chunk) {
|
public void addToCache(Column chunk) {
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
return chunk;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long chunkPosition = MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ());
|
chunks.put(MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ()), chunk);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Column getChunk(int chunkX, int chunkZ) {
|
public Column getChunk(int chunkX, int chunkZ) {
|
||||||
|
|
|
@ -52,15 +52,12 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
||||||
ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().getPosition().toInt());
|
ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().getPosition().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge received column with cache on network thread
|
session.getChunkCache().addToCache(packet.getColumn());
|
||||||
Column mergedColumn = session.getChunkCache().addToCache(packet.getColumn());
|
Column column = packet.getColumn();
|
||||||
if (mergedColumn == null) { // There were no changes?!?
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
|
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
|
||||||
try {
|
try {
|
||||||
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, mergedColumn);
|
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column);
|
||||||
ChunkSection[] sections = chunkData.getSections();
|
ChunkSection[] sections = chunkData.getSections();
|
||||||
|
|
||||||
// Find highest section
|
// Find highest section
|
||||||
|
@ -90,7 +87,7 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
||||||
(section != null ? section : session.getBlockTranslator().getEmptyChunkSection()).writeToNetwork(byteBuf);
|
(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
|
byteBuf.writeByte(0); // Border blocks - Edu edition only
|
||||||
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
||||||
|
|
||||||
|
@ -109,8 +106,8 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
||||||
LevelChunkPacket levelChunkPacket = new LevelChunkPacket();
|
LevelChunkPacket levelChunkPacket = new LevelChunkPacket();
|
||||||
levelChunkPacket.setSubChunksLength(sectionCount);
|
levelChunkPacket.setSubChunksLength(sectionCount);
|
||||||
levelChunkPacket.setCachingEnabled(false);
|
levelChunkPacket.setCachingEnabled(false);
|
||||||
levelChunkPacket.setChunkX(mergedColumn.getX());
|
levelChunkPacket.setChunkX(column.getX());
|
||||||
levelChunkPacket.setChunkZ(mergedColumn.getZ());
|
levelChunkPacket.setChunkZ(column.getZ());
|
||||||
levelChunkPacket.setData(payload);
|
levelChunkPacket.setData(payload);
|
||||||
session.sendUpstreamPacket(levelChunkPacket);
|
session.sendUpstreamPacket(levelChunkPacket);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
Loading…
Reference in a new issue