Skip to content

Commit c7cd3bb

Browse files
committed
Add preload chunk version
1 parent 2596b8a commit c7cd3bb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/main/java/cn/nukkit/level/Level.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public int size() {
251251

252252
private final Long2ObjectMap<Int2ObjectMap<Player>> subChunkSendQueue = new Long2ObjectOpenHashMap<>();
253253

254-
private final ConcurrentMap<Long, Int2ObjectMap<Player>> chunkSendQueue = new ConcurrentHashMap<>();
254+
private final Long2ObjectMap<Int2ObjectMap<Player>> chunkSendQueue = new Long2ObjectOpenHashMap<>();
255255
private final LongSet chunkSendTasks = new LongOpenHashSet();
256256

257257
private final Long2BooleanMap chunkPopulationQueue = new Long2BooleanOpenHashMap();
@@ -3431,10 +3431,10 @@ private void sendChunk(int x, int z, long index, int subChunkCount, ChunkBlobCac
34313431

34323432
private void processChunkRequest() {
34333433
this.timings.syncChunkSendTimer.startTiming();
3434-
Iterator<Map.Entry<Long, Int2ObjectMap<Player>>> it = this.chunkSendQueue.entrySet().iterator();
3434+
Iterator<Long2ObjectMap.Entry<Int2ObjectMap<Player>>> it = this.chunkSendQueue.long2ObjectEntrySet().iterator();
34353435
while (it.hasNext()) {
3436-
Map.Entry<Long, Int2ObjectMap<Player>> entry = it.next();
3437-
long index = entry.getKey();
3436+
Long2ObjectMap.Entry<Int2ObjectMap<Player>> entry = it.next();
3437+
long index = entry.getLongKey();
34383438
if (!this.chunkSendTasks.add(index)) {
34393439
continue;
34403440
}
@@ -3534,7 +3534,7 @@ private void processChunkRequest() {
35343534
}
35353535

35363536
if (!requestFullChunk) {
3537-
this.chunkSendQueue.remove(index);
3537+
it.remove();
35383538
this.chunkSendTasks.remove(index);
35393539

35403540
if (!requestSubChunks) {

src/main/java/cn/nukkit/level/format/generic/ChunkRequestTask.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.nio.file.Paths;
3737
import java.nio.file.StandardOpenOption;
3838
import java.util.Arrays;
39-
import java.util.Collections;
4039
import java.util.EnumMap;
4140
import java.util.EnumSet;
4241
import java.util.List;
@@ -48,6 +47,8 @@
4847

4948
@Log4j2
5049
public class ChunkRequestTask extends AsyncTask<Void> {
50+
private static final EnumSet<StaticVersion> PRELOAD_VERSIONS = EnumSet.noneOf(StaticVersion.class);
51+
5152
private static final byte[] EMPTY = new byte[0];
5253

5354
public static final int PADDING_SUB_CHUNK_COUNT = 4;
@@ -119,8 +120,8 @@ public ChunkRequestTask(Chunk chunk) {
119120
x = chunk.getX();
120121
z = chunk.getZ();
121122
level = chunk.getProvider().getLevel();
122-
Set<StaticVersion> requestedVersions = level.getRequestChunkVersions().keySet();
123-
this.requestedVersions = requestedVersions.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(requestedVersions);
123+
this.requestedVersions = EnumSet.copyOf(PRELOAD_VERSIONS);
124+
this.requestedVersions.addAll(level.getRequestChunkVersions().keySet());
124125
timestamp = chunk.getChanges();
125126
}
126127

@@ -492,4 +493,8 @@ private static int toValidBiome(int id) {
492493
// make sure we aren't sending bogus biomes - the 1.18.0 client crashes if we do this
493494
return name == null ? EnumBiome.OCEAN.id : id;
494495
}
496+
497+
public static boolean addPreloadVersion(StaticVersion version) {
498+
return PRELOAD_VERSIONS.add(version);
499+
}
495500
}

0 commit comments

Comments
 (0)