9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-27 10:59:16 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0155-Optimize-ThreadedTicketLevelPropagator.patch
2025-04-29 23:30:09 +02:00

71 lines
4.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Mon, 14 Apr 2025 14:36:57 +0200
Subject: [PATCH] Optimize ThreadedTicketLevelPropagator
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java
index 01598347ea545f2ff2ac337086345d7369a64520..fbea9d83b7458760d4b1b5e1c8bd77ff46072b97 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ThreadedTicketLevelPropagator.java
@@ -998,6 +998,7 @@ public abstract class ThreadedTicketLevelPropagator {
final int decodeOffsetZ = -this.encodeOffsetZ;
final int encodeOffset = this.coordinateOffset;
final int sectionOffset = this.sectionIndexOffset;
+ final Section[] sectionsArray = this.sections;
final Long2ByteLinkedOpenHashMap updatedPositions = this.updatedPositions;
@@ -1012,13 +1013,23 @@ public abstract class ThreadedTicketLevelPropagator {
int propagateDirectionBitset = (int)(queueValue >>> (COORDINATE_BITS + COORDINATE_BITS + LEVEL_BITS)) & ((1 << 16) - 1);
if ((queueValue & FLAG_RECHECK_LEVEL) != 0L) {
- if (this.getLevel(posX, posZ) != propagatedLevel) {
+ final int sectionX = posX >> SECTION_SHIFT;
+ final int sectionZ = posZ >> SECTION_SHIFT;
+ final Section section = sectionsArray[sectionX + (sectionZ * SECTION_CACHE_WIDTH) + sectionOffset];
+ final int localIdx = (posX & (SECTION_SIZE - 1)) | ((posZ & (SECTION_SIZE - 1)) << SECTION_SHIFT);
+ if ((section.levels[localIdx] & 0xFF) != propagatedLevel) {
// not at the level we expect, so something changed.
continue;
}
} else if ((queueValue & FLAG_WRITE_LEVEL) != 0L) {
// these are used to restore sources after a propagation decrease
- this.setLevel(posX, posZ, propagatedLevel);
+ final int sectionX = posX >> SECTION_SHIFT;
+ final int sectionZ = posZ >> SECTION_SHIFT;
+ final Section section = sectionsArray[sectionX + (sectionZ * SECTION_CACHE_WIDTH) + sectionOffset];
+ final int localIdx = (posX & (SECTION_SIZE - 1)) | ((posZ & (SECTION_SIZE - 1)) << SECTION_SHIFT);
+ final short currentLevel = section.levels[localIdx];
+ section.levels[localIdx] = (short) ((currentLevel & ~0xFF) | (propagatedLevel & 0xFF));
+ updatedPositions.put(CoordinateUtils.getChunkKey(posX, posZ), (byte) propagatedLevel);
}
// this bitset represents the values that we have not propagated to
@@ -1093,7 +1104,7 @@ public abstract class ThreadedTicketLevelPropagator {
currentPropagation ^= (bitsetLine1 | bitsetLine2 | bitsetLine3);
// now try to propagate
- final Section section = this.sections[sectionIndex];
+ final Section section = sectionsArray[sectionIndex];
// lower 8 bits are current level, next upper 7 bits are source level, next 1 bit is updated source flag
final short currentStoredLevel = section.levels[localIndex];
@@ -1144,6 +1155,7 @@ public abstract class ThreadedTicketLevelPropagator {
final int decodeOffsetZ = -this.encodeOffsetZ;
final int encodeOffset = this.coordinateOffset;
final int sectionOffset = this.sectionIndexOffset;
+ final Section[] sectionsArray = this.sections;
final Long2ByteLinkedOpenHashMap updatedPositions = this.updatedPositions;
@@ -1227,7 +1239,7 @@ public abstract class ThreadedTicketLevelPropagator {
final long bitsetLine3 = currentPropagation & (7L << (start + (8 + 8)));
// now try to propagate
- final Section section = this.sections[sectionIndex];
+ final Section section = sectionsArray[sectionIndex];
// lower 8 bits are current level, next upper 7 bits are source level, next 1 bit is updated source flag
final short currentStoredLevel = section.levels[localIndex];