This commit is contained in:
Daniel Mills 2021-01-01 18:53:32 -05:00
parent 8dd858e813
commit a921845ae3
13 changed files with 193 additions and 131 deletions

View File

@ -16,7 +16,6 @@ import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull;
import java.util.Random;
import java.util.concurrent.Semaphore;
public class IrisEngine extends BlockPopulator implements Engine
{
@ -48,19 +47,15 @@ public class IrisEngine extends BlockPopulator implements Engine
@Setter
@Getter
private volatile int minHeight;
private int permits;
private boolean failing;
private boolean closed;
private int cacheId;
private Semaphore s;
private int art;
private final int art;
public IrisEngine(EngineTarget target, EngineCompound compound, int index)
{
Iris.info("Initializing Engine: " + target.getWorld().getName() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)");
metrics = new EngineMetrics(32);
permits = 10000;
this.s = new Semaphore(permits);
this.target = target;
this.framework = new IrisEngineFramework(this);
worldManager = new IrisWorldManager(this);
@ -84,13 +79,13 @@ public class IrisEngine extends BlockPopulator implements Engine
}
@Override
public int getCurrentlyGenerating() {
return permits - s.availablePermits();
public boolean isClosed() {
return closed;
}
@Override
public boolean isClosed() {
return closed;
public void recycle() {
getFramework().recycle();
}
@Override
@ -108,7 +103,6 @@ public class IrisEngine extends BlockPopulator implements Engine
try
{
boolean structures = postblocks != null;
s.acquire(1);
PrecisionStopwatch p = PrecisionStopwatch.start();
Hunk<BlockData> blocks = vblocks.synchronize().listen((xx,y,zz,t) -> catchBlockUpdates(x+xx,y+getMinHeight(),z+zz, t));
Hunk<BlockData> pblocks = structures ? postblocks.synchronize().listen((xx,y,zz,t) -> catchBlockUpdates(x+xx,y+getMinHeight(),z+zz, t)) : null;
@ -120,11 +114,9 @@ public class IrisEngine extends BlockPopulator implements Engine
getFramework().getRavineModifier().modify(x, z, blocks);
getFramework().getPostModifier().modify(x, z, blocks);
getFramework().getDecorantActuator().actuate(x, z, structures ? fringe : blocks);
getFramework().getEngineParallax().insertParallax(x, z, structures ? fringe : blocks);
getFramework().getEngineParallax().insertParallax(x, z, blocks);
getFramework().getDepositModifier().modify(x, z, blocks);
getMetrics().getTotal().put(p.getMilliseconds());
s.release(1);
getFramework().recycle();
}
catch(Throwable e)

View File

@ -210,6 +210,7 @@ public class IrisEngineCompound implements EngineCompound {
@Override
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<BlockData> postblocks, Hunk<Biome> biomes)
{
recycle();
PrecisionStopwatch p = PrecisionStopwatch.start();
if(engines.length == 1 && !getEngine(0).getTarget().isInverted())
{
@ -272,17 +273,6 @@ public class IrisEngineCompound implements EngineCompound {
wallClock.put(p.getMilliseconds());
}
@Override
public int getCurrentlyGeneratingEngines() {
int v = 0;
for(Engine i : engines)
{
v+= i.getCurrentlyGenerating();
}
return v;
}
@Override
public int getSize() {
return engines.length;

View File

@ -12,6 +12,9 @@ public class CommandIrisStudio extends MortarCommand
@Command
private CommandIrisStudioCreate create;
@Command
private CommandIrisStudioFix fix;
@Command
private CommandIrisStudioOpen open;

View File

@ -0,0 +1,65 @@
package com.volmit.iris.manager.command;
import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.MortarCommand;
import com.volmit.iris.util.MortarSender;
import org.bukkit.Chunk;
import org.bukkit.block.data.BlockData;
public class CommandIrisStudioFix extends MortarCommand
{
public CommandIrisStudioFix()
{
super("fix");
requiresPermission(Iris.perm.studio);
setDescription("Go to the spawn of the currently open studio world.");
setCategory("Studio");
}
@Override
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!IrisSettings.get().isStudio())
{
sender.sendMessage("To use Iris Studio, please enable studio in Iris/settings.json");
return true;
}
if(!Iris.proj.isProjectOpen())
{
sender.sendMessage("There is not a studio currently loaded.");
return true;
}
try
{
Chunk c = sender.player().getLocation().getChunk();
int cx = c.getX() * 16;
int cz = c.getZ() * 16;
Hunk<BlockData> bd = Hunk.viewBlocks(c);
Iris.proj.getActiveProject().getActiveProvider().getCompound().getDefaultEngine().getFramework().getEngineParallax().insertParallax(cx, cz, bd);
sender.sendMessage("Done!");
}
catch(Throwable e)
{
sender.sendMessage("Failed to teleport to the studio world. Try re-opening the project.");
}
return true;
}
@Override
protected String getArgsUsage()
{
return "";
}
}

View File

@ -1,8 +1,9 @@
package com.volmit.iris.manager.edit;
import com.volmit.iris.util.*;
import com.volmit.iris.scaffold.engine.EngineCompositeGenerator;
import com.volmit.iris.scaffold.IrisWorlds;
import com.volmit.iris.scaffold.engine.IrisAccess;
import com.volmit.iris.scaffold.parallax.ParallaxAccess;
import com.volmit.iris.util.*;
import lombok.Data;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -18,10 +19,11 @@ public class DustRevealer {
public static void spawn(Block block, MortarSender sender)
{
World world = block.getWorld();
IrisAccess access = IrisWorlds.access(world);
if(world.getGenerator() instanceof EngineCompositeGenerator)
if(access != null)
{
ParallaxAccess a = ((EngineCompositeGenerator)world.getGenerator()).getComposite().getEngineForHeight(block.getY()).getParallax();
ParallaxAccess a = access.getEngineAccess(block.getY()).getParallaxAccess();
if(a.getObject(block.getX(), block.getY(), block.getZ()) != null)
{
@ -43,6 +45,7 @@ public class DustRevealer {
J.s(() -> {
new BlockSignal(world.getBlockAt(block.getX(), block.getY(), block.getZ()), 100);
J.a(() -> {
try {
is(new BlockPosition(block.getX() + 1, block.getY(), block.getZ()));
is(new BlockPosition(block.getX() - 1, block.getY(), block.getZ()));
is(new BlockPosition(block.getX(), block.getY() + 1, block.getZ()));
@ -69,6 +72,12 @@ public class DustRevealer {
is(new BlockPosition(block.getX()+1, block.getY() + 1, block.getZ() + 1));
is(new BlockPosition(block.getX()+1, block.getY() - 1, block.getZ() - 1));
is(new BlockPosition(block.getX()+1, block.getY() - 1, block.getZ() + 1));
}
catch(Throwable e)
{
e.printStackTrace();
}
});
}, RNG.r.i(3,6));
}
@ -78,6 +87,7 @@ public class DustRevealer {
{
hits.add(a);
new DustRevealer(parallax, world, a, key, hits);
return true;
}
return false;

View File

@ -26,8 +26,6 @@ import java.util.Arrays;
public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootProvider, BlockUpdater, Renderer, Hotloadable {
public void close();
public int getCurrentlyGenerating();
public boolean isClosed();
public EngineWorldManager getWorldManager();
@ -42,6 +40,8 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
public void setMinHeight(int min);
public void recycle();
public int getIndex();
public int getMinHeight();

View File

@ -784,6 +784,11 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
@Override
public boolean isFailing() {
if(getComposite() == null)
{
return false;
}
return getComposite().isFailing();
}

View File

@ -23,8 +23,6 @@ public interface EngineCompound extends Listener, Hotloadable, DataProvider
public World getWorld();
public int getCurrentlyGeneratingEngines();
public void printMetrics(CommandSender sender);
public int getSize();
@ -67,6 +65,14 @@ public interface EngineCompound extends Listener, Hotloadable, DataProvider
return getEngine(getSize() - 1);
}
public default void recycle()
{
for(int i = 0; i < getSize(); i++)
{
getEngine(i).recycle();
}
}
public default void save()
{
saveEngineMetadata();

View File

@ -65,8 +65,6 @@ public class HunkRegionSlice<T>
}
public void clear()
{
synchronized(save)
{
for(String i : new KList<>(compound.getValue().keySet()))
{
@ -76,7 +74,6 @@ public class HunkRegionSlice<T>
}
}
}
}
public void save()
{
@ -132,7 +129,7 @@ public class HunkRegionSlice<T>
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
}
public synchronized int unloadAll()
public int unloadAll()
{
int v = 0;
for(ChunkPosition i : loadedChunks.k())
@ -147,7 +144,7 @@ public class HunkRegionSlice<T>
return v;
}
public synchronized void save(Hunk<T> region, int x, int z)
public void save(Hunk<T> region, int x, int z)
{
try
{
@ -164,7 +161,7 @@ public class HunkRegionSlice<T>
return loadedChunks.containsKey(new ChunkPosition(x, z));
}
public synchronized void save(int x, int z)
public void save(int x, int z)
{
if(isLoaded(x, z))
{
@ -172,7 +169,7 @@ public class HunkRegionSlice<T>
}
}
public synchronized void unload(int x, int z)
public void unload(int x, int z)
{
ChunkPosition key = new ChunkPosition(x, z);
if(isLoaded(x, z))
@ -188,7 +185,7 @@ public class HunkRegionSlice<T>
}
}
public synchronized Hunk<T> load(int x, int z)
public Hunk<T> load(int x, int z)
{
if(isLoaded(x, z))
{

View File

@ -27,6 +27,8 @@ public class ParallaxChunkMeta {
dos.writeByte(parallaxChunkMeta.getMinObject() + Byte.MIN_VALUE);
dos.writeByte(parallaxChunkMeta.getMaxObject() + Byte.MIN_VALUE);
}
dos.writeInt(parallaxChunkMeta.count);
}
@Override
@ -37,7 +39,7 @@ public class ParallaxChunkMeta {
boolean o = din.readBoolean();
int min = o ? din.readByte() - Byte.MIN_VALUE : -1;
int max = o ? din.readByte() - Byte.MIN_VALUE : -1;
return new ParallaxChunkMeta(bb, g, p, o, min, max);
return new ParallaxChunkMeta(bb, g, p, o, min, max, din.readInt());
}
};
@ -47,9 +49,10 @@ public class ParallaxChunkMeta {
private boolean objects;
private int maxObject = -1;
private int minObject = -1;
private int count;
public ParallaxChunkMeta()
{
this(false, false, false, false, -1, -1);
this(false, false, false, false, -1, -1, 0);
}
}

View File

@ -2,7 +2,6 @@ package com.volmit.iris.scaffold.parallax;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.J;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
@ -17,7 +16,6 @@ public class ParallaxWorld implements ParallaxAccess
private final KList<Long> save;
private final File folder;
private final int height;
private final ChronoLatch cleanup;
public ParallaxWorld(int height, File folder)
{
@ -25,7 +23,6 @@ public class ParallaxWorld implements ParallaxAccess
this.folder = folder;
save = new KList<>();
loadedRegions = new KMap<>();
cleanup = new ChronoLatch(5000);
folder.mkdirs();
}
@ -124,11 +121,6 @@ public class ParallaxWorld implements ParallaxAccess
ParallaxRegion v = new ParallaxRegion(height, folder, x, z);
loadedRegions.put(key(x, z), v);
if(cleanup.flip())
{
cleanup();
}
return v;
}

View File

@ -645,7 +645,6 @@ Runnable rr = () ->
try
{
vv.add("Parallelism: " + access().getCompound().getCurrentlyGeneratingEngines());
vv.add("Plax Cache : " + Form.f(access().getParallaxChunkCount()));
}