mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
remove, add and fix patches
This commit is contained in:
@@ -3952,7 +3952,7 @@ index f4aa10bbd98f514f27224346b3b9332f2218602d..ff319fa2ddea43d5b3c55897b1aaaf9f
|
|||||||
return this.status.compareAndSet(AbstractConsecutiveExecutor.Status.SLEEPING, AbstractConsecutiveExecutor.Status.RUNNING);
|
return this.status.compareAndSet(AbstractConsecutiveExecutor.Status.SLEEPING, AbstractConsecutiveExecutor.Status.RUNNING);
|
||||||
}
|
}
|
||||||
diff --git a/net/minecraft/util/thread/BlockableEventLoop.java b/net/minecraft/util/thread/BlockableEventLoop.java
|
diff --git a/net/minecraft/util/thread/BlockableEventLoop.java b/net/minecraft/util/thread/BlockableEventLoop.java
|
||||||
index 4186615014dccc919e77d5f88c995127984537a6..5e81b60b8198de6123794726c617cebbc36cdc21 100644
|
index 186c1b2e3599770385150eb7acdcd890aa5835eb..e570740d3910573694c462b0a4894349940917a8 100644
|
||||||
--- a/net/minecraft/util/thread/BlockableEventLoop.java
|
--- a/net/minecraft/util/thread/BlockableEventLoop.java
|
||||||
+++ b/net/minecraft/util/thread/BlockableEventLoop.java
|
+++ b/net/minecraft/util/thread/BlockableEventLoop.java
|
||||||
@@ -15,13 +15,9 @@ import java.util.function.Supplier;
|
@@ -15,13 +15,9 @@ import java.util.function.Supplier;
|
||||||
@@ -3967,7 +3967,7 @@ index 4186615014dccc919e77d5f88c995127984537a6..5e81b60b8198de6123794726c617cebb
|
|||||||
|
|
||||||
-public abstract class BlockableEventLoop<R extends Runnable> implements ProfilerMeasured, TaskScheduler<R>, Executor {
|
-public abstract class BlockableEventLoop<R extends Runnable> implements ProfilerMeasured, TaskScheduler<R>, Executor {
|
||||||
+public abstract class BlockableEventLoop<R extends Runnable> implements TaskScheduler<R>, Executor {
|
+public abstract class BlockableEventLoop<R extends Runnable> implements TaskScheduler<R>, Executor {
|
||||||
public static final long BLOCK_TIME_NANOS = 2000000L; // DivineMC - Fix MC-183518
|
public static final long BLOCK_TIME_NANOS = 100000L;
|
||||||
private final String name;
|
private final String name;
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
@@ -30,7 +26,6 @@ public abstract class BlockableEventLoop<R extends Runnable> implements Profiler
|
@@ -30,7 +26,6 @@ public abstract class BlockableEventLoop<R extends Runnable> implements Profiler
|
||||||
@@ -3978,7 +3978,7 @@ index 4186615014dccc919e77d5f88c995127984537a6..5e81b60b8198de6123794726c617cebb
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean shouldRun(R runnable);
|
protected abstract boolean shouldRun(R runnable);
|
||||||
@@ -160,11 +155,6 @@ public abstract class BlockableEventLoop<R extends Runnable> implements Profiler
|
@@ -161,11 +156,6 @@ public abstract class BlockableEventLoop<R extends Runnable> implements Profiler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Chunk System Optimizations
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
|
diff --git a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
|
||||||
index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..b588449cfe766c14a0cf4ea9640b04a51bbcf433 100644
|
index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..78e3c49a233dc6bed558458d555fe740a8cc839e 100644
|
||||||
--- a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
|
--- a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
|
||||||
+++ b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
|
+++ b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
|
||||||
@@ -59,12 +59,15 @@ public final class NearbyPlayers {
|
@@ -59,12 +59,15 @@ public final class NearbyPlayers {
|
||||||
@@ -28,75 +28,83 @@ index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..b588449cfe766c14a0cf4ea9640b04a5
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +191,10 @@ public final class NearbyPlayers {
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
||||||
final ReferenceList<ServerPlayer> list = this.players[idx];
|
index ba20e87d2105ce53cdaf4049de2388d05fcd1b56..131e673c8eaa2afa801de5913982259d48908358 100644
|
||||||
if (list == null) {
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
||||||
++this.nonEmptyLists;
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
||||||
- final ReferenceList<ServerPlayer> players = (this.players[idx] = new ReferenceList<>(EMPTY_PLAYERS_ARRAY));
|
@@ -383,6 +383,14 @@ public final class ChunkEntitySlices {
|
||||||
|
|
||||||
|
private E[] storage;
|
||||||
|
private int size;
|
||||||
|
+ private it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap entityToIndex = null; // DivineMC - Chunk System optimization
|
||||||
|
+
|
||||||
+ // DivineMC start - Chunk System optimization
|
+ // DivineMC start - Chunk System optimization
|
||||||
+ this.players[idx] = new ReferenceList<>(EMPTY_PLAYERS_ARRAY);
|
+ private void setupIndexMap() {
|
||||||
+ final ReferenceList<ServerPlayer> players = this.players[idx];
|
+ this.entityToIndex = new it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap(2, 0.8f);
|
||||||
+ // DivineMC end - Chunk System optimization
|
+ this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE);
|
||||||
this.nearbyPlayers.directByChunk[idx].put(this.chunkKey, players);
|
+ }
|
||||||
players.add(player);
|
|
||||||
return;
|
|
||||||
diff --git a/ca/spottedleaf/moonrise/patches/blockstate_propertyaccess/util/ZeroCollidingReferenceStateTable.java b/ca/spottedleaf/moonrise/patches/blockstate_propertyaccess/util/ZeroCollidingReferenceStateTable.java
|
|
||||||
index 866f38eb0f379ffbe2888023a7d1c290f521a231..08666b4aa1c7663861dc361f60e6f1cc46694521 100644
|
|
||||||
--- a/ca/spottedleaf/moonrise/patches/blockstate_propertyaccess/util/ZeroCollidingReferenceStateTable.java
|
|
||||||
+++ b/ca/spottedleaf/moonrise/patches/blockstate_propertyaccess/util/ZeroCollidingReferenceStateTable.java
|
|
||||||
@@ -21,13 +21,15 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|
||||||
|
|
||||||
public final class ZeroCollidingReferenceStateTable<O, S> {
|
|
||||||
|
|
||||||
- private final Int2ObjectOpenHashMap<Indexer> propertyToIndexer;
|
|
||||||
+ private final it.unimi.dsi.fastutil.ints.Int2ObjectMap<Indexer> propertyToIndexer; // DivineMC - Chunk System optimization
|
|
||||||
private S[] lookup;
|
|
||||||
private final Collection<Property<?>> properties;
|
|
||||||
|
|
||||||
public ZeroCollidingReferenceStateTable(final Collection<Property<?>> properties) {
|
|
||||||
- this.propertyToIndexer = new Int2ObjectOpenHashMap<>(properties.size());
|
|
||||||
- this.properties = new ReferenceArrayList<>(properties);
|
|
||||||
+ // DivineMC start - Chunk System optimization
|
|
||||||
+ this.propertyToIndexer = it.unimi.dsi.fastutil.ints.Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>(properties.size()));
|
|
||||||
+ this.properties = it.unimi.dsi.fastutil.objects.ReferenceLists.synchronize(new ReferenceArrayList<>(properties));
|
|
||||||
+ // DivineMC end - Chunk System optimization
|
+ // DivineMC end - Chunk System optimization
|
||||||
|
|
||||||
final List<Property<?>> sortedProperties = new ArrayList<>(properties);
|
public BasicEntityList() {
|
||||||
|
this(0);
|
||||||
@@ -77,11 +79,11 @@ public final class ZeroCollidingReferenceStateTable<O, S> {
|
@@ -403,6 +411,7 @@ public final class ChunkEntitySlices {
|
||||||
return ret;
|
private void resize() {
|
||||||
|
if (this.storage == EMPTY) {
|
||||||
|
this.storage = (E[])new Entity[DEFAULT_CAPACITY];
|
||||||
|
+ this.setupIndexMap(); // DivineMC - Chunk System optimization
|
||||||
|
} else {
|
||||||
|
this.storage = Arrays.copyOf(this.storage, this.storage.length * 2);
|
||||||
|
}
|
||||||
|
@@ -416,6 +425,7 @@ public final class ChunkEntitySlices {
|
||||||
|
} else {
|
||||||
|
this.storage[idx] = entity;
|
||||||
|
}
|
||||||
|
+ this.entityToIndex.put(entity.getId(), idx); // DivineMC - Chunk System optimization
|
||||||
}
|
}
|
||||||
|
|
||||||
- public boolean isLoaded() {
|
public int indexOf(final E entity) {
|
||||||
+ public synchronized boolean isLoaded() { // DivineMC - Chunk System optimization
|
@@ -431,24 +441,31 @@ public final class ChunkEntitySlices {
|
||||||
return this.lookup != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- public void loadInTable(final Map<Map<Property<?>, Comparable<?>>, S> universe) {
|
public boolean remove(final E entity) {
|
||||||
+ public synchronized void loadInTable(final Map<Map<Property<?>, Comparable<?>>, S> universe) { // DivineMC - Chunk System optimization
|
- final int idx = this.indexOf(entity);
|
||||||
if (this.lookup != null) {
|
- if (idx == -1) {
|
||||||
throw new IllegalStateException();
|
+ // DivineMC start - Chunk System optimization - by Sakura, copied from EntityList
|
||||||
}
|
+ if (this.entityToIndex == null) {
|
||||||
@@ -117,7 +119,7 @@ public final class ZeroCollidingReferenceStateTable<O, S> {
|
return false;
|
||||||
return ((PropertyAccess<T>)property).moonrise$getById((int)modded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- public <T extends Comparable<T>> S set(final long index, final Property<T> property, final T with) {
|
- final int size = --this.size;
|
||||||
+ public synchronized <T extends Comparable<T>> S set(final long index, final Property<T> property, final T with) { // DivineMC - Chunk System optimization
|
- final E[] storage = this.storage;
|
||||||
final int newValueId = ((PropertyAccess<T>)property).moonrise$getIdFor(with);
|
- if (idx != size) {
|
||||||
if (newValueId < 0) {
|
- System.arraycopy(storage, idx + 1, storage, idx, size - idx);
|
||||||
return null;
|
+ final int index = this.entityToIndex.remove(entity.getId());
|
||||||
@@ -139,7 +141,7 @@ public final class ZeroCollidingReferenceStateTable<O, S> {
|
+ if (index == Integer.MIN_VALUE) {
|
||||||
return this.lookup[(int)newIndex];
|
+ return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
- storage[size] = null;
|
||||||
|
+ final int endIndex = --this.size;
|
||||||
|
+ final E end = this.storage[endIndex];
|
||||||
|
+ if (index != endIndex) {
|
||||||
|
+ // not empty after this call
|
||||||
|
+ this.entityToIndex.put(end.getId(), index); // update index
|
||||||
|
+ }
|
||||||
|
+ this.storage[index] = end;
|
||||||
|
+ this.storage[endIndex] = null;
|
||||||
|
+ // DivineMC end - Chunk System optimization - by Sakura, copied from EntityList
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has(final E entity) {
|
||||||
|
- return this.indexOf(entity) != -1;
|
||||||
|
+ return this.entityToIndex != null && this.entityToIndex.containsKey(entity.getId()); // DivineMC - Chunk System optimization
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- public <T extends Comparable<T>> S trySet(final long index, final Property<T> property, final T with, final S dfl) {
|
|
||||||
+ public synchronized <T extends Comparable<T>> S trySet(final long index, final Property<T> property, final T with, final S dfl) { // DivineMC - Chunk System optimization
|
|
||||||
final Indexer indexer = this.propertyToIndexer.get(((PropertyAccess<T>)property).moonrise$getId());
|
|
||||||
if (indexer == null) {
|
|
||||||
return dfl;
|
|
||||||
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
||||||
index 7a52c42845bd74d0bb7649f87764aba12f442f02..78f2d7c698a4f2c21a473627c3017a9751f80cf1 100644
|
index 7a52c42845bd74d0bb7649f87764aba12f442f02..03ab44b69725a18ed567826e4417f1d6701f08c9 100644
|
||||||
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
||||||
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
||||||
@@ -187,13 +187,13 @@ public final class RegionizedPlayerChunkLoader {
|
@@ -187,13 +187,13 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
@@ -115,32 +123,23 @@ index 7a52c42845bd74d0bb7649f87764aba12f442f02..78f2d7c698a4f2c21a473627c3017a97
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayer(final ServerPlayer player) {
|
public void updatePlayer(final ServerPlayer player) {
|
||||||
@@ -299,7 +299,7 @@ public final class RegionizedPlayerChunkLoader {
|
@@ -304,7 +304,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
- public void tick() {
|
|
||||||
+ public synchronized void tick() { // DivineMC - Chunk System optimization - synchronized
|
|
||||||
TickThread.ensureTickThread("Cannot tick player chunk loader async");
|
|
||||||
long currTime = System.nanoTime();
|
long currTime = System.nanoTime();
|
||||||
for (final ServerPlayer player : new java.util.ArrayList<>(this.world.players())) {
|
for (final ServerPlayer player : new java.util.ArrayList<>(this.world.players())) {
|
||||||
@@ -310,6 +310,7 @@ public final class RegionizedPlayerChunkLoader {
|
final PlayerChunkLoaderData loader = ((ChunkSystemServerPlayer)player).moonrise$getChunkLoader();
|
||||||
}
|
- if (loader == null || loader.removed || loader.world != this.world) {
|
||||||
loader.update(); // can't invoke plugin logic
|
+ if (loader == null || loader.removed || loader.world != this.world || !loader.canTick) { // DivineMC - Chunk System optimization
|
||||||
loader.updateQueues(currTime);
|
// not our problem anymore
|
||||||
+ player.connection.resumeFlushing(); // DivineMC - Chunk System optimization
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -323,6 +323,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
|
|
||||||
@@ -360,7 +361,7 @@ public final class RegionizedPlayerChunkLoader {
|
private final ServerPlayer player;
|
||||||
GENERATED_TICKET_LEVEL,
|
private final ServerLevel world;
|
||||||
TICK_TICKET_LEVEL
|
+ public volatile boolean canTick; // DivineMC - Chunk System optimization
|
||||||
};
|
|
||||||
- private final Long2ByteOpenHashMap chunkTicketStage = new Long2ByteOpenHashMap();
|
private int lastChunkX = Integer.MIN_VALUE;
|
||||||
+ private final it.unimi.dsi.fastutil.longs.Long2ByteMap chunkTicketStage = it.unimi.dsi.fastutil.longs.Long2ByteMaps.synchronize(new Long2ByteOpenHashMap()); // DivineMC - Chunk System optimization
|
private int lastChunkZ = Integer.MIN_VALUE;
|
||||||
{
|
|
||||||
this.chunkTicketStage.defaultReturnValue(CHUNK_TICKET_STAGE_NONE);
|
|
||||||
}
|
|
||||||
@@ -382,10 +383,19 @@ public final class RegionizedPlayerChunkLoader {
|
@@ -382,10 +383,19 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
final int centerX = PlayerChunkLoaderData.this.lastChunkX;
|
final int centerX = PlayerChunkLoaderData.this.lastChunkX;
|
||||||
final int centerZ = PlayerChunkLoaderData.this.lastChunkZ;
|
final int centerZ = PlayerChunkLoaderData.this.lastChunkZ;
|
||||||
@@ -165,60 +164,31 @@ index 7a52c42845bd74d0bb7649f87764aba12f442f02..78f2d7c698a4f2c21a473627c3017a97
|
|||||||
};
|
};
|
||||||
private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
|
private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
|
||||||
private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
|
private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
|
||||||
@@ -488,7 +498,7 @@ public final class RegionizedPlayerChunkLoader {
|
@@ -853,6 +863,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void add() {
|
||||||
- protected void removeCallback(final PlayerChunkLoaderData parameter, final int chunkX, final int chunkZ) {
|
+ this.canTick = false; // DivineMC - Chunk System optimization
|
||||||
+ protected synchronized void removeCallback(final PlayerChunkLoaderData parameter, final int chunkX, final int chunkZ) { // DivineMC - Chunk System optimization
|
TickThread.ensureTickThread(this.player, "Cannot add player asynchronously");
|
||||||
final long chunk = CoordinateUtils.getChunkKey(chunkX, chunkZ);
|
|
||||||
// note: by the time this is called, the tick cleanup should have ran - so, if the chunk is at
|
|
||||||
// the tick stage it was deemed in range for loading. Thus, we need to move it to generated
|
|
||||||
@@ -622,7 +632,7 @@ public final class RegionizedPlayerChunkLoader {
|
|
||||||
return Math.max(Math.abs(dx), Math.abs(dz)) <= this.lastTickDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
- private boolean areNeighboursGenerated(final int chunkX, final int chunkZ, final int radius) {
|
|
||||||
+ private synchronized boolean areNeighboursGenerated(final int chunkX, final int chunkZ, final int radius) { // DivineMC - Chunk System optimization
|
|
||||||
for (int dz = -radius; dz <= radius; ++dz) {
|
|
||||||
for (int dx = -radius; dx <= radius; ++dx) {
|
|
||||||
if ((dx | dz) == 0) {
|
|
||||||
@@ -641,10 +651,10 @@ public final class RegionizedPlayerChunkLoader {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
- void updateQueues(final long time) {
|
|
||||||
+ synchronized void updateQueues(final long time) { // DivineMC - Chunk System optimization
|
|
||||||
TickThread.ensureTickThread(this.player, "Cannot tick player chunk loader async");
|
|
||||||
if (this.removed) {
|
if (this.removed) {
|
||||||
- throw new IllegalStateException("Ticking removed player chunk loader");
|
throw new IllegalStateException("Adding removed player chunk loader");
|
||||||
+ return; // DivineMC - Chunk System optimization - just return
|
@@ -892,6 +903,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
}
|
|
||||||
// update rate limits
|
// now we can update
|
||||||
final double loadRate = this.getMaxChunkLoadRate();
|
this.update();
|
||||||
@@ -907,10 +917,10 @@ public final class RegionizedPlayerChunkLoader {
|
+ this.canTick = true; // DivineMC - Chunk System optimization
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- void update() {
|
private boolean isLoadedChunkGeneratable(final int chunkX, final int chunkZ) {
|
||||||
+ synchronized void update() { // DivineMC - Chunk System optimization
|
@@ -1060,6 +1072,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
TickThread.ensureTickThread(this.player, "Cannot update player asynchronously");
|
|
||||||
if (this.removed) {
|
|
||||||
- throw new IllegalStateException("Updating removed player chunk loader");
|
|
||||||
+ return; // DivineMC - Chunk System optimization - just return
|
|
||||||
}
|
|
||||||
final ViewDistances playerDistances = ((ChunkSystemServerPlayer)this.player).moonrise$getViewDistanceHolder().getViewDistances();
|
|
||||||
final ViewDistances worldDistances = ((ChunkSystemServerLevel)this.world).moonrise$getViewDistanceHolder().getViewDistances();
|
|
||||||
@@ -1059,7 +1069,7 @@ public final class RegionizedPlayerChunkLoader {
|
|
||||||
this.flushDelayedTicketOps();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- void remove() {
|
void remove() {
|
||||||
+ synchronized void remove() { // DivineMC - Chunk System optimization
|
+ this.canTick = false; // DivineMC - Chunk System optimization
|
||||||
TickThread.ensureTickThread(this.player, "Cannot add player asynchronously");
|
TickThread.ensureTickThread(this.player, "Cannot add player asynchronously");
|
||||||
if (this.removed) {
|
if (this.removed) {
|
||||||
throw new IllegalStateException("Removing removed player chunk loader");
|
throw new IllegalStateException("Removing removed player chunk loader");
|
||||||
@@ -1087,7 +1097,7 @@ public final class RegionizedPlayerChunkLoader {
|
@@ -1087,7 +1100,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongOpenHashSet getSentChunksRaw() {
|
public LongOpenHashSet getSentChunksRaw() {
|
||||||
@@ -866,6 +836,18 @@ index 95ed5a0ff3f0588f625ba48a5fee3aafbab9d13f..f2fd6d5eb024f646875868c441eb2da2
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static final class LoadDataFromDiskTask {
|
protected static final class LoadDataFromDiskTask {
|
||||||
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/util/ParallelSearchRadiusIteration.java b/ca/spottedleaf/moonrise/patches/chunk_system/util/ParallelSearchRadiusIteration.java
|
||||||
|
index 93fd23027c00cef76562098306737272fda1350a..44e443768f5163454fd11425afd3bc07b2c0c6c2 100644
|
||||||
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/util/ParallelSearchRadiusIteration.java
|
||||||
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/util/ParallelSearchRadiusIteration.java
|
||||||
|
@@ -23,6 +23,7 @@ public final class ParallelSearchRadiusIteration {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long[] getSearchIteration(final int radius) {
|
||||||
|
+ if (radius >= SEARCH_RADIUS_ITERATION_LIST.length) return SEARCH_RADIUS_ITERATION_LIST[SEARCH_RADIUS_ITERATION_LIST.length - 1]; // DivineMC - Chunk System Optimizations
|
||||||
|
return SEARCH_RADIUS_ITERATION_LIST[radius];
|
||||||
|
}
|
||||||
|
|
||||||
diff --git a/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java b/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java b/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java
|
||||||
index 6d1fe8028739145b11fce98ad62b2f8044299548..2cd1197fa0d15e19749409cc857a0254de444ba5 100644
|
index 6d1fe8028739145b11fce98ad62b2f8044299548..2cd1197fa0d15e19749409cc857a0254de444ba5 100644
|
||||||
--- a/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java
|
--- a/ca/spottedleaf/moonrise/patches/chunk_tick_iteration/ChunkTickConstants.java
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
|
||||||
|
Date: Fri, 13 Sep 2024 14:32:32 -0700
|
||||||
|
Subject: [PATCH] Paper PR: Add ticket on player join to avoid chunk
|
||||||
|
load-unload-load cycle
|
||||||
|
|
||||||
|
Original license: GPLv3
|
||||||
|
Original project: https://github.com/PaperMC/Paper
|
||||||
|
Paper pull request: https://github.com/PaperMC/Paper/pull/11398
|
||||||
|
|
||||||
|
Adding the entity will add and then immediately remove an entity load ticket, which would result in the chunk loading and then unloading before being loaded again once the player chunk loader reacts (delay can vary based on rate limit configs)
|
||||||
|
By adding a ticket with a short removal delay we attempt to keep the chunk loaded until the player chunk loader reacts, but this is not a guarantee due to the aforementioned rate limit configs. Plugins should still handle load/unload events as normal, however this will reduce redundant calls.
|
||||||
|
The delay is currently set to 2 seconds, however, we may want to adjust this before merging (for example the player chunk unload delay is 5 seconds)
|
||||||
|
|
||||||
|
This patch fixes PaperMC/Paper#9581
|
||||||
|
|
||||||
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
||||||
|
index 4cf581e618a774cac010f593bacc7f221f7dea78..a1d07b6dcce9af1a8cd715d2b0aa99e0e575af38 100644
|
||||||
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
||||||
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
|
||||||
|
@@ -48,6 +48,7 @@ public final class RegionizedPlayerChunkLoader {
|
||||||
|
|
||||||
|
public static final TicketType PLAYER_TICKET = ChunkSystemTicketType.create("chunk_system:player_ticket", Long::compareTo);
|
||||||
|
public static final TicketType PLAYER_TICKET_DELAYED = ChunkSystemTicketType.create("chunk_system:player_ticket_delayed", Long::compareTo, 5L * 20L);
|
||||||
|
+ public static final TicketType PLAYER_JOIN = ChunkSystemTicketType.create("chunk_system:player_join", (a, b) -> 0, 5 * 20); // Paper - Add ticket on player join to avoid chunk load-unload-load cycle
|
||||||
|
|
||||||
|
public static final int GENERATED_TICKET_LEVEL = ChunkHolderManager.FULL_LOADED_TICKET_LEVEL;
|
||||||
|
public static final int LOADED_TICKET_LEVEL = ChunkTaskScheduler.getTicketLevel(ChunkStatus.EMPTY);
|
||||||
|
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
||||||
|
index 8923a30daf515262e4bdbfbd55e3cb827092979c..de66143a2f093b43233c12cc0ea384a51bdf4840 100644
|
||||||
|
--- a/net/minecraft/server/players/PlayerList.java
|
||||||
|
+++ b/net/minecraft/server/players/PlayerList.java
|
||||||
|
@@ -315,6 +315,13 @@ public abstract class PlayerList {
|
||||||
|
// this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player))); // CraftBukkit - replaced with loop below
|
||||||
|
// Paper start - Fire PlayerJoinEvent when Player is actually ready; correctly register player BEFORE PlayerJoinEvent, so the entity is valid and doesn't require tick delay hacks
|
||||||
|
player.supressTrackerForLogin = true;
|
||||||
|
+ // Paper start - Add ticket on player join to avoid chunk load-unload-load cycle
|
||||||
|
+ serverLevel.moonrise$getChunkTaskScheduler().chunkHolderManager.addTicketAtLevel(
|
||||||
|
+ ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PLAYER_JOIN,
|
||||||
|
+ player.chunkPosition(),
|
||||||
|
+ ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.TICK_TICKET_LEVEL,
|
||||||
|
+ net.minecraft.util.Unit.INSTANCE);
|
||||||
|
+ // Paper end - Add ticket on player join to avoid chunk load-unload-load cycle
|
||||||
|
serverLevel.addNewPlayer(player);
|
||||||
|
this.server.getCustomBossEvents().onPlayerConnect(player); // see commented out section below serverLevel.addPlayerJoin(player);
|
||||||
|
// Paper end - Fire PlayerJoinEvent when Player is actually ready
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
--- a/net/minecraft/util/thread/BlockableEventLoop.java
|
|
||||||
+++ b/net/minecraft/util/thread/BlockableEventLoop.java
|
|
||||||
@@ -22,7 +_,7 @@
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
public abstract class BlockableEventLoop<R extends Runnable> implements ProfilerMeasured, TaskScheduler<R>, Executor {
|
|
||||||
- public static final long BLOCK_TIME_NANOS = 100000L;
|
|
||||||
+ public static final long BLOCK_TIME_NANOS = 2000000L; // DivineMC - Fix MC-183518
|
|
||||||
private final String name;
|
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
|
||||||
private final Queue<R> pendingRunnables = Queues.newConcurrentLinkedQueue();
|
|
||||||
@@ -146,8 +_,7 @@
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void waitForTasks() {
|
|
||||||
- Thread.yield();
|
|
||||||
- LockSupport.parkNanos("waiting for tasks", 100000L);
|
|
||||||
+ LockSupport.parkNanos("waiting for tasks", 2000000L); // DivineMC - Fix MC-183518
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doRunTask(R task) {
|
|
||||||
Reference in New Issue
Block a user