2020-11-06 04:37:46 +01:00
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>
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java b/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java
2020-11-06 04:37:46 +01:00
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java
+++ b/src/main/java/net/minecraft/world/level/biome/WorldChunkManagerTheEnd.java
@@ -0,0 +0,0 @@ package net.minecraft.world.level.biome;
2020-11-06 04:37:46 +01:00
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;
2021-03-16 08:19:45 +01:00
import net.minecraft.core.IRegistry;
import net.minecraft.resources.RegistryLookupCodec;
2021-03-16 16:50:45 +01:00
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;
2020-11-06 04:37:46 +01:00
@@ -0,0 +0,0 @@ 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));
@@ -0,0 +0,0 @@ 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;