mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +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<>());
|
setSliverCache(new KMap<>());
|
||||||
setSliverBuffer(sliverBuffer);
|
setSliverBuffer(sliverBuffer);
|
||||||
setMasterLock(new MasterLock());
|
setMasterLock(new MasterLock());
|
||||||
|
getMasterLock().disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onInit(RNG rng)
|
public void onInit(RNG rng)
|
||||||
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.gen.scaffold.TerrainTarget;
|
import com.volmit.iris.gen.scaffold.TerrainTarget;
|
||||||
import com.volmit.iris.util.ChunkPosition;
|
import com.volmit.iris.util.ChunkPosition;
|
||||||
|
import com.volmit.iris.util.IrisLock;
|
||||||
import com.volmit.iris.util.KList;
|
import com.volmit.iris.util.KList;
|
||||||
import com.volmit.iris.util.KMap;
|
import com.volmit.iris.util.KMap;
|
||||||
import com.volmit.iris.util.M;
|
import com.volmit.iris.util.M;
|
||||||
@ -21,6 +22,7 @@ public class AtomicWorldData
|
|||||||
private KMap<ChunkPosition, Long> lastChunk;
|
private KMap<ChunkPosition, Long> lastChunk;
|
||||||
private KList<ChunkPosition> unloadRegions;
|
private KList<ChunkPosition> unloadRegions;
|
||||||
private KList<ChunkPosition> unloadChunks;
|
private KList<ChunkPosition> unloadChunks;
|
||||||
|
private IrisLock lock = new IrisLock("ULLock");
|
||||||
private long last = M.ms();
|
private long last = M.ms();
|
||||||
|
|
||||||
public AtomicWorldData(TerrainTarget world)
|
public AtomicWorldData(TerrainTarget world)
|
||||||
@ -263,8 +265,10 @@ public class AtomicWorldData
|
|||||||
|
|
||||||
public void clean(int j)
|
public void clean(int j)
|
||||||
{
|
{
|
||||||
|
lock.lock();
|
||||||
if(M.ms() - last < getUnloadBatchSpeed())
|
if(M.ms() - last < getUnloadBatchSpeed())
|
||||||
{
|
{
|
||||||
|
lock.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,6 +335,7 @@ public class AtomicWorldData
|
|||||||
}
|
}
|
||||||
|
|
||||||
unloadChunks.clear();
|
unloadChunks.clear();
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getUnloadBatchSize()
|
private int getUnloadBatchSize()
|
||||||
|
@ -7,9 +7,11 @@ public class MasterLock
|
|||||||
{
|
{
|
||||||
private KMap<String, IrisLock> locks;
|
private KMap<String, IrisLock> locks;
|
||||||
private IrisLock lock;
|
private IrisLock lock;
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
public MasterLock()
|
public MasterLock()
|
||||||
{
|
{
|
||||||
|
enabled = true;
|
||||||
locks = new KMap<>();
|
locks = new KMap<>();
|
||||||
lock = new IrisLock("MasterLock");
|
lock = new IrisLock("MasterLock");
|
||||||
}
|
}
|
||||||
@ -19,8 +21,18 @@ public class MasterLock
|
|||||||
locks.clear();
|
locks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disable()
|
||||||
|
{
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
public void lock(String key)
|
public void lock(String key)
|
||||||
{
|
{
|
||||||
|
if(!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
if(!locks.containsKey(key))
|
if(!locks.containsKey(key))
|
||||||
{
|
{
|
||||||
@ -34,6 +46,11 @@ public class MasterLock
|
|||||||
|
|
||||||
public void unlock(String key)
|
public void unlock(String key)
|
||||||
{
|
{
|
||||||
|
if(!enabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
if(!locks.containsKey(key))
|
if(!locks.containsKey(key))
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@ package com.volmit.iris.gen.provisions;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
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.TerrainChunk;
|
||||||
import com.volmit.iris.gen.scaffold.TerrainProvider;
|
import com.volmit.iris.gen.scaffold.TerrainProvider;
|
||||||
import com.volmit.iris.util.ChunkPosition;
|
import com.volmit.iris.util.ChunkPosition;
|
||||||
import com.volmit.iris.util.J;
|
|
||||||
import com.volmit.iris.util.KMap;
|
import com.volmit.iris.util.KMap;
|
||||||
import com.volmit.iris.util.RNG;
|
import com.volmit.iris.util.RNG;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned
|
|||||||
world.unloadChunkRequest(x, z);
|
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);
|
ChunkPosition c = new ChunkPosition(x, z);
|
||||||
|
|
||||||
@ -50,7 +50,12 @@ public class ProvisionBukkit extends ChunkGenerator implements Provisioned
|
|||||||
TerrainChunk snapshot = TerrainChunk.create(world);
|
TerrainChunk snapshot = TerrainChunk.create(world);
|
||||||
snapshot.setRaw(generateChunkData(world, getRNG(world, x, z), x, z, snapshot));
|
snapshot.setRaw(generateChunkData(world, getRNG(world, x, z), x, z, snapshot));
|
||||||
precache.put(c, 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);
|
TerrainChunk snapshot = precache.remove(c);
|
||||||
snapshot.inject(biome);
|
snapshot.inject(biome);
|
||||||
return snapshot;
|
return snapshot.getRaw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.awt.image.ImageObserver;
|
import java.awt.image.ImageObserver;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@ -30,6 +31,7 @@ public class PregenGui extends JPanel
|
|||||||
Graphics2D bg;
|
Graphics2D bg;
|
||||||
double minC;
|
double minC;
|
||||||
double maxC;
|
double maxC;
|
||||||
|
private ReentrantLock l;
|
||||||
private BufferedImage image = new BufferedImage(res, res, BufferedImage.TYPE_INT_RGB);
|
private BufferedImage image = new BufferedImage(res, res, BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
public PregenGui()
|
public PregenGui()
|
||||||
@ -45,10 +47,20 @@ public class PregenGui extends JPanel
|
|||||||
Graphics2D g = (Graphics2D) gx;
|
Graphics2D g = (Graphics2D) gx;
|
||||||
bg = (Graphics2D) image.getGraphics();
|
bg = (Graphics2D) image.getGraphics();
|
||||||
|
|
||||||
|
l.lock();
|
||||||
while(order.isNotEmpty())
|
while(order.isNotEmpty())
|
||||||
{
|
{
|
||||||
order.pop().run();
|
try
|
||||||
|
{
|
||||||
|
order.pop().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
l.unlock();
|
||||||
|
|
||||||
g.drawImage(image, 0, 0, getParent().getWidth(), getParent().getHeight(), new ImageObserver()
|
g.drawImage(image, 0, 0, getParent().getWidth(), getParent().getHeight(), new ImageObserver()
|
||||||
{
|
{
|
||||||
@ -69,11 +81,8 @@ public class PregenGui extends JPanel
|
|||||||
g.drawString(i, 20, hh += h);
|
g.drawString(i, 20, hh += h);
|
||||||
}
|
}
|
||||||
|
|
||||||
J.a(() ->
|
J.sleep((long) 1);
|
||||||
{
|
repaint();
|
||||||
J.sleep((long) 500);
|
|
||||||
repaint();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void draw(ChunkPosition p, Color c, double minC, double maxC, Graphics2D bg)
|
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");
|
JFrame frame = new JFrame("Pregen View");
|
||||||
PregenGui nv = new PregenGui();
|
PregenGui nv = new PregenGui();
|
||||||
|
nv.l = new ReentrantLock();
|
||||||
nv.job = j;
|
nv.job = j;
|
||||||
j.subscribe((c, b) ->
|
j.subscribe((c, b) ->
|
||||||
{
|
{
|
||||||
|
nv.l.lock();
|
||||||
nv.order.add(() -> nv.draw(c, b, nv.minC, nv.maxC, nv.bg));
|
nv.order.add(() -> nv.draw(c, b, nv.minC, nv.maxC, nv.bg));
|
||||||
|
nv.l.unlock();
|
||||||
});
|
});
|
||||||
frame.add(nv);
|
frame.add(nv);
|
||||||
frame.setSize(1000, 1000);
|
frame.setSize(1000, 1000);
|
||||||
|
@ -33,6 +33,14 @@ public class IrisLock
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lock.unlock();
|
try
|
||||||
|
{
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.volmit.iris.util;
|
package com.volmit.iris.util;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -20,6 +21,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 AtomicInteger g = new AtomicInteger();
|
||||||
private PrecisionStopwatch s;
|
private PrecisionStopwatch s;
|
||||||
private ChronoLatch cl;
|
private ChronoLatch cl;
|
||||||
private ChronoLatch clx;
|
private ChronoLatch clx;
|
||||||
@ -35,10 +37,12 @@ public class PregenJob implements Listener
|
|||||||
private Spiraler chunkSpiraler;
|
private Spiraler chunkSpiraler;
|
||||||
private boolean first;
|
private boolean first;
|
||||||
private Consumer2<ChunkPosition, Color> consumer;
|
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)
|
public PregenJob(World world, int size, MortarSender sender, Runnable onDone)
|
||||||
{
|
{
|
||||||
|
g.set(0);
|
||||||
this.s = PrecisionStopwatch.start();
|
this.s = PrecisionStopwatch.start();
|
||||||
Iris.instance.registerListener(this);
|
Iris.instance.registerListener(this);
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@ -107,7 +111,7 @@ public class PregenJob implements Listener
|
|||||||
|
|
||||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
|
|
||||||
while(p.getMilliseconds() < 5000)
|
while(p.getMilliseconds() < 7000)
|
||||||
{
|
{
|
||||||
tick();
|
tick();
|
||||||
}
|
}
|
||||||
@ -161,30 +165,7 @@ public class PregenJob implements Listener
|
|||||||
if(chunkSpiraler.hasNext())
|
if(chunkSpiraler.hasNext())
|
||||||
{
|
{
|
||||||
chunkSpiraler.next();
|
chunkSpiraler.next();
|
||||||
|
tickChunk();
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(spiraler.hasNext())
|
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()
|
public void saveAllRequest()
|
||||||
{
|
{
|
||||||
if(clf.flip())
|
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)
|
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