This commit is contained in:
Daniel Mills 2020-10-17 13:20:38 -04:00
parent ea46c78a15
commit 564c79c411
5 changed files with 135 additions and 13 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>bytecode.ninja</groupId>
<artifactId>Iris</artifactId>
<version>1.0.14</version>
<version>1.0.15</version>
<name>Iris</name>
<properties>
<skip.copy>false</skip.copy>

View File

@ -90,10 +90,6 @@ public class IrisSettings
@Desc("Skips preparing spawn by using nms to hijack the world init phase")
public boolean skipPrepareSpawnNMS = true;
@DontObfuscate
@Desc("Used to activate Iris")
public String activationCode = "";
public static IrisSettings get()
{
if(settings != null)

View File

@ -1,8 +1,11 @@
package com.volmit.iris.gen;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
import org.bukkit.Bukkit;
@ -33,10 +36,15 @@ import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.FastBlockData;
import com.volmit.iris.util.Form;
import com.volmit.iris.util.IrisStructureResult;
import com.volmit.iris.util.J;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.M;
import com.volmit.iris.util.O;
import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG;
import com.volmit.iris.util.Spiraler;
import io.papermc.lib.PaperLib;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -613,4 +621,84 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte
{
return true;
}
public File[] scrapeRegion(int x, int z, Consumer<Double> progress)
{
int minX = x << 5;
int minZ = z << 5;
int maxX = x + 31;
int maxZ = z + 31;
AtomicInteger outputs = new AtomicInteger(0);
new Spiraler(36, 36, (vx, vz) ->
{
int ax = vx + 16 + minX;
int az = vz + 16 + minZ;
if(ax > maxX || ax < minX || az > maxZ || az < minZ)
{
return;
}
PaperLib.getChunkAtAsyncUrgently(getTarget().getRealWorld(), ax, az, true).thenAccept((c) ->
{
outputs.addAndGet(1);
});
}).drain();
long ms = M.ms();
int lastChange = outputs.get();
while(outputs.get() != 1024)
{
J.sleep(1000);
if(outputs.get() != lastChange)
{
lastChange = outputs.get();
ms = M.ms();
progress.accept((double) lastChange / 1024D);
}
if(outputs.get() == lastChange && M.ms() - ms > 60000)
{
Iris.error("Cant get this chunk region waited 60 seconds!");
break;
}
}
progress.accept(1D);
O<Boolean> b = new O<Boolean>();
b.set(false);
J.s(() ->
{
getTarget().getRealWorld().save();
Iris.instance.getServer().dispatchCommand(Bukkit.getConsoleSender(), "save-all");
b.set(true);
});
try
{
getParallaxMap().saveAll();
}
catch(IOException e)
{
e.printStackTrace();
}
while(!b.get())
{
J.sleep(10);
}
File r = new File(getTarget().getRealWorld().getWorldFolder(), "region/r." + x + "." + z + ".mca");
File p = new File(getTarget().getRealWorld().getWorldFolder(), "parallax/sr." + x + "." + z + ".smca");
if(r.exists() && p.exists())
{
return new File[] {r, p};
}
return null;
}
}

View File

@ -81,7 +81,7 @@ public class PregenGui extends JPanel
g.drawString(i, 20, hh += h);
}
J.sleep((long) 1);
J.sleep((long) 250);
repaint();
}
@ -99,6 +99,7 @@ public class PregenGui extends JPanel
bg.fillRect(x, z, xa - x, za - z);
}
@SuppressWarnings("deprecation")
private static void createAndShowGUI(PregenJob j)
{
JFrame frame = new JFrame("Pregen View");
@ -107,6 +108,10 @@ public class PregenGui extends JPanel
nv.job = j;
j.subscribe((c, b) ->
{
if(b.equals(Color.pink) && c.equals(new ChunkPosition(Integer.MAX_VALUE, Integer.MAX_VALUE)))
{
frame.hide();
}
nv.l.lock();
nv.order.add(() -> nv.draw(c, b, nv.minC, nv.maxC, nv.bg));
nv.l.unlock();

View File

@ -12,15 +12,16 @@ import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent;
import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.gen.IrisTerrainProvider;
import com.volmit.iris.gen.provisions.ProvisionBukkit;
import com.volmit.iris.gui.PregenGui;
import io.papermc.lib.PaperLib;
import lombok.Getter;
public class PregenJob implements Listener
{
@Getter
private World world;
private int size;
private int total;
@ -43,12 +44,14 @@ public class PregenJob implements Listener
private Spiraler spiraler;
private Spiraler chunkSpiraler;
private boolean first;
private Consumer2<ChunkPosition, Color> consumer;
private static Consumer2<ChunkPosition, Color> consumer;
private IrisTerrainProvider tp;
private double cps = 0;
private int lg = 0;
private long lt = M.ms();
private int cubeSize = IrisSettings.get().getPregenTileSize();
private int cubeSize = 32;
private long nogen = M.ms();
private KList<ChunkPosition> requeueMCA = new KList<ChunkPosition>();
private RollingSequence acps = new RollingSequence(PaperLib.isPaper() ? 8 : 32);
int xc = 0;
@ -109,6 +112,11 @@ public class PregenJob implements Listener
try
{
Bukkit.getScheduler().cancelTask(task);
if(consumer != null)
{
consumer.accept(new ChunkPosition(Integer.MAX_VALUE, Integer.MAX_VALUE), Color.pink);
}
}
catch(Throwable e)
@ -172,7 +180,7 @@ public class PregenJob implements Listener
public void tick()
{
if((total - genned < 0 || genned > (((size + 32) / 16) * (size + 32) / 16)) && !completed)
if(M.ms() - nogen > 5000 && Math.min((double) genned / (double) total, 1.0) > 0.99 && !completed)
{
completed = true;
@ -185,7 +193,12 @@ public class PregenJob implements Listener
Iris.instance.unregisterListener(this);
completed = true;
sender.sendMessage("Pregen Completed!");
if(consumer != null)
{
consumer.accept(new ChunkPosition(Integer.MAX_VALUE, Integer.MAX_VALUE), Color.pink);
}
onDone.run();
return;
}
if(completed)
@ -221,10 +234,22 @@ public class PregenJob implements Listener
tickChunk();
}
else if(spiraler.hasNext())
else if(spiraler.hasNext() || requeueMCA.isNotEmpty())
{
saveAllRequest();
spiraler.next();
if(requeueMCA.isNotEmpty())
{
ChunkPosition posf = requeueMCA.popRandom();
mcaX = posf.getX();
mcaZ = posf.getZ();
chunkSpiraler.retarget(cubeSize, cubeSize);
}
else if(spiraler.hasNext())
{
spiraler.next();
}
while(chunkSpiraler.hasNext())
{
@ -284,10 +309,11 @@ public class PregenJob implements Listener
consumer.accept(new ChunkPosition(cx, cz), Color.magenta);
}
PaperLib.getChunkAtAsync(world, cx, cz).thenAccept(chunk ->
PaperLib.getChunkAtAsyncUrgently(world, cx, cz, true).thenAccept(chunk ->
{
working.release();
genned++;
nogen = M.ms();
if(consumer != null)
{
@ -312,6 +338,7 @@ public class PregenJob implements Listener
world.loadChunk(chunkX, chunkZ);
genned++;
nogen = M.ms();
if(consumer != null)
{
@ -392,4 +419,10 @@ public class PregenJob implements Listener
return new String[] {"Progress: " + Form.pc(Math.min((double) genned / (double) total, 1.0), 0), "Generated: " + Form.f(genned) + " Chunks", "Remaining: " + Form.f(total - genned) + " Chunks", "Elapsed: " + Form.duration((long) s.getMilliseconds(), 2), "Estimate: " + ((genned >= total - 5 ? "Any second..." : s.getMilliseconds() < 25000 ? "Calculating..." : Form.duration(eta, 2))), "ChunksMS: " + Form.duration(1000D / cps, 2), "Chunks/s: " + Form.f(cps, 1),
};
}
public void progressMCA(Color color, int x, int z, double pct)
{
// TODO Auto-generated method stub
}
}