Skip to content

Commit

Permalink
Add preload chunk version
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Aug 14, 2023
1 parent 2596b8a commit c7cd3bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public int size() {

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

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

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

private void processChunkRequest() {
this.timings.syncChunkSendTimer.startTiming();
Iterator<Map.Entry<Long, Int2ObjectMap<Player>>> it = this.chunkSendQueue.entrySet().iterator();
Iterator<Long2ObjectMap.Entry<Int2ObjectMap<Player>>> it = this.chunkSendQueue.long2ObjectEntrySet().iterator();
while (it.hasNext()) {
Map.Entry<Long, Int2ObjectMap<Player>> entry = it.next();
long index = entry.getKey();
Long2ObjectMap.Entry<Int2ObjectMap<Player>> entry = it.next();
long index = entry.getLongKey();
if (!this.chunkSendTasks.add(index)) {
continue;
}
Expand Down Expand Up @@ -3534,7 +3534,7 @@ private void processChunkRequest() {
}

if (!requestFullChunk) {
this.chunkSendQueue.remove(index);
it.remove();
this.chunkSendTasks.remove(index);

if (!requestSubChunks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.List;
Expand All @@ -48,6 +47,8 @@

@Log4j2
public class ChunkRequestTask extends AsyncTask<Void> {
private static final EnumSet<StaticVersion> PRELOAD_VERSIONS = EnumSet.noneOf(StaticVersion.class);

private static final byte[] EMPTY = new byte[0];

public static final int PADDING_SUB_CHUNK_COUNT = 4;
Expand Down Expand Up @@ -119,8 +120,8 @@ public ChunkRequestTask(Chunk chunk) {
x = chunk.getX();
z = chunk.getZ();
level = chunk.getProvider().getLevel();
Set<StaticVersion> requestedVersions = level.getRequestChunkVersions().keySet();
this.requestedVersions = requestedVersions.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(requestedVersions);
this.requestedVersions = EnumSet.copyOf(PRELOAD_VERSIONS);
this.requestedVersions.addAll(level.getRequestChunkVersions().keySet());
timestamp = chunk.getChanges();
}

Expand Down Expand Up @@ -492,4 +493,8 @@ private static int toValidBiome(int id) {
// make sure we aren't sending bogus biomes - the 1.18.0 client crashes if we do this
return name == null ? EnumBiome.OCEAN.id : id;
}

public static boolean addPreloadVersion(StaticVersion version) {
return PRELOAD_VERSIONS.add(version);
}
}

0 comments on commit c7cd3bb

Please sign in to comment.