mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +00:00
128 lines
7.5 KiB
Diff
128 lines
7.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Wed, 23 Nov 2022 16:45:45 +0100
|
|
Subject: [PATCH] Optimize random calls in chunk ticking
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
This patch is based on the following patch:
|
|
"Optimize random calls in chunk ticking"
|
|
By: Paul Sauve <paul@technove.co>
|
|
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
The patch also received the following subsequent modification:
|
|
By: Kevin Raneri <kevin.raneri@gmail.com>
|
|
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
* Airplane description *
|
|
|
|
Especially at over 30,000 chunks these random calls are fairly heavy. We
|
|
use a different method here for checking lightning, and for checking
|
|
ice.
|
|
|
|
Lightning: Each chunk now keeps an int of how many ticks until the
|
|
lightning should strike. This int is a random number from 0 to 100000 * 2,
|
|
the multiplication is required to keep the probability the same.
|
|
|
|
Ice and snow: We just generate a single random number 0-16 and increment
|
|
it, while checking if it's 0 for the current chunk.
|
|
|
|
Depending on configuration for things that tick in a chunk, this is a
|
|
5-10% improvement.
|
|
|
|
* Airplane copyright *
|
|
|
|
Airplane
|
|
Copyright (C) 2020 Technove LLC
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
|
index 9500fc2f841819b0d40e8a6e48353bb28b6dbe49..5c8d76b80c6cefd87088282e59f5f0f72a4f1611 100644
|
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -495,6 +495,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
|
long l = gameTime - this.lastInhabitedUpdate;
|
|
this.lastInhabitedUpdate = gameTime;
|
|
if (!this.level.isDebug()) {
|
|
+ this.level.resetIceAndSnowTick(); // Gale - Airplane - optimize random calls in chunk ticking - reset ice & snow tick random
|
|
if (this.level.tickRateManager().runsNormally()) {
|
|
List<LevelChunk> list = this.tickingChunks;
|
|
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index e43fa760210cb4c956b2143a65452eecf5f923f4..b35fe7112f2ad94e85e98931c403b3ffa8608382 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -890,13 +890,15 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
// Paper end - optimise random ticking
|
|
|
|
+ private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.simpleRandom.nextInt(16); } // Gale - Airplane - optimize random calls in chunk ticking
|
|
+
|
|
public void tickChunk(LevelChunk chunk, int randomTickSpeed) {
|
|
final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom; // Paper - optimise random ticking
|
|
ChunkPos pos = chunk.getPos();
|
|
boolean isRaining = this.isRaining();
|
|
int minBlockX = pos.getMinBlockX();
|
|
int minBlockZ = pos.getMinBlockZ();
|
|
- if (!this.paperConfig().environment.disableThunder && isRaining && this.isThundering() && this.spigotConfig.thunderChance > 0 && simpleRandom.nextInt(this.spigotConfig.thunderChance) == 0) { // Spigot // Paper - Option to disable thunder // Paper - optimise random ticking
|
|
+ if (!this.paperConfig().environment.disableThunder && isRaining && this.isThundering() && this.spigotConfig.thunderChance > 0 /*&& simpleRandom.nextInt(this.spigotConfig.thunderChance) == 0*/ && chunk.shouldDoLightning(this.random)) { // Spigot // Paper - Option to disable thunder // Paper - optimise random ticking // Gale - Airplane - optimize random calls in chunk ticking - replace random with shouldDoLightning
|
|
BlockPos blockPos = this.findLightningTargetAround(this.getBlockRandomPos(minBlockX, 0, minBlockZ, 15));
|
|
if (this.isRainingAt(blockPos)) {
|
|
DifficultyInstance currentDifficultyAt = this.getCurrentDifficultyAt(blockPos);
|
|
@@ -922,7 +924,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
}
|
|
|
|
- if (!this.paperConfig().environment.disableIceAndSnow) { // Paper - Option to disable ice and snow
|
|
+ if (!this.paperConfig().environment.disableIceAndSnow && (this.currentIceAndSnowTick++ & 15) == 0) { // Paper - Option to disable ice and snow // Gale - Airplane - optimize random calls in chunk ticking - optimize further random ticking
|
|
for (int i = 0; i < randomTickSpeed; i++) {
|
|
if (simpleRandom.nextInt(48) == 0) { // Paper - optimise random ticking
|
|
this.tickPrecipitation(this.getBlockRandomPos(minBlockX, 0, minBlockZ, 15));
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
index 3a7707427691a7862499a7efa3b39ead1ef78013..95972e7d5e0357ff5884f1cb2f7596c5029f999d 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -125,6 +125,18 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
}
|
|
// Paper end - get block chunk optimisation
|
|
|
|
+ // Gale start - Airplane - optimize random calls in chunk ticking - instead of using a random every time the chunk is ticked, define when lightning strikes preemptively
|
|
+ private int lightningTick;
|
|
+ // shouldDoLightning compiles down to 29 bytes, which with the default of 35 byte inlining should guarantee an inline
|
|
+ public final boolean shouldDoLightning(net.minecraft.util.RandomSource random) {
|
|
+ if (this.lightningTick-- <= 0) {
|
|
+ this.lightningTick = random.nextInt(this.level.spigotConfig.thunderChance) << 1;
|
|
+ return true;
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ // Gale end - Airplane - optimize random calls in chunk ticking - instead of using a random every time the chunk is ticked, define when lightning strikes preemptively
|
|
+
|
|
public LevelChunk(Level level, ChunkPos pos) {
|
|
this(level, pos, UpgradeData.EMPTY, new LevelChunkTicks<>(), new LevelChunkTicks<>(), 0L, null, null, null);
|
|
}
|
|
@@ -161,6 +173,8 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
this.debug = !empty && this.level.isDebug();
|
|
this.defaultBlockState = empty ? VOID_AIR_BLOCKSTATE : AIR_BLOCKSTATE;
|
|
// Paper end - get block chunk optimisation
|
|
+
|
|
+ this.lightningTick = this.level.simpleRandom.nextInt(100000) << 1; // Gale - Airplane - optimize random calls in chunk ticking - initialize lightning tick
|
|
}
|
|
|
|
public LevelChunk(ServerLevel level, ProtoChunk chunk, @Nullable LevelChunk.PostLoadProcessor postLoad) {
|