mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
976c6d425b
A recent commit has been made that caused patches to be out of order, rebuilding
78 lines
4.3 KiB
Diff
78 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: SuperCoder7979 <25208576+SuperCoder7979@users.noreply.github.com>
|
|
Date: Tue, 3 Nov 2020 23:48:05 -0600
|
|
Subject: [PATCH] Significantly improve performance of the end generation
|
|
|
|
This patch implements a noise cache for the end which significantly reduces the computation time of generation. This results in about a 3x improvement.
|
|
|
|
Original code by SuperCoder7979 and Gegy in Lithium, licensed under LGPL-3.0 (Source: https://github.com/jellysquid3/lithium-fabric)
|
|
|
|
Co-authored-by: Gegy <gegy1000@gmail.com>
|
|
Co-authored-by: Dylan Xaldin <Puremin0rez515@gmail.com>
|
|
Co-authored-by: pop4959 <pop4959@gmail.com>
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java b/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java
|
|
index 1077972d694d604c3ec97d333d34a9ab81819c33..62fe4cc00a24e330443d2f006a88dbab3798fb28 100644
|
|
--- a/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java
|
|
+++ b/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java
|
|
@@ -3,10 +3,12 @@ package net.minecraft.world.level.biome;
|
|
import com.google.common.collect.ImmutableList;
|
|
import com.mojang.serialization.Codec;
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
+import it.unimi.dsi.fastutil.HashCommon; // Paper
|
|
import java.util.List;
|
|
import net.minecraft.core.IRegistry;
|
|
import net.minecraft.resources.RegistryLookupCodec;
|
|
import net.minecraft.util.MathHelper;
|
|
+import net.minecraft.world.level.ChunkCoordIntPair;
|
|
import net.minecraft.world.level.levelgen.SeededRandom;
|
|
import net.minecraft.world.level.levelgen.synth.NoiseGenerator3Handler;
|
|
|
|
@@ -27,6 +29,16 @@ public class WorldChunkManagerTheEnd extends WorldChunkManager {
|
|
private final BiomeBase k;
|
|
private final BiomeBase l;
|
|
private final BiomeBase m;
|
|
+ // Paper start
|
|
+ private static final class NoiseCache {
|
|
+ public long[] keys = new long[8192];
|
|
+ public float[] values = new float[8192];
|
|
+ public NoiseCache() {
|
|
+ java.util.Arrays.fill(keys, Long.MIN_VALUE);
|
|
+ }
|
|
+ }
|
|
+ private static final ThreadLocal<java.util.Map<NoiseGenerator3Handler, NoiseCache>> noiseCache = ThreadLocal.withInitial(java.util.WeakHashMap::new);
|
|
+ // Paper end
|
|
|
|
public WorldChunkManagerTheEnd(IRegistry<BiomeBase> iregistry, long i) {
|
|
this(iregistry, i, (BiomeBase) iregistry.d(Biomes.THE_END), (BiomeBase) iregistry.d(Biomes.END_HIGHLANDS), (BiomeBase) iregistry.d(Biomes.END_MIDLANDS), (BiomeBase) iregistry.d(Biomes.SMALL_END_ISLANDS), (BiomeBase) iregistry.d(Biomes.END_BARRENS));
|
|
@@ -81,13 +93,27 @@ public class WorldChunkManagerTheEnd extends WorldChunkManager {
|
|
|
|
f = MathHelper.a(f, -100.0F, 80.0F);
|
|
|
|
+ NoiseCache cache = noiseCache.get().computeIfAbsent(noisegenerator3handler, m -> new NoiseCache()); // Paper
|
|
for (int k1 = -12; k1 <= 12; ++k1) {
|
|
for (int l1 = -12; l1 <= 12; ++l1) {
|
|
long i2 = (long) (k + k1);
|
|
long j2 = (long) (l + l1);
|
|
|
|
- if (i2 * i2 + j2 * j2 > 4096L && noisegenerator3handler.a((double) i2, (double) j2) < -0.8999999761581421D) {
|
|
- float f1 = (MathHelper.e((float) i2) * 3439.0F + MathHelper.e((float) j2) * 147.0F) % 13.0F + 9.0F;
|
|
+ // Paper start - Significantly improve end generation performance by using a noise cache
|
|
+ long key = ChunkCoordIntPair.pair((int) i2, (int) j2);
|
|
+ int index = (int) HashCommon.mix(key) & 8191;
|
|
+ float f1 = Float.MIN_VALUE;
|
|
+ if (cache.keys[index] == key) {
|
|
+ f1 = cache.values[index];
|
|
+ } else {
|
|
+ if (i2 * i2 + j2 * j2 > 4096L && noisegenerator3handler.a((double) i2, (double) j2) < -0.8999999761581421D) {
|
|
+ f1 = (MathHelper.e((float) i2) * 3439.0F + MathHelper.e((float) j2) * 147.0F) % 13.0F + 9.0F;
|
|
+ }
|
|
+ cache.keys[index] = key;
|
|
+ cache.values[index] = f1;
|
|
+ }
|
|
+ if (f1 != Float.MIN_VALUE) {
|
|
+ // Paper end
|
|
float f2 = (float) (i1 - k1 * 2);
|
|
float f3 = (float) (j1 - l1 * 2);
|
|
float f4 = 100.0F - MathHelper.c(f2 * f2 + f3 * f3) * f1;
|