mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 04:29:05 +00:00
Caching Revisited
This commit is contained in:
@@ -164,43 +164,45 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator {
|
||||
}
|
||||
|
||||
public IrisRegion sampleRegion(int x, int z) {
|
||||
|
||||
|
||||
double wx = getModifiedX(x, z);
|
||||
double wz = getModifiedZ(x, z);
|
||||
return glBiome.getRegion(wx, wz);
|
||||
}
|
||||
|
||||
public BiomeResult sampleBiome(int x, int z) {
|
||||
if (!getDimension().getFocus().equals("")) {
|
||||
IrisBiome biome = loadBiome(getDimension().getFocus());
|
||||
return getCache().getRawBiome(x, z, () -> {
|
||||
if (!getDimension().getFocus().equals("")) {
|
||||
IrisBiome biome = loadBiome(getDimension().getFocus());
|
||||
|
||||
for (String i : getDimension().getRegions()) {
|
||||
IrisRegion reg = loadRegion(i);
|
||||
for (String i : getDimension().getRegions()) {
|
||||
IrisRegion reg = loadRegion(i);
|
||||
|
||||
if (reg.getLandBiomes().contains(biome.getLoadKey())) {
|
||||
biome.setInferredType(InferredType.LAND);
|
||||
break;
|
||||
if (reg.getLandBiomes().contains(biome.getLoadKey())) {
|
||||
biome.setInferredType(InferredType.LAND);
|
||||
break;
|
||||
}
|
||||
|
||||
if (reg.getSeaBiomes().contains(biome.getLoadKey())) {
|
||||
biome.setInferredType(InferredType.SEA);
|
||||
break;
|
||||
}
|
||||
|
||||
if (reg.getShoreBiomes().contains(biome.getLoadKey())) {
|
||||
biome.setInferredType(InferredType.SHORE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (reg.getSeaBiomes().contains(biome.getLoadKey())) {
|
||||
biome.setInferredType(InferredType.SEA);
|
||||
break;
|
||||
}
|
||||
|
||||
if (reg.getShoreBiomes().contains(biome.getLoadKey())) {
|
||||
biome.setInferredType(InferredType.SHORE);
|
||||
break;
|
||||
}
|
||||
return new BiomeResult(biome, 0);
|
||||
}
|
||||
|
||||
return new BiomeResult(biome, 0);
|
||||
}
|
||||
double wx = getModifiedX(x, z);
|
||||
double wz = getModifiedZ(x, z);
|
||||
IrisRegion region = glBiome.getRegion(wx, wz);
|
||||
BiomeResult res = glBiome.generateRegionData(wx, wz, x, z, region);
|
||||
|
||||
double wx = getModifiedX(x, z);
|
||||
double wz = getModifiedZ(x, z);
|
||||
IrisRegion region = glBiome.getRegion(wx, wz);
|
||||
BiomeResult res = glBiome.generateRegionData(wx, wz, x, z, region);
|
||||
|
||||
return res;
|
||||
return res;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.IrisContext;
|
||||
import com.volmit.iris.IrisDataManager;
|
||||
import com.volmit.iris.IrisMetrics;
|
||||
import com.volmit.iris.gen.atomics.AtomicMulticache;
|
||||
import com.volmit.iris.noise.CNG;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
@@ -46,6 +47,7 @@ import net.md_5.bungee.api.ChatColor;
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public abstract class ContextualChunkGenerator extends ChunkGenerator implements Listener {
|
||||
private AtomicMulticache cache;
|
||||
private IrisDataManager data;
|
||||
protected boolean failing;
|
||||
protected int task;
|
||||
@@ -70,6 +72,7 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
|
||||
perSecond = new ChronoLatch(1000);
|
||||
hlast = M.ms();
|
||||
hlock = new IrisLock("HotLock");
|
||||
cache = new AtomicMulticache();
|
||||
CNG.creates = 0;
|
||||
generated = 0;
|
||||
ticks = 0;
|
||||
|
||||
@@ -81,7 +81,8 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, boolean ignoreFluid) {
|
||||
int h = (int) Math.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z));
|
||||
int h = (int) Math
|
||||
.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z));
|
||||
|
||||
if (getDimension().isCarving() && h >= getDimension().getCarvingMin()) {
|
||||
while (getGlCarve().isCarved(x, h, z)) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import lombok.EqualsAndHashCode;
|
||||
public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
|
||||
private GroupedExecutor accelerant;
|
||||
private int threads;
|
||||
protected boolean safe;
|
||||
protected int cacheX;
|
||||
protected int cacheZ;
|
||||
private IrisLock genlock;
|
||||
@@ -28,7 +27,6 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
|
||||
|
||||
public ParallelChunkGenerator(String dimensionName, int threads) {
|
||||
super(dimensionName);
|
||||
safe = false;
|
||||
cacheX = 0;
|
||||
cacheZ = 0;
|
||||
this.threads = threads;
|
||||
@@ -68,6 +66,7 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
|
||||
genlock.lock();
|
||||
cacheX = x;
|
||||
cacheZ = z;
|
||||
getCache().targetChunk(cacheX, cacheZ);
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
AtomicSliverMap map = new AtomicSliverMap();
|
||||
HeightMap height = new HeightMap();
|
||||
@@ -90,11 +89,7 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
setCachingAllowed(true);
|
||||
setSafe(false);
|
||||
accelerant.waitFor(key);
|
||||
setSafe(true);
|
||||
setCachingAllowed(false);
|
||||
map.write(data, grid, height);
|
||||
getMetrics().getTerrain().put(p.getMilliseconds());
|
||||
p = PrecisionStopwatch.start();
|
||||
|
||||
@@ -68,7 +68,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
|
||||
double wx = getZoomed(ox);
|
||||
double wz = getZoomed(oz);
|
||||
int depth = 0;
|
||||
double noise = getNoiseHeight(rx, rz) + fluidHeight;
|
||||
double noise = getTerrainHeight(rx, rz);
|
||||
int height = (int) Math.round(noise);
|
||||
boolean carvable = getDimension().isCarving() && height > getDimension().getCarvingMin();
|
||||
IrisRegion region = sampleRegion(rx, rz);
|
||||
@@ -409,7 +409,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
|
||||
|
||||
}
|
||||
|
||||
protected double getNoiseHeight(int rx, int rz) {
|
||||
private double getNoiseHeight(int rx, int rz) {
|
||||
double wx = getZoomed(rx);
|
||||
double wz = getZoomed(rz);
|
||||
double h = getBiomeHeight(wx, wz, rx, rz);
|
||||
@@ -477,9 +477,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
|
||||
|
||||
@Override
|
||||
public IrisRegion sampleRegion(int x, int z) {
|
||||
IrisRegion r = super.sampleRegion(x, z);
|
||||
|
||||
return r;
|
||||
return getCache().getRegion(x, z, () -> super.sampleRegion(x, z));
|
||||
}
|
||||
|
||||
public BiomeResult sampleTrueBiome(int x, int z, double noise) {
|
||||
@@ -487,27 +485,26 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
|
||||
return focus();
|
||||
}
|
||||
|
||||
double wx = getModifiedX(x, z);
|
||||
double wz = getModifiedZ(x, z);
|
||||
IrisRegion region = sampleRegion(x, z);
|
||||
int height = (int) Math.round(noise);
|
||||
double sh = region.getShoreHeight(wx, wz);
|
||||
BiomeResult res = sampleTrueBiomeBase(x, z, height);
|
||||
IrisBiome current = res.getBiome();
|
||||
return getCache().getBiome(x, z, () -> {
|
||||
double wx = getModifiedX(x, z);
|
||||
double wz = getModifiedZ(x, z);
|
||||
IrisRegion region = sampleRegion(x, z);
|
||||
int height = (int) Math.round(noise);
|
||||
double sh = region.getShoreHeight(wx, wz);
|
||||
BiomeResult res = sampleTrueBiomeBase(x, z, height);
|
||||
IrisBiome current = res.getBiome();
|
||||
|
||||
if (current.isSea() && height > getDimension().getFluidHeight() - sh) {
|
||||
return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region);
|
||||
}
|
||||
if (current.isSea() && height > getDimension().getFluidHeight() - sh) {
|
||||
return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region);
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int onSampleColumnHeight(int cx, int cz, int rx, int rz, int x, int z) {
|
||||
int fluidHeight = getDimension().getFluidHeight();
|
||||
double noise = getNoiseHeight(rx, rz);
|
||||
|
||||
return (int) Math.round(noise) + fluidHeight;
|
||||
return (int) Math.round(getTerrainHeight(rx, rz));
|
||||
}
|
||||
|
||||
private boolean touchesSea(int rx, int rz) {
|
||||
@@ -528,7 +525,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
|
||||
}
|
||||
|
||||
public double getTerrainHeight(int x, int z) {
|
||||
return getNoiseHeight(x, z) + getFluidHeight();
|
||||
return getCache().getHeight(x, z, () -> getNoiseHeight(x, z) + getFluidHeight());
|
||||
}
|
||||
|
||||
public double getTerrainWaterHeight(int x, int z) {
|
||||
|
||||
105
src/main/java/com/volmit/iris/gen/atomics/AtomicMulticache.java
Normal file
105
src/main/java/com/volmit/iris/gen/atomics/AtomicMulticache.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package com.volmit.iris.gen.atomics;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.object.IrisRegion;
|
||||
import com.volmit.iris.util.BiomeResult;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.KMap;
|
||||
|
||||
public class AtomicMulticache {
|
||||
private final AtomicInteger x;
|
||||
private final AtomicInteger z;
|
||||
private final KMap<Long, Double> height;
|
||||
private final KMap<Long, BiomeResult> biome;
|
||||
private final KMap<Long, BiomeResult> rawBiome;
|
||||
private final KMap<Long, IrisRegion> region;
|
||||
private int r = 0;
|
||||
private int w = 0;
|
||||
private int m = 0;
|
||||
|
||||
public AtomicMulticache() {
|
||||
x = new AtomicInteger(0);
|
||||
z = new AtomicInteger(0);
|
||||
height = new KMap<Long, Double>();
|
||||
biome = new KMap<Long, BiomeResult>();
|
||||
rawBiome = new KMap<Long, BiomeResult>();
|
||||
region = new KMap<Long, IrisRegion>();
|
||||
}
|
||||
|
||||
public void targetChunk(int x, int z) {
|
||||
this.x.set(x);
|
||||
this.z.set(z);
|
||||
|
||||
Iris.info("R: " + Form.f(r) + " W: " + Form.f(w) + " M: " + Form.f(m) + " (" + Form.pc(r / (double) (r + m), 1)
|
||||
+ "), SIZE: " + Form.f(height.size() + biome.size() + region.size()));
|
||||
height.clear();
|
||||
region.size();
|
||||
biome.size();
|
||||
r = 0;
|
||||
w = 0;
|
||||
m = 0;
|
||||
}
|
||||
|
||||
public double getHeight(int x, int z, Supplier<Double> g) {
|
||||
return height.compute(pos(x, z), (k, v) -> {
|
||||
if (v == null) {
|
||||
m++;
|
||||
w++;
|
||||
return g.get();
|
||||
}
|
||||
|
||||
r++;
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
public IrisRegion getRegion(int x, int z, Supplier<IrisRegion> g) {
|
||||
return region.compute(pos(x, z), (k, v) -> {
|
||||
if (v == null) {
|
||||
m++;
|
||||
w++;
|
||||
return g.get();
|
||||
}
|
||||
|
||||
r++;
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
public BiomeResult getBiome(int x, int z, Supplier<BiomeResult> g) {
|
||||
return biome.compute(pos(x, z), (k, v) -> {
|
||||
if (v == null) {
|
||||
m++;
|
||||
w++;
|
||||
return g.get();
|
||||
}
|
||||
|
||||
r++;
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
public BiomeResult getRawBiome(int x, int z, Supplier<BiomeResult> g) {
|
||||
return rawBiome.compute(pos(x, z), (k, v) -> {
|
||||
if (v == null) {
|
||||
m++;
|
||||
w++;
|
||||
return g.get();
|
||||
}
|
||||
|
||||
r++;
|
||||
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
private long pos(int x, int z) {
|
||||
return (((long) x) << 32) | (z & 0xffffffffL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user