mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Fix
This commit is contained in:
parent
265807941a
commit
9bdcd6aace
@ -56,6 +56,7 @@ public abstract class ParallaxTerrainProvider extends TopographicTerrainProvider
|
||||
setSliverCache(new KMap<>());
|
||||
setSliverBuffer(sliverBuffer);
|
||||
setMasterLock(new MasterLock());
|
||||
getMasterLock().disable();
|
||||
}
|
||||
|
||||
public void onInit(RNG rng)
|
||||
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.gen.scaffold.TerrainTarget;
|
||||
import com.volmit.iris.util.ChunkPosition;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.M;
|
||||
@ -21,6 +22,7 @@ public class AtomicWorldData
|
||||
private KMap<ChunkPosition, Long> lastChunk;
|
||||
private KList<ChunkPosition> unloadRegions;
|
||||
private KList<ChunkPosition> unloadChunks;
|
||||
private IrisLock lock = new IrisLock("ULLock");
|
||||
private long last = M.ms();
|
||||
|
||||
public AtomicWorldData(TerrainTarget world)
|
||||
@ -263,8 +265,10 @@ public class AtomicWorldData
|
||||
|
||||
public void clean(int j)
|
||||
{
|
||||
lock.lock();
|
||||
if(M.ms() - last < getUnloadBatchSpeed())
|
||||
{
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -331,6 +335,7 @@ public class AtomicWorldData
|
||||
}
|
||||
|
||||
unloadChunks.clear();
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
private int getUnloadBatchSize()
|
||||
|
@ -7,9 +7,11 @@ public class MasterLock
|
||||
{
|
||||
private KMap<String, IrisLock> locks;
|
||||
private IrisLock lock;
|
||||
private boolean enabled;
|
||||
|
||||
public MasterLock()
|
||||
{
|
||||
enabled = true;
|
||||
locks = new KMap<>();
|
||||
lock = new IrisLock("MasterLock");
|
||||
}
|
||||
@ -19,8 +21,18 @@ public class MasterLock
|
||||
locks.clear();
|
||||
}
|
||||
|
||||
public void disable()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public void lock(String key)
|
||||
{
|
||||
if(!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
if(!locks.containsKey(key))
|
||||
{
|
||||
@ -34,6 +46,11 @@ public class MasterLock
|
||||
|
||||
public void unlock(String key)
|
||||
{
|
||||
if(!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
if(!locks.containsKey(key))
|
||||
{
|
||||
|
@ -2,6 +2,7 @@ package com.volmit.iris.gen.provisions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -13,7 +14,6 @@ import com.volmit.iris.gen.scaffold.Provisioned;
|
||||
import com.volmit.iris.gen.scaffold.TerrainChunk;
|
||||
import com.volmit.iris.gen.scaffold.TerrainProvider;
|
||||
import com.volmit.iris.util.ChunkPosition;
|
||||
import com.volmit.iris.util.J;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
@ -41,7 +41,7 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned
|
||||
world.unloadChunkRequest(x, z);
|
||||
}
|
||||
|
||||
public void generateAsync(World world, int x, int z)
|
||||
public void generateAsync(World world, int x, int z, Consumer<Boolean> onDone)
|
||||
{
|
||||
ChunkPosition c = new ChunkPosition(x, z);
|
||||
|
||||
@ -50,7 +50,12 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned
|
||||
TerrainChunk snapshot = TerrainChunk.create(world);
|
||||
snapshot.setRaw(generateChunkData(world, getRNG(world, x, z), x, z, snapshot));
|
||||
precache.put(c, snapshot);
|
||||
J.s(() -> generate(world, x, z));
|
||||
onDone.accept(true);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
onDone.accept(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +75,7 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned
|
||||
{
|
||||
TerrainChunk snapshot = precache.remove(c);
|
||||
snapshot.inject(biome);
|
||||
return snapshot;
|
||||
return snapshot.getRaw();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
@ -30,6 +31,7 @@ public class PregenGui extends JPanel
|
||||
Graphics2D bg;
|
||||
double minC;
|
||||
double maxC;
|
||||
private ReentrantLock l;
|
||||
private BufferedImage image = new BufferedImage(res, res, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
public PregenGui()
|
||||
@ -45,11 +47,21 @@ public class PregenGui extends JPanel
|
||||
Graphics2D g = (Graphics2D) gx;
|
||||
bg = (Graphics2D) image.getGraphics();
|
||||
|
||||
l.lock();
|
||||
while(order.isNotEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
order.pop().run();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
l.unlock();
|
||||
|
||||
g.drawImage(image, 0, 0, getParent().getWidth(), getParent().getHeight(), new ImageObserver()
|
||||
{
|
||||
@Override
|
||||
@ -69,11 +81,8 @@ public class PregenGui extends JPanel
|
||||
g.drawString(i, 20, hh += h);
|
||||
}
|
||||
|
||||
J.a(() ->
|
||||
{
|
||||
J.sleep((long) 500);
|
||||
J.sleep((long) 1);
|
||||
repaint();
|
||||
});
|
||||
}
|
||||
|
||||
private void draw(ChunkPosition p, Color c, double minC, double maxC, Graphics2D bg)
|
||||
@ -94,10 +103,13 @@ public class PregenGui extends JPanel
|
||||
{
|
||||
JFrame frame = new JFrame("Pregen View");
|
||||
PregenGui nv = new PregenGui();
|
||||
nv.l = new ReentrantLock();
|
||||
nv.job = j;
|
||||
j.subscribe((c, b) ->
|
||||
{
|
||||
nv.l.lock();
|
||||
nv.order.add(() -> nv.draw(c, b, nv.minC, nv.maxC, nv.bg));
|
||||
nv.l.unlock();
|
||||
});
|
||||
frame.add(nv);
|
||||
frame.setSize(1000, 1000);
|
||||
|
@ -33,6 +33,14 @@ public class IrisLock
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@ -20,6 +21,7 @@ public class PregenJob implements Listener
|
||||
private int genned;
|
||||
private boolean completed;
|
||||
public static int task = -1;
|
||||
private AtomicInteger g = new AtomicInteger();
|
||||
private PrecisionStopwatch s;
|
||||
private ChronoLatch cl;
|
||||
private ChronoLatch clx;
|
||||
@ -35,10 +37,12 @@ public class PregenJob implements Listener
|
||||
private Spiraler chunkSpiraler;
|
||||
private boolean first;
|
||||
private Consumer2<ChunkPosition, Color> consumer;
|
||||
private int cubeSize = 5;
|
||||
private int cubeSize = 7;
|
||||
int xc = 0;
|
||||
|
||||
public PregenJob(World world, int size, MortarSender sender, Runnable onDone)
|
||||
{
|
||||
g.set(0);
|
||||
this.s = PrecisionStopwatch.start();
|
||||
Iris.instance.registerListener(this);
|
||||
this.world = world;
|
||||
@ -107,7 +111,7 @@ public class PregenJob implements Listener
|
||||
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
|
||||
while(p.getMilliseconds() < 5000)
|
||||
while(p.getMilliseconds() < 7000)
|
||||
{
|
||||
tick();
|
||||
}
|
||||
@ -161,30 +165,7 @@ public class PregenJob implements Listener
|
||||
if(chunkSpiraler.hasNext())
|
||||
{
|
||||
chunkSpiraler.next();
|
||||
|
||||
if(isChunkWithin(chunkX, chunkZ))
|
||||
{
|
||||
if(consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.cyan.darker().darker());
|
||||
}
|
||||
|
||||
world.loadChunk(chunkX, chunkZ);
|
||||
genned++;
|
||||
|
||||
if(consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.GREEN.darker());
|
||||
}
|
||||
}
|
||||
tickChunk();
|
||||
}
|
||||
|
||||
else if(spiraler.hasNext())
|
||||
@ -219,6 +200,38 @@ public class PregenJob implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
private void tickChunk()
|
||||
{
|
||||
tickSyncChunk();
|
||||
}
|
||||
|
||||
private void tickSyncChunk()
|
||||
{
|
||||
if(isChunkWithin(chunkX, chunkZ))
|
||||
{
|
||||
if(consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.blue.darker().darker());
|
||||
}
|
||||
|
||||
world.loadChunk(chunkX, chunkZ);
|
||||
genned++;
|
||||
|
||||
if(consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.BLUE);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.blue.brighter().brighter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllRequest()
|
||||
{
|
||||
if(clf.flip())
|
||||
@ -240,7 +253,7 @@ public class PregenJob implements Listener
|
||||
{
|
||||
if(e.getWorld().equals(world) && isChunkWithin(e.getChunk().getX(), e.getChunk().getZ()) && consumer != null)
|
||||
{
|
||||
consumer.accept(new ChunkPosition(e.getChunk().getX(), e.getChunk().getZ()), Color.GREEN);
|
||||
consumer.accept(new ChunkPosition(e.getChunk().getX(), e.getChunk().getZ()), Color.blue.brighter());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user