9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-25 18:19:14 +00:00

Bust the cache

This commit is contained in:
cyberpwn
2021-09-25 12:55:27 -04:00
parent 4ba8ecd3fd
commit 333e158ca5
8 changed files with 148 additions and 32 deletions

View File

@@ -171,7 +171,8 @@ public class IrisComplex implements DataProvider {
Interpolated.of(a -> 0D, a -> focus.getInferredType())) :
engine.getDimension().getContinentalStyle().create(rng.nextParallelRNG(234234565), getData())
.bake().scale(1D / engine.getDimension().getContinentZoom()).bake().stream()
.convert((v) -> v >= engine.getDimension().getLandChance() ? InferredType.SEA : InferredType.LAND).cache2D(engine, cacheSize);
.convert((v) -> v >= engine.getDimension().getLandChance() ? InferredType.SEA : InferredType.LAND)
.cache2D(engine, cacheSize);
baseBiomeStream = focus != null ? ProceduralStream.of((x, z) -> focus,
Interpolated.of(a -> 0D, a -> focus)) :
bridgeStream.convertAware2D((t, x, z) -> inferredStreams.get(t).get(x, z))
@@ -179,16 +180,9 @@ public class IrisComplex implements DataProvider {
heightStream = ProceduralStream.of((x, z) -> {
IrisBiome b = focus != null ? focus : baseBiomeStream.get(x, z);
return getHeight(engine, b, x, z, engine.getSeedManager().getHeight());
}, Interpolated.DOUBLE).clamp(0, engine.getHeight()).cache2D(engine, cacheSize, true);
}, Interpolated.DOUBLE).clamp(0, engine.getHeight()).cache2D(engine, cacheSize);
roundedHeighteightStream = heightStream.round();
slopeStream = heightStream.slope(3).cache2D(engine, cacheSize);
trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D,
b -> focus))
.cache2D(engine, cacheSize) : heightStream
.convertAware2D((h, x, z) ->
fixBiomeType(h, baseBiomeStream.get(x, z),
regionStream.get(x, z), x, z, fluidHeight))
.cache2D(engine, cacheSize);
trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D,
b -> focus))
.cache2D(engine, cacheSize) : heightStream
@@ -197,7 +191,7 @@ public class IrisComplex implements DataProvider {
regionStream.get(x, z), x, z, fluidHeight))
.cache2D(engine, cacheSize);
trueBiomeDerivativeStream = trueBiomeStream.convert(IrisBiome::getDerivative).cache2D(engine, cacheSize);
heightFluidStream = heightStream.max(fluidHeight).cache2D(engine, cacheSize, true);
heightFluidStream = heightStream.max(fluidHeight).cache2D(engine, cacheSize);
maxHeightStream = ProceduralStream.ofDouble((x, z) -> height);
terrainSurfaceDecoration = trueBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D(engine, cacheSize);

View File

@@ -462,17 +462,6 @@ public class IrisEngine implements Engine {
mode.generate(x, z, blocks, vbiomes, multicore);
}
if(!multicore)
{
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
blocks.set(i, 255, j, B.get("GLASS"));
}
}
}
getMantle().getMantle().flag(x>>4, z>>4, MantleFlag.REAL, true);
getMetrics().getTotal().put(p.getMilliseconds());
generated.incrementAndGet();

View File

@@ -0,0 +1,53 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.data;
import com.volmit.iris.util.function.Function2;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class ChunkCache<T> {
private final AtomicReferenceArray<T> cache;
public ChunkCache() {
cache = new AtomicReferenceArray<>(256);
}
public T compute(int x, int z, Function2<Integer, Integer, T> function)
{
T t = get(x&15, z&15);
if(t == null)
{
t = function.apply(x, z);
set(x&15, z&15, t);
}
return t;
}
private void set(int x, int z, T t) {
cache.set(x * 16 + z, t);
}
private T get(int x, int z) {
return cache.get(x * 16 + z);
}
}

View File

@@ -0,0 +1,46 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.data;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
public class ComplexCache<T> {
private KMap<Long, ChunkCache<T>> chunks;
public ComplexCache()
{
chunks = new KMap<>();
}
public boolean has(int x, int z)
{
return chunks.containsKey(Cache.key(x, z));
}
public void invalidate(int x, int z)
{
chunks.remove(Cache.key(x, z));
}
public ChunkCache<T> chunk(int x, int z)
{
return chunks.computeIfAbsent(Cache.key(x, z), (f) -> new ChunkCache<>());
}
}

View File

@@ -0,0 +1,24 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.data;
@FunctionalInterface
public interface Heafty {
int getHeaft();
}

View File

@@ -21,18 +21,29 @@ package com.volmit.iris.util.data;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.scheduling.J;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
public class KCache<K,V> implements MeteredCache {
private long max;
private final long max;
private CacheLoader<K, V> loader;
private LoadingCache<K, V> cache;
private final boolean fastDump;
public KCache(CacheLoader<K, V> loader, long max)
{
this(loader, max, false);
}
public KCache(CacheLoader<K, V> loader, long max, boolean fastDump)
{
this.max = max;
this.fastDump = fastDump;
this.loader = loader;
this.cache = create(loader);
}
@@ -41,6 +52,9 @@ public class KCache<K,V> implements MeteredCache {
return Caffeine
.newBuilder()
.maximumSize(max)
.initialCapacity((int) (max))
.softValues()
.expireAfterAccess(5, TimeUnit.MINUTES)
.build((k) -> loader == null ? null : loader.load(k));
}
@@ -57,9 +71,7 @@ public class KCache<K,V> implements MeteredCache {
public void invalidate()
{
LoadingCache<?,?> c = cache;
cache = create(loader);
c.invalidateAll();
cache.invalidateAll();
}
public V get(K k)

View File

@@ -24,6 +24,7 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IRare;
import com.volmit.iris.engine.object.IrisStyledRange;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.data.ComplexCache;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.function.Function4;
@@ -288,12 +289,8 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
return new To3DStream<T>(this);
}
default ProceduralStream<T> cache2D(Engine engine, int maxSize) {
return cache2D(engine, maxSize, false);
}
default ProceduralStream<T> cache2D(Engine engine, int maxSize, boolean weak) {
return new CachedStream2D<T>(engine, this, maxSize, weak);
default ProceduralStream<T> cache2D(Engine engine, int size) {
return new CachedStream2D<T>(engine, this, size);
}
default ProceduralStream<T> cache3D(Engine engine, int maxSize) {

View File

@@ -27,6 +27,7 @@ import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.data.ComplexCache;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.stream.BasicStream;
import com.volmit.iris.util.stream.ProceduralStream;
@@ -36,7 +37,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
private final KCache<Long, T> cache;
private final Engine engine;
public CachedStream2D(Engine engine, ProceduralStream<T> stream, int size, boolean weak) {
public CachedStream2D(Engine engine, ProceduralStream<T> stream, int size) {
super();
this.stream = stream;
this.engine = engine;