Parallax support tile data

This commit is contained in:
Daniel Mills 2021-01-13 09:44:49 -05:00
parent 1d052231f0
commit 2a51454682
3 changed files with 44 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package com.volmit.iris.scaffold.parallax;
import com.volmit.iris.object.tile.TileData;
import com.volmit.iris.scaffold.hunk.Hunk;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
public interface ParallaxAccess {
@ -12,6 +14,14 @@ public interface ParallaxAccess {
getBlocksRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d);
}
default TileData<? extends TileState> getTile(int x, int y, int z) {
return getTilesR(x >> 4, z >> 4).get(x & 15, y, z & 15);
}
default void setTile(int x, int y, int z, TileData<? extends TileState> d) {
getTilesRW(x >> 4, z >> 4).set(x & 15, y, z & 15, d);
}
default String getObject(int x, int y, int z) {
return getObjectsR(x >> 4, z >> 4).get(x & 15, y, z & 15);
}
@ -87,6 +97,10 @@ public interface ParallaxAccess {
getMetaRW(x, z).setFeatureGenerated(v);
}
public Hunk<TileData<? extends TileState>> getTilesR(int x, int z);
public Hunk<TileData<? extends TileState>> getTilesRW(int x, int z);
public Hunk<BlockData> getBlocksR(int x, int z);
public Hunk<BlockData> getBlocksRW(int x, int z);
@ -119,6 +133,7 @@ public interface ParallaxAccess {
{
getUpdatesRW(x, z).fill(false);
getBlocksRW(x, z).fill(null);
getTilesRW(x, z).fill(null);
getObjectsRW(x, z).fill(null);
}
}

View File

@ -1,5 +1,6 @@
package com.volmit.iris.scaffold.parallax;
import com.volmit.iris.object.tile.TileData;
import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.scaffold.hunk.io.HunkIOAdapter;
import com.volmit.iris.scaffold.hunk.io.HunkRegion;
@ -9,6 +10,7 @@ import com.volmit.iris.util.ByteArrayTag;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.M;
import com.volmit.iris.util.Tag;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import java.io.File;
@ -20,6 +22,7 @@ public class ParallaxRegion extends HunkRegion
private Hunk<ParallaxChunkMeta> meta;
private HunkIOAdapter<ParallaxChunkMeta> metaAdapter;
private HunkRegionSlice<BlockData> blockSlice;
private HunkRegionSlice<TileData<? extends TileState>> tileSlice;
private HunkRegionSlice<String> objectSlice;
private HunkRegionSlice<Boolean> updateSlice;
private final GridLock lock;
@ -45,6 +48,7 @@ public class ParallaxRegion extends HunkRegion
private void setupSlices()
{
blockSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
tileSlice = HunkRegionSlice.TILE.apply(height, getCompound());
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates");
metaAdapter = ParallaxChunkMeta.adapter.apply(getCompound());
@ -148,6 +152,7 @@ public class ParallaxRegion extends HunkRegion
{
blockSlice.save();
objectSlice.save();
tileSlice.save();
updateSlice.save();
saveMetaHunk();
super.save();
@ -157,7 +162,8 @@ public class ParallaxRegion extends HunkRegion
{
unloadMetaHunk();
return blockSlice.unloadAll()+
objectSlice.unloadAll()+
objectSlice.unloadAll()+
tileSlice.unloadAll()+
updateSlice.unloadAll();
}
@ -166,6 +172,11 @@ public class ParallaxRegion extends HunkRegion
return blockSlice;
}
public HunkRegionSlice<TileData<? extends TileState>> getTileSlice() {
lastUse = M.ms();
return tileSlice;
}
public HunkRegionSlice<String> getObjectSlice() {
lastUse = M.ms();
return objectSlice;
@ -178,11 +189,12 @@ public class ParallaxRegion extends HunkRegion
public synchronized int cleanup(long c) {
return blockSlice.cleanup(c) +
objectSlice.cleanup(c) +
objectSlice.cleanup(c) +
tileSlice.cleanup(c) +
updateSlice.cleanup(c);
}
public int getChunkCount() {
return blockSlice.getLoadCount() + objectSlice.getLoadCount() + updateSlice.getLoadCount();
return blockSlice.getLoadCount() + objectSlice.getLoadCount() + tileSlice.getLoadCount() + updateSlice.getLoadCount();
}
}

View File

@ -1,10 +1,12 @@
package com.volmit.iris.scaffold.parallax;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.object.tile.TileData;
import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.util.J;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import java.io.File;
@ -161,6 +163,18 @@ public class ParallaxWorld implements ParallaxAccess
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
}
@Override
public Hunk<TileData<? extends TileState>> getTilesR(int x, int z)
{
return getR(x >> 5, z >> 5).getTileSlice().getR(x & 31, z & 31);
}
@Override
public Hunk<TileData<? extends TileState>> getTilesRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getTileSlice().getRW(x & 31, z & 31);
}
@Override
public Hunk<String> getObjectsR(int x, int z)
{