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

View File

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

View File

@ -12,6 +12,9 @@ public class CommandIrisStudio extends MortarCommand
@Command @Command
private CommandIrisStudioCreate create; private CommandIrisStudioCreate create;
@Command
private CommandIrisStudioFix fix;
@Command @Command
private CommandIrisStudioOpen open; 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; package com.volmit.iris.manager.edit;
import com.volmit.iris.util.*; import com.volmit.iris.scaffold.IrisWorlds;
import com.volmit.iris.scaffold.engine.EngineCompositeGenerator; import com.volmit.iris.scaffold.engine.IrisAccess;
import com.volmit.iris.scaffold.parallax.ParallaxAccess; import com.volmit.iris.scaffold.parallax.ParallaxAccess;
import com.volmit.iris.util.*;
import lombok.Data; import lombok.Data;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -18,10 +19,11 @@ public class DustRevealer {
public static void spawn(Block block, MortarSender sender) public static void spawn(Block block, MortarSender sender)
{ {
World world = block.getWorld(); 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) if(a.getObject(block.getX(), block.getY(), block.getZ()) != null)
{ {
@ -43,32 +45,39 @@ public class DustRevealer {
J.s(() -> { J.s(() -> {
new BlockSignal(world.getBlockAt(block.getX(), block.getY(), block.getZ()), 100); new BlockSignal(world.getBlockAt(block.getX(), block.getY(), block.getZ()), 100);
J.a(() -> { J.a(() -> {
is(new BlockPosition(block.getX() + 1, block.getY(), block.getZ())); 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())); is(new BlockPosition(block.getX() - 1, block.getY(), block.getZ()));
is(new BlockPosition(block.getX(), block.getY() - 1, block.getZ())); is(new BlockPosition(block.getX(), block.getY() + 1, block.getZ()));
is(new BlockPosition(block.getX(), block.getY(), block.getZ() + 1)); is(new BlockPosition(block.getX(), block.getY() - 1, block.getZ()));
is(new BlockPosition(block.getX(), block.getY(), block.getZ() - 1)); is(new BlockPosition(block.getX(), block.getY(), block.getZ() + 1));
is(new BlockPosition(block.getX() + 1, block.getY(), block.getZ() + 1)); is(new BlockPosition(block.getX(), block.getY(), block.getZ() - 1));
is(new BlockPosition(block.getX() + 1, block.getY(), block.getZ() - 1)); is(new BlockPosition(block.getX() + 1, block.getY(), block.getZ() + 1));
is(new BlockPosition(block.getX() - 1, block.getY(), block.getZ() + 1)); is(new BlockPosition(block.getX() + 1, block.getY(), block.getZ() - 1));
is(new BlockPosition(block.getX() - 1, block.getY(), block.getZ() - 1)); is(new BlockPosition(block.getX() - 1, block.getY(), block.getZ() + 1));
is(new BlockPosition(block.getX() + 1, block.getY() + 1, block.getZ())); is(new BlockPosition(block.getX() - 1, block.getY(), block.getZ() - 1));
is(new BlockPosition(block.getX() + 1, block.getY() - 1, block.getZ())); is(new BlockPosition(block.getX() + 1, block.getY() + 1, block.getZ()));
is(new BlockPosition(block.getX() - 1, block.getY() + 1, block.getZ())); is(new BlockPosition(block.getX() + 1, block.getY() - 1, block.getZ()));
is(new BlockPosition(block.getX() - 1, block.getY() - 1, block.getZ())); is(new BlockPosition(block.getX() - 1, block.getY() + 1, block.getZ()));
is(new BlockPosition(block.getX(), block.getY() + 1, block.getZ() - 1)); is(new BlockPosition(block.getX() - 1, block.getY() - 1, block.getZ()));
is(new BlockPosition(block.getX(), block.getY() + 1, block.getZ() + 1)); is(new BlockPosition(block.getX(), block.getY() + 1, block.getZ() - 1));
is(new BlockPosition(block.getX(), block.getY() - 1, block.getZ() - 1)); is(new BlockPosition(block.getX(), block.getY() + 1, block.getZ() + 1));
is(new BlockPosition(block.getX(), block.getY() - 1, block.getZ() + 1)); is(new BlockPosition(block.getX(), block.getY() - 1, block.getZ() - 1));
is(new BlockPosition(block.getX()-1, block.getY() + 1, block.getZ() - 1)); is(new BlockPosition(block.getX(), 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));
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)); 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));
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)); 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));
is(new BlockPosition(block.getX()+1, block.getY() - 1, block.getZ() + 1));
}
catch(Throwable e)
{
e.printStackTrace();
}
}); });
}, RNG.r.i(3,6)); }, RNG.r.i(3,6));
} }
@ -78,6 +87,7 @@ public class DustRevealer {
{ {
hits.add(a); hits.add(a);
new DustRevealer(parallax, world, a, key, hits); new DustRevealer(parallax, world, a, key, hits);
return true;
} }
return false; return false;

View File

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

View File

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

View File

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

View File

@ -35,7 +35,7 @@ public class HunkRegionSlice<T>
this.lastUse = new KMap<>(); this.lastUse = new KMap<>();
} }
public int cleanup(long t) public int cleanup(long t)
{ {
int v = 0; int v = 0;
if(loadedChunks.size() != lastUse.size()) if(loadedChunks.size() != lastUse.size())
@ -64,21 +64,18 @@ public class HunkRegionSlice<T>
return v; return v;
} }
public void clear() public void clear()
{ {
synchronized(save) for(String i : new KList<>(compound.getValue().keySet()))
{ {
for(String i : new KList<>(compound.getValue().keySet())) if(i.startsWith(key + "."))
{ {
if(i.startsWith(key + ".")) compound.getValue().remove(i);
{
compound.getValue().remove(i);
}
} }
} }
} }
public void save() public void save()
{ {
BurstExecutor e = MultiBurst.burst.burst(); BurstExecutor e = MultiBurst.burst.burst();
for(ChunkPosition i : save.copy()) for(ChunkPosition i : save.copy())
@ -104,17 +101,17 @@ public class HunkRegionSlice<T>
e.complete(); e.complete();
} }
public boolean contains(int x, int z) public boolean contains(int x, int z)
{ {
return compound.getValue().containsKey(key(x, z)); return compound.getValue().containsKey(key(x, z));
} }
public void delete(int x, int z) public void delete(int x, int z)
{ {
compound.getValue().remove(key(x, z)); compound.getValue().remove(key(x, z));
} }
public Hunk<T> read(int x, int z) throws IOException public Hunk<T> read(int x, int z) throws IOException
{ {
Tag t = compound.getValue().get(key(x, z)); Tag t = compound.getValue().get(key(x, z));
@ -127,12 +124,12 @@ public class HunkRegionSlice<T>
return adapter.read(factory, (ByteArrayTag) t); return adapter.read(factory, (ByteArrayTag) t);
} }
public void write(Hunk<T> hunk, int x, int z) throws IOException public void write(Hunk<T> hunk, int x, int z) throws IOException
{ {
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z))); compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
} }
public synchronized int unloadAll() public int unloadAll()
{ {
int v = 0; int v = 0;
for(ChunkPosition i : loadedChunks.k()) for(ChunkPosition i : loadedChunks.k())
@ -147,7 +144,7 @@ public class HunkRegionSlice<T>
return v; return v;
} }
public synchronized void save(Hunk<T> region, int x, int z) public void save(Hunk<T> region, int x, int z)
{ {
try try
{ {
@ -159,12 +156,12 @@ public class HunkRegionSlice<T>
} }
} }
public boolean isLoaded(int x, int z) public boolean isLoaded(int x, int z)
{ {
return loadedChunks.containsKey(new ChunkPosition(x, z)); 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)) 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); ChunkPosition key = new ChunkPosition(x, z);
if(isLoaded(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)) if(isLoaded(x, z))
{ {
@ -220,7 +217,7 @@ public class HunkRegionSlice<T>
return v; return v;
} }
public Hunk<T> get(int x, int z) public Hunk<T> get(int x, int z)
{ {
ChunkPosition key = new ChunkPosition(x, z); ChunkPosition key = new ChunkPosition(x, z);
@ -236,12 +233,12 @@ public class HunkRegionSlice<T>
return c; return c;
} }
public Hunk<T> getR(int x, int z) public Hunk<T> getR(int x, int z)
{ {
return get(x, z).readOnly(); return get(x, z).readOnly();
} }
public Hunk<T> getRW(int x, int z) public Hunk<T> getRW(int x, int z)
{ {
save.addIfMissing(new ChunkPosition(x, z)); save.addIfMissing(new ChunkPosition(x, z));
return get(x, z); return get(x, z);
@ -257,7 +254,7 @@ public class HunkRegionSlice<T>
return key + "." + x + "." + z; return key + "." + x + "." + z;
} }
public int getLoadCount() public int getLoadCount()
{ {
return loadedChunks.size(); return loadedChunks.size();
} }

View File

@ -27,6 +27,8 @@ public class ParallaxChunkMeta {
dos.writeByte(parallaxChunkMeta.getMinObject() + Byte.MIN_VALUE); dos.writeByte(parallaxChunkMeta.getMinObject() + Byte.MIN_VALUE);
dos.writeByte(parallaxChunkMeta.getMaxObject() + Byte.MIN_VALUE); dos.writeByte(parallaxChunkMeta.getMaxObject() + Byte.MIN_VALUE);
} }
dos.writeInt(parallaxChunkMeta.count);
} }
@Override @Override
@ -37,7 +39,7 @@ public class ParallaxChunkMeta {
boolean o = din.readBoolean(); boolean o = din.readBoolean();
int min = o ? din.readByte() - Byte.MIN_VALUE : -1; int min = o ? din.readByte() - Byte.MIN_VALUE : -1;
int max = 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 boolean objects;
private int maxObject = -1; private int maxObject = -1;
private int minObject = -1; private int minObject = -1;
private int count;
public ParallaxChunkMeta() public ParallaxChunkMeta()
{ {
this(false, false, false, false, -1, -1); this(false, false, false, false, -1, -1, 0);
} }
} }

View File

@ -49,17 +49,17 @@ public class ParallaxRegion extends HunkRegion
lastUse = M.ms(); lastUse = M.ms();
} }
public boolean hasBeenIdleLongerThan(long time) public boolean hasBeenIdleLongerThan(long time)
{ {
return M.ms() - lastUse > time; return M.ms() - lastUse > time;
} }
public ParallaxChunkMeta getMetaR(int x, int z) public ParallaxChunkMeta getMetaR(int x, int z)
{ {
return getMetaHunkR().getOr(x, 0, z, new ParallaxChunkMeta()); return getMetaHunkR().getOr(x, 0, z, new ParallaxChunkMeta());
} }
public ParallaxChunkMeta getMetaRW(int x, int z) public ParallaxChunkMeta getMetaRW(int x, int z)
{ {
lastUse = M.ms(); lastUse = M.ms();
dirtyMeta = true; dirtyMeta = true;
@ -73,7 +73,7 @@ public class ParallaxRegion extends HunkRegion
return p; return p;
} }
private Hunk<ParallaxChunkMeta> getMetaHunkR() private Hunk<ParallaxChunkMeta> getMetaHunkR()
{ {
if(meta == null) if(meta == null)
{ {
@ -83,13 +83,13 @@ public class ParallaxRegion extends HunkRegion
return meta; return meta;
} }
private Hunk<ParallaxChunkMeta> getMetaHunkRW() private Hunk<ParallaxChunkMeta> getMetaHunkRW()
{ {
dirtyMeta = true; dirtyMeta = true;
return getMetaHunkR(); return getMetaHunkR();
} }
public Hunk<ParallaxChunkMeta> loadMetaHunk() public Hunk<ParallaxChunkMeta> loadMetaHunk()
{ {
lastUse = M.ms(); lastUse = M.ms();
if(meta == null) if(meta == null)
@ -114,7 +114,7 @@ public class ParallaxRegion extends HunkRegion
return meta; return meta;
} }
public void unloadMetaHunk() public void unloadMetaHunk()
{ {
if(dirtyMeta) if(dirtyMeta)
{ {
@ -125,7 +125,7 @@ public class ParallaxRegion extends HunkRegion
meta = null; meta = null;
} }
public void saveMetaHunk() public void saveMetaHunk()
{ {
if(meta != null && dirtyMeta) if(meta != null && dirtyMeta)
{ {
@ -138,7 +138,7 @@ public class ParallaxRegion extends HunkRegion
} }
} }
public void save() throws IOException public void save() throws IOException
{ {
blockSlice.save(); blockSlice.save();
objectSlice.save(); objectSlice.save();
@ -147,7 +147,7 @@ public class ParallaxRegion extends HunkRegion
super.save(); super.save();
} }
public int unload() public int unload()
{ {
unloadMetaHunk(); unloadMetaHunk();
return blockSlice.unloadAll()+ return blockSlice.unloadAll()+
@ -155,28 +155,28 @@ public class ParallaxRegion extends HunkRegion
updateSlice.unloadAll(); updateSlice.unloadAll();
} }
public HunkRegionSlice<BlockData> getBlockSlice() { public HunkRegionSlice<BlockData> getBlockSlice() {
lastUse = M.ms(); lastUse = M.ms();
return blockSlice; return blockSlice;
} }
public HunkRegionSlice<String> getObjectSlice() { public HunkRegionSlice<String> getObjectSlice() {
lastUse = M.ms(); lastUse = M.ms();
return objectSlice; return objectSlice;
} }
public HunkRegionSlice<Boolean> getUpdateSlice() { public HunkRegionSlice<Boolean> getUpdateSlice() {
lastUse = M.ms(); lastUse = M.ms();
return updateSlice; return updateSlice;
} }
public int cleanup(long c) { public int cleanup(long c) {
return blockSlice.cleanup(c) + return blockSlice.cleanup(c) +
objectSlice.cleanup(c) + objectSlice.cleanup(c) +
updateSlice.cleanup(c); updateSlice.cleanup(c);
} }
public int getChunkCount() { public int getChunkCount() {
return blockSlice.getLoadCount() + objectSlice.getLoadCount() + updateSlice.getLoadCount(); return blockSlice.getLoadCount() + objectSlice.getLoadCount() + updateSlice.getLoadCount();
} }
} }

View File

@ -2,7 +2,6 @@ package com.volmit.iris.scaffold.parallax;
import com.volmit.iris.IrisSettings; import com.volmit.iris.IrisSettings;
import com.volmit.iris.scaffold.hunk.Hunk; import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.J; import com.volmit.iris.util.J;
import com.volmit.iris.util.KList; import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap; import com.volmit.iris.util.KMap;
@ -17,7 +16,6 @@ public class ParallaxWorld implements ParallaxAccess
private final KList<Long> save; private final KList<Long> save;
private final File folder; private final File folder;
private final int height; private final int height;
private final ChronoLatch cleanup;
public ParallaxWorld(int height, File folder) public ParallaxWorld(int height, File folder)
{ {
@ -25,16 +23,15 @@ public class ParallaxWorld implements ParallaxAccess
this.folder = folder; this.folder = folder;
save = new KList<>(); save = new KList<>();
loadedRegions = new KMap<>(); loadedRegions = new KMap<>();
cleanup = new ChronoLatch(5000);
folder.mkdirs(); folder.mkdirs();
} }
public int getRegionCount() public int getRegionCount()
{ {
return loadedRegions.size(); return loadedRegions.size();
} }
public int getChunkCount() public int getChunkCount()
{ {
int m = 0; int m = 0;
@ -54,7 +51,7 @@ public class ParallaxWorld implements ParallaxAccess
return m; return m;
} }
public void close() public void close()
{ {
for(ParallaxRegion i : loadedRegions.v()) for(ParallaxRegion i : loadedRegions.v())
{ {
@ -65,7 +62,7 @@ public class ParallaxWorld implements ParallaxAccess
loadedRegions.clear(); loadedRegions.clear();
} }
public void save(ParallaxRegion region) public void save(ParallaxRegion region)
{ {
try try
{ {
@ -78,12 +75,12 @@ public class ParallaxWorld implements ParallaxAccess
} }
} }
public boolean isLoaded(int x, int z) public boolean isLoaded(int x, int z)
{ {
return loadedRegions.containsKey(key(x, z)); return loadedRegions.containsKey(key(x, z));
} }
public void save(int x, int z) public void save(int x, int z)
{ {
if(isLoaded(x, z)) if(isLoaded(x, z))
{ {
@ -91,7 +88,7 @@ public class ParallaxWorld implements ParallaxAccess
} }
} }
public int unload(int x, int z) public int unload(int x, int z)
{ {
long key = key(x, z); long key = key(x, z);
int v = 0; int v = 0;
@ -114,7 +111,7 @@ public class ParallaxWorld implements ParallaxAccess
return v; return v;
} }
public ParallaxRegion load(int x, int z) public ParallaxRegion load(int x, int z)
{ {
if(isLoaded(x, z)) if(isLoaded(x, z))
{ {
@ -124,15 +121,10 @@ public class ParallaxWorld implements ParallaxAccess
ParallaxRegion v = new ParallaxRegion(height, folder, x, z); ParallaxRegion v = new ParallaxRegion(height, folder, x, z);
loadedRegions.put(key(x, z), v); loadedRegions.put(key(x, z), v);
if(cleanup.flip())
{
cleanup();
}
return v; return v;
} }
public ParallaxRegion getR(int x, int z) public ParallaxRegion getR(int x, int z)
{ {
long key = key(x, z); long key = key(x, z);
@ -146,7 +138,7 @@ public class ParallaxWorld implements ParallaxAccess
return region; return region;
} }
public ParallaxRegion getRW(int x, int z) public ParallaxRegion getRW(int x, int z)
{ {
save.addIfMissing(key(x, z)); save.addIfMissing(key(x, z));
return getR(x, z); return getR(x, z);
@ -158,60 +150,60 @@ public class ParallaxWorld implements ParallaxAccess
} }
@Override @Override
public Hunk<BlockData> getBlocksR(int x, int z) public Hunk<BlockData> getBlocksR(int x, int z)
{ {
return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31); return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31);
} }
@Override @Override
public Hunk<BlockData> getBlocksRW(int x, int z) public Hunk<BlockData> getBlocksRW(int x, int z)
{ {
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31); return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
} }
@Override @Override
public Hunk<String> getObjectsR(int x, int z) public Hunk<String> getObjectsR(int x, int z)
{ {
return getR(x >> 5, z >> 5).getObjectSlice().getR(x & 31, z & 31); return getR(x >> 5, z >> 5).getObjectSlice().getR(x & 31, z & 31);
} }
@Override @Override
public Hunk<String> getObjectsRW(int x, int z) public Hunk<String> getObjectsRW(int x, int z)
{ {
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31); return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
} }
@Override @Override
public Hunk<Boolean> getUpdatesR(int x, int z) public Hunk<Boolean> getUpdatesR(int x, int z)
{ {
return getR(x >> 5, z >> 5).getUpdateSlice().getR(x & 31, z & 31); return getR(x >> 5, z >> 5).getUpdateSlice().getR(x & 31, z & 31);
} }
@Override @Override
public Hunk<Boolean> getUpdatesRW(int x, int z) public Hunk<Boolean> getUpdatesRW(int x, int z)
{ {
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31); return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
} }
@Override @Override
public ParallaxChunkMeta getMetaR(int x, int z) public ParallaxChunkMeta getMetaR(int x, int z)
{ {
return getR(x >> 5, z >> 5).getMetaR(x & 31, z & 31); return getR(x >> 5, z >> 5).getMetaR(x & 31, z & 31);
} }
@Override @Override
public ParallaxChunkMeta getMetaRW(int x, int z) public ParallaxChunkMeta getMetaRW(int x, int z)
{ {
return getRW(x >> 5, z >> 5).getMetaRW(x & 31, z & 31); return getRW(x >> 5, z >> 5).getMetaRW(x & 31, z & 31);
} }
public void cleanup() public void cleanup()
{ {
cleanup(IrisSettings.get().getParallaxRegionEvictionMS(), IrisSettings.get().getParallaxChunkEvictionMS()); cleanup(IrisSettings.get().getParallaxRegionEvictionMS(), IrisSettings.get().getParallaxChunkEvictionMS());
} }
@Override @Override
public void cleanup(long r, long c) { public void cleanup(long r, long c) {
J.a(() -> { J.a(() -> {
try try
{ {
@ -241,12 +233,12 @@ public class ParallaxWorld implements ParallaxAccess
} }
@Override @Override
public void saveAll() { public void saveAll() {
J.a(this::saveAllNOW); J.a(this::saveAllNOW);
} }
@Override @Override
public void saveAllNOW() { public void saveAllNOW() {
for(ParallaxRegion i : loadedRegions.v()) for(ParallaxRegion i : loadedRegions.v())
{ {
if(save.contains(key(i.getX(), i.getZ()))) if(save.contains(key(i.getX(), i.getZ())))

View File

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