mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-25 10:09:14 +00:00
Faster Interpolatin
This commit is contained in:
@@ -431,12 +431,14 @@ public class IrisComplex implements DataProvider {
|
||||
double h = 0;
|
||||
|
||||
for (IrisGenerator gen : generators) {
|
||||
double hi = gen.getInterpolator().interpolate(x, z, (xx, zz) ->
|
||||
h += gen.getInterpolator().interpolate(x, z, (xx, zz) ->
|
||||
{
|
||||
try {
|
||||
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
||||
|
||||
return bx.getGenLinkMax(gen.getLoadKey());
|
||||
return M.lerp(bx.getGenLinkMin(gen.getLoadKey()),
|
||||
bx.getGenLinkMax(gen.getLoadKey()),
|
||||
gen.getHeight(x, z, seed + 239945));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
@@ -445,23 +447,6 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
double lo = gen.getInterpolator().interpolate(x, z, (xx, zz) ->
|
||||
{
|
||||
try {
|
||||
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
||||
|
||||
return bx.getGenLinkMin(gen.getLoadKey());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
Iris.warn("Failed to sample lo biome at " + xx + " " + zz + " using the generator " + gen.getLoadKey());
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
h += M.lerp(lo, hi, gen.getHeight(x, z, seed + 239945));
|
||||
}
|
||||
|
||||
AtomicDouble noise = new AtomicDouble(h + fluidHeight + overlayStream.get(x, z));
|
||||
|
||||
@@ -70,7 +70,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
}
|
||||
|
||||
int maxGroups = 3;
|
||||
int biomeBaseCooldownSeconds = 15;
|
||||
int biomeBaseCooldownSeconds = 0;
|
||||
|
||||
for (UUID i : spawnCooldowns.k()) {
|
||||
if (M.ms() - spawnCooldowns.get(i) > TimeUnit.SECONDS.toMillis(biomeBaseCooldownSeconds)) {
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.reflect.V;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import io.netty.util.internal.ConcurrentSet;
|
||||
import lombok.Getter;
|
||||
@@ -83,9 +84,12 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
private final ChronoLatch hotloadcd;
|
||||
@Getter
|
||||
private double generatedPerSecond = 0;
|
||||
private final int art;
|
||||
private ReactiveFolder hotloader = null;
|
||||
private IrisWorld cworld = null;
|
||||
private final Looper ticker;
|
||||
private final Looper cleaner;
|
||||
private int hotloaderMisses = 0;
|
||||
private long lastHotloadTime = 100;
|
||||
|
||||
public EngineCompositeGenerator() {
|
||||
this(null, true);
|
||||
@@ -93,12 +97,53 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
|
||||
public EngineCompositeGenerator(String query, boolean production) {
|
||||
super();
|
||||
ticker = new Looper() {
|
||||
@Override
|
||||
protected long loop() {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
if(!tickHotloader())
|
||||
{
|
||||
hotloaderMisses++;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
hotloaderMisses = 0;
|
||||
}
|
||||
lastHotloadTime+= p.getMilliseconds();
|
||||
lastHotloadTime /= 2;
|
||||
|
||||
return 120 + (long)(lastHotloadTime/2) + Math.min(hotloaderMisses * 125, 1375);
|
||||
}
|
||||
};
|
||||
ticker.setPriority(Thread.MIN_PRIORITY);
|
||||
ticker.setName("Iris Project Manager");
|
||||
|
||||
cleaner = new Looper() {
|
||||
@Override
|
||||
protected long loop() {
|
||||
if(getComposite() != null)
|
||||
{
|
||||
getComposite().clean();
|
||||
}
|
||||
|
||||
return 10000;
|
||||
}
|
||||
};
|
||||
cleaner.setPriority(Thread.MIN_PRIORITY);
|
||||
cleaner.setName("Iris Parallax Manager");
|
||||
cleaner.start();
|
||||
|
||||
if(isStudio())
|
||||
{
|
||||
ticker.start();
|
||||
}
|
||||
|
||||
hotloadcd = new ChronoLatch(3500);
|
||||
mst = M.ms();
|
||||
this.production = production;
|
||||
this.dimensionQuery = query;
|
||||
initialized = new AtomicBoolean(false);
|
||||
art = J.ar(this::tick, 40);
|
||||
populators = new KList<BlockPopulator>().qadd(new BlockPopulator() {
|
||||
@Override
|
||||
public void populate(World world, Random random, Chunk chunk) {
|
||||
@@ -137,35 +182,24 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
}
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
public boolean tickHotloader() {
|
||||
if (getComposite() == null || isClosed()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!initialized.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int pri = Thread.currentThread().getPriority();
|
||||
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
|
||||
|
||||
if (M.ms() - mst > 1000) {
|
||||
generatedPerSecond = (double) (generated - lgenerated) / ((double) (M.ms() - mst) / 1000D);
|
||||
mst = M.ms();
|
||||
lgenerated = generated;
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (hotloader != null) {
|
||||
hotloader.check();
|
||||
getComposite().clean();
|
||||
return hotloader.check();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
}
|
||||
|
||||
Thread.currentThread().setPriority(pri);
|
||||
return false;
|
||||
}
|
||||
|
||||
private synchronized IrisDimension getDimension(IrisWorld world) {
|
||||
@@ -562,6 +596,8 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
|
||||
public Runnable generateChunkRawData(IrisWorld world, int x, int z, TerrainChunk tc, boolean multicore) {
|
||||
initialize(world);
|
||||
tickMetrics();
|
||||
|
||||
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||
Hunk<BlockData> post = Hunk.newAtomicHunk(biomes.getWidth(), biomes.getHeight(), biomes.getDepth());
|
||||
@@ -570,6 +606,14 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
return () -> blocks.insertSoftly(0, 0, 0, post, (b) -> b == null || B.isAirOrFluid(b));
|
||||
}
|
||||
|
||||
private void tickMetrics() {
|
||||
if (M.ms() - mst > 1000) {
|
||||
generatedPerSecond = (double) (generated - lgenerated) / ((double) (M.ms() - mst) / 1000D);
|
||||
mst = M.ms();
|
||||
lgenerated = generated;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSpawn(World world, int x, int z) {
|
||||
return super.canSpawn(world, x, z);
|
||||
@@ -689,7 +733,11 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
J.car(art);
|
||||
if(isStudio())
|
||||
{
|
||||
ticker.interrupt();
|
||||
}
|
||||
|
||||
if (getComposite() != null) {
|
||||
getComposite().close();
|
||||
|
||||
|
||||
@@ -586,16 +586,19 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
}
|
||||
|
||||
for (IrisFeaturePotential j : p.getAddFeatures()) {
|
||||
ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4);
|
||||
double a = Math.max(v.getW(), v.getD());
|
||||
if(j.hasZone(rng, xx >> 4, zz >> 4))
|
||||
{
|
||||
ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4);
|
||||
double a = Math.max(v.getW(), v.getD());
|
||||
|
||||
for (IrisFeaturePositional k : rw.getFeatures()) {
|
||||
if (k.getX() == xx && k.getZ() == zz) {
|
||||
break;
|
||||
for (IrisFeaturePositional k : rw.getFeatures()) {
|
||||
if (k.getX() == xx && k.getZ() == zz) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rw.getFeatures().add(new IrisFeaturePositional(xx, zz, j.getZone()));
|
||||
rw.getFeatures().add(new IrisFeaturePositional(xx, zz, j.getZone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -646,16 +649,19 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
}
|
||||
|
||||
for (IrisFeaturePotential j : objectPlacement.getAddFeatures()) {
|
||||
ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4);
|
||||
double a = Math.max(v.getW(), v.getD());
|
||||
if(j.hasZone(rng, xx >> 4, zz >> 4))
|
||||
{
|
||||
ParallaxChunkMeta rw = getParallaxAccess().getMetaRW(xx >> 4, zz >> 4);
|
||||
double a = Math.max(v.getW(), v.getD());
|
||||
|
||||
for (IrisFeaturePositional k : rw.getFeatures()) {
|
||||
if (k.getX() == xx && k.getZ() == zz) {
|
||||
continue placing;
|
||||
for (IrisFeaturePositional k : rw.getFeatures()) {
|
||||
if (k.getX() == xx && k.getZ() == zz) {
|
||||
continue placing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rw.getFeatures().add(new IrisFeaturePositional(xx, zz, j.getZone()));
|
||||
rw.getFeatures().add(new IrisFeaturePositional(xx, zz, j.getZone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ public class IrisEntitySpawn implements IRare {
|
||||
return e;
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
Iris.error(" Failed to retrieve real entity @ " + at);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.volmit.iris.util.io;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.math.M;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -48,10 +49,6 @@ public class FolderWatcher extends FileWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
if (watchers == null) {
|
||||
System.out.print("wtf");
|
||||
}
|
||||
|
||||
for (File i : watchers.k()) {
|
||||
if (!i.exists()) {
|
||||
watchers.remove(i);
|
||||
@@ -71,13 +68,13 @@ public class FolderWatcher extends FileWatcher {
|
||||
KMap<File, FolderWatcher> w = watchers.copy();
|
||||
readProperties();
|
||||
|
||||
for (File i : w.k()) {
|
||||
for (File i : w.keySet()) {
|
||||
if (!watchers.containsKey(i)) {
|
||||
deleted.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (File i : watchers.k()) {
|
||||
for (File i : watchers.keySet()) {
|
||||
if (!w.containsKey(i)) {
|
||||
created.add(i);
|
||||
} else {
|
||||
@@ -98,6 +95,34 @@ public class FolderWatcher extends FileWatcher {
|
||||
return super.checkModified();
|
||||
}
|
||||
|
||||
public boolean checkModifiedFast() {
|
||||
if(watchers == null || watchers.isEmpty())
|
||||
{
|
||||
return checkModified();
|
||||
}
|
||||
|
||||
changed.clear();
|
||||
created.clear();
|
||||
deleted.clear();
|
||||
|
||||
if (file.isDirectory()) {
|
||||
for (File i : watchers.keySet()) {
|
||||
FolderWatcher fw = watchers.get(i);
|
||||
if (fw.checkModifiedFast()) {
|
||||
changed.add(fw.file);
|
||||
}
|
||||
|
||||
changed.addAll(fw.getChanged());
|
||||
created.addAll(fw.getCreated());
|
||||
deleted.addAll(fw.getDeleted());
|
||||
}
|
||||
|
||||
return !changed.isEmpty() || !created.isEmpty() || !deleted.isEmpty();
|
||||
}
|
||||
|
||||
return super.checkModified();
|
||||
}
|
||||
|
||||
public KMap<File, FolderWatcher> getWatchers() {
|
||||
return watchers;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class ReactiveFolder {
|
||||
private final File folder;
|
||||
private final Consumer3<KList<File>, KList<File>, KList<File>> hotload;
|
||||
private FolderWatcher fw;
|
||||
private int checkCycle = 0;
|
||||
|
||||
public ReactiveFolder(File folder, Consumer3<KList<File>, KList<File>, KList<File>> hotload) {
|
||||
this.folder = folder;
|
||||
@@ -39,10 +40,11 @@ public class ReactiveFolder {
|
||||
fw = new FolderWatcher(folder);
|
||||
}
|
||||
|
||||
public void check() {
|
||||
public boolean check() {
|
||||
checkCycle++;
|
||||
boolean modified = false;
|
||||
|
||||
if (fw.checkModified()) {
|
||||
if (checkCycle % 3 == 0 ? fw.checkModified() : fw.checkModifiedFast()) {
|
||||
for (File i : fw.getCreated()) {
|
||||
if (i.getName().endsWith(".iob") || i.getName().endsWith(".json")) {
|
||||
modified = true;
|
||||
@@ -73,6 +75,6 @@ public class ReactiveFolder {
|
||||
hotload.accept(fw.getCreated(), fw.getChanged(), fw.getDeleted());
|
||||
}
|
||||
|
||||
fw.checkModified();
|
||||
return fw.checkModified();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user