mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Pregen job remembers generally where it left off
This commit is contained in:
parent
c72559c31a
commit
49b494ed02
@ -1,6 +1,8 @@
|
|||||||
package com.volmit.iris.util;
|
package com.volmit.iris.util;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -28,6 +30,7 @@ public class PregenJob implements Listener
|
|||||||
private int genned;
|
private int genned;
|
||||||
private boolean completed;
|
private boolean completed;
|
||||||
public static int task = -1;
|
public static int task = -1;
|
||||||
|
private int ticks;
|
||||||
private Semaphore working;
|
private Semaphore working;
|
||||||
private AtomicInteger g = new AtomicInteger();
|
private AtomicInteger g = new AtomicInteger();
|
||||||
private PrecisionStopwatch s;
|
private PrecisionStopwatch s;
|
||||||
@ -94,6 +97,7 @@ public class PregenJob implements Listener
|
|||||||
mcaX = x;
|
mcaX = x;
|
||||||
mcaZ = z;
|
mcaZ = z;
|
||||||
chunkSpiraler.retarget(cubeSize, cubeSize);
|
chunkSpiraler.retarget(cubeSize, cubeSize);
|
||||||
|
ticks++;
|
||||||
});
|
});
|
||||||
|
|
||||||
chunkSpiraler.setOffset(Math.floorDiv(cubeSize, 2), Math.floorDiv(cubeSize, 2));
|
chunkSpiraler.setOffset(Math.floorDiv(cubeSize, 2), Math.floorDiv(cubeSize, 2));
|
||||||
@ -103,6 +107,7 @@ public class PregenJob implements Listener
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
PregenGui.launch(this);
|
PregenGui.launch(this);
|
||||||
|
fastFowardTicksIfPossible();
|
||||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::onTick, 0, 0);
|
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::onTick, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +159,11 @@ public class PregenJob implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onTick()
|
public void onTick()
|
||||||
|
{
|
||||||
|
onTick(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onTick(boolean skip)
|
||||||
{
|
{
|
||||||
if(paused)
|
if(paused)
|
||||||
{
|
{
|
||||||
@ -165,13 +175,18 @@ public class PregenJob implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(skip)
|
||||||
|
{
|
||||||
|
tick(skip);
|
||||||
|
}
|
||||||
|
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
|
|
||||||
if(PaperLib.isPaper())
|
if(PaperLib.isPaper())
|
||||||
{
|
{
|
||||||
for(int i = 0; i < 16; i++)
|
for(int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
tickPaper();
|
tickPaper(skip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +194,7 @@ public class PregenJob implements Listener
|
|||||||
{
|
{
|
||||||
while(p.getMilliseconds() < 7000)
|
while(p.getMilliseconds() < 7000)
|
||||||
{
|
{
|
||||||
tick();
|
tick(skip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +220,11 @@ public class PregenJob implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void tickPaper()
|
public void tickPaper()
|
||||||
|
{
|
||||||
|
tickPaper(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tickPaper(boolean skip)
|
||||||
{
|
{
|
||||||
if(working.getQueueLength() >= tc() / 2)
|
if(working.getQueueLength() >= tc() / 2)
|
||||||
{
|
{
|
||||||
@ -213,11 +233,16 @@ public class PregenJob implements Listener
|
|||||||
|
|
||||||
for(int i = 0; i < 128; i++)
|
for(int i = 0; i < 128; i++)
|
||||||
{
|
{
|
||||||
tick();
|
tick(skip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick()
|
public void tick()
|
||||||
|
{
|
||||||
|
tick(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick(boolean skip)
|
||||||
{
|
{
|
||||||
if(M.ms() - nogen > 5000 && Math.min((double) genned / (double) total, 1.0) > 0.99 && !completed)
|
if(M.ms() - nogen > 5000 && Math.min((double) genned / (double) total, 1.0) > 0.99 && !completed)
|
||||||
{
|
{
|
||||||
@ -270,12 +295,18 @@ public class PregenJob implements Listener
|
|||||||
if(chunkSpiraler.hasNext())
|
if(chunkSpiraler.hasNext())
|
||||||
{
|
{
|
||||||
chunkSpiraler.next();
|
chunkSpiraler.next();
|
||||||
tickChunk();
|
if(!skip)
|
||||||
|
{
|
||||||
|
tickChunk();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(spiraler.hasNext() || requeueMCA.isNotEmpty())
|
else if(spiraler.hasNext() || requeueMCA.isNotEmpty())
|
||||||
{
|
{
|
||||||
saveAllRequest();
|
if(!skip)
|
||||||
|
{
|
||||||
|
saveAllRequest();
|
||||||
|
}
|
||||||
|
|
||||||
if(requeueMCA.isNotEmpty())
|
if(requeueMCA.isNotEmpty())
|
||||||
{
|
{
|
||||||
@ -395,6 +426,30 @@ public class PregenJob implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fastFowardTicksIfPossible()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int ticks = Integer.valueOf(IO.readAll(new File(world.getWorldFolder(), "pregen.ticks")).trim());
|
||||||
|
ticks -= 6;
|
||||||
|
|
||||||
|
if(ticks <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < ticks; i++)
|
||||||
|
{
|
||||||
|
spiraler.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void saveAllRequest()
|
public void saveAllRequest()
|
||||||
{
|
{
|
||||||
if(clf.flip())
|
if(clf.flip())
|
||||||
@ -403,6 +458,19 @@ public class PregenJob implements Listener
|
|||||||
{
|
{
|
||||||
world.unloadChunkRequest(i.getX(), i.getZ());
|
world.unloadChunkRequest(i.getX(), i.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
J.a(() ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IO.writeAll(new File(world.getWorldFolder(), "pregen.ticks"), ticks + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(clx.flip())
|
if(clx.flip())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user