Hunk Slices!

This commit is contained in:
Daniel Mills 2020-10-27 22:14:32 -04:00
parent 39b4649a04
commit aff7e49024
7 changed files with 521 additions and 422 deletions

View File

@ -116,26 +116,56 @@ public class Iris extends MortarPlugin
}
private static boolean doesSupport3DBiomes()
{
try
{
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
return v >= 15;
}
catch(Throwable e)
{
}
return false;
}
private static boolean doesSupportCustomModels()
{
try
{
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
return v >= 14;
}
catch(Throwable e)
{
}
return false;
}
private static boolean doesSupportAwareness()
{
try
{
int v = Integer.parseInt(Bukkit.getBukkitVersion().split("\\Q-\\E")[0].split("\\Q.\\E")[1]);
return v >= 15;
}
catch(Throwable e)
{
}
return false;
}
@Override
public void start()
{
@ -281,17 +311,22 @@ public class Iris extends MortarPlugin
public static void msg(String string)
{
lock.lock();
try
{
if(instance == null)
{
System.out.println("[Iris]: " + string);
lock.unlock();
return;
}
String msg = C.GRAY + "[" + C.GREEN + "Iris" + C.GRAY + "]: " + string;
Bukkit.getConsoleSender().sendMessage(msg);
lock.unlock();
}
catch(Throwable e)
{
System.out.println("[Iris]: " + string);
}
}
public static File getCached(String name, String url)
@ -388,6 +423,13 @@ public class Iris extends MortarPlugin
}
public static void verbose(String string)
{
if(true)
{
System.out.println(string);
}
try
{
if(IrisSettings.get().verbose)
{
@ -395,6 +437,12 @@ public class Iris extends MortarPlugin
}
}
catch(Throwable e)
{
msg(C.GRAY + string);
}
}
public static void success(String string)
{
msg(C.GREEN + string);

View File

@ -1,15 +1,18 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.util.CompoundTag;
import lombok.Getter;
import java.io.File;
import java.io.IOException;
import org.bukkit.block.data.BlockData;
import java.io.File;
import com.volmit.iris.util.CompoundTag;
public class HunkCompoundRegion extends HunkRegion {
import lombok.Getter;
public class HunkCompoundRegion extends HunkRegion
{
@Getter
private HunkRegionSlice<BlockData> parallaxSlice;
private HunkRegionSlice<BlockData> blockSlice;
@Getter
private HunkRegionSlice<String> objectSlice;
@Getter
@ -17,21 +20,39 @@ public class HunkCompoundRegion extends HunkRegion {
private final int height;
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound) {
public HunkCompoundRegion(int height, File folder, int x, int z, CompoundTag compound)
{
super(folder, x, z, compound);
this.height = height;
setupSlices();
}
public HunkCompoundRegion(int height, File folder, int x, int z) {
public HunkCompoundRegion(int height, File folder, int x, int z)
{
super(folder, x, z);
this.height = height;
setupSlices();
}
private void setupSlices() {
parallaxSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
private void setupSlices()
{
blockSlice = HunkRegionSlice.BLOCKDATA.apply(height, getCompound());
objectSlice = HunkRegionSlice.STRING.apply(height, getCompound(), "objects");
updateSlice = HunkRegionSlice.BOOLEAN.apply(height, getCompound(), "updates");
}
public void save() throws IOException
{
blockSlice.save();
objectSlice.save();
updateSlice.save();
super.save();
}
public void unload()
{
blockSlice.unloadAll();
objectSlice.unloadAll();
updateSlice.unloadAll();
}
}

View File

@ -1,16 +1,19 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NBTInputStream;
import com.volmit.iris.util.NBTOutputStream;
import lombok.Data;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import com.volmit.iris.Iris;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NBTInputStream;
import com.volmit.iris.util.NBTOutputStream;
import com.volmit.iris.util.Tag;
import lombok.Data;
@Data
public class HunkRegion
@ -20,15 +23,17 @@ public class HunkRegion
private final int x;
private final int z;
public HunkRegion(File folder, int x, int z, CompoundTag compound) {
this.compound = compound;
public HunkRegion(File folder, int x, int z, CompoundTag compound)
{
this.compound = fix(compound);
this.folder = folder;
this.x = x;
this.z = z;
folder.mkdirs();
}
public HunkRegion(File folder, int x, int z) {
public HunkRegion(File folder, int x, int z)
{
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
File f = getFile();
@ -37,7 +42,7 @@ public class HunkRegion
try
{
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
compound = (CompoundTag) in.readTag();
compound = fix((CompoundTag) in.readTag());
in.close();
}
@ -48,6 +53,18 @@ public class HunkRegion
}
}
private CompoundTag fix(CompoundTag readTag)
{
Map<String, Tag> v = readTag.getValue();
if(!(v instanceof KMap))
{
return new CompoundTag(readTag.getName(), new KMap<String, Tag>(v));
}
return readTag;
}
public File getFile()
{
return new File(folder, x + "." + z + ".dat");
@ -62,6 +79,7 @@ public class HunkRegion
NBTOutputStream out = new NBTOutputStream(fos);
out.writeTag(compound);
out.close();
Iris.verbose("Saved Region: " + getX() + " " + getZ());
}
}
}

View File

@ -1,17 +1,21 @@
package com.volmit.iris.gen.v2.scaffold.hunk.io;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisObject;
import com.volmit.iris.util.*;
import org.bukkit.block.Biome;
import java.io.IOException;
import org.bukkit.block.data.BlockData;
import java.io.IOException;
import java.util.function.Function;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.util.ByteArrayTag;
import com.volmit.iris.util.CompoundTag;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.Tag;
public class HunkRegionSlice<T> {
public class HunkRegionSlice<T>
{
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
@ -35,6 +39,8 @@ public class HunkRegionSlice<T> {
}
public void clear()
{
synchronized(save)
{
for(String i : new KList<>(compound.getValue().keySet()))
{
@ -44,6 +50,17 @@ public class HunkRegionSlice<T> {
}
}
}
}
public void save()
{
for(short i : save)
{
save((byte) (i & 0xFF), (byte) ((i >> 8) & 0xFF));
}
save.clear();
}
public boolean contains(int x, int z)
{
@ -61,6 +78,7 @@ public class HunkRegionSlice<T> {
if(!(t instanceof ByteArrayTag))
{
Iris.verbose("NOT BYTE ARRAY!");
return null;
}
@ -69,10 +87,10 @@ public class HunkRegionSlice<T> {
public void write(Hunk<T> hunk, int x, int z) throws IOException
{
compound.getValue().put(key(x,z), hunk.writeByteArrayTag(adapter, key));
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
}
public synchronized void close()
public synchronized void unloadAll()
{
for(Short i : loadedChunks.k())
{
@ -85,9 +103,12 @@ public class HunkRegionSlice<T> {
public synchronized void save(Hunk<T> region, int x, int z)
{
try {
try
{
write(region, x, z);
} catch (IOException e) {
}
catch(IOException e)
{
e.printStackTrace();
}
}
@ -132,9 +153,13 @@ public class HunkRegionSlice<T> {
if(contains(x, z))
{
try {
try
{
v = read(x, z);
} catch (IOException e) {
}
catch(IOException e)
{
e.printStackTrace();
}
}

View File

@ -1,15 +1,17 @@
package com.volmit.iris.gen.v2.scaffold.parallax;
import java.io.File;
import java.io.IOException;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.gen.v2.scaffold.hunk.Hunk;
import com.volmit.iris.gen.v2.scaffold.hunk.io.HunkCompoundRegion;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import org.bukkit.block.data.BlockData;
import java.io.File;
import java.io.IOException;
public class ParallaxWorld implements ParallaxAccess {
public class ParallaxWorld implements ParallaxAccess
{
private final KMap<Long, HunkCompoundRegion> loadedRegions;
private final KList<Long> save;
private final File folder;
@ -37,9 +39,13 @@ public class ParallaxWorld implements ParallaxAccess {
public synchronized void save(HunkCompoundRegion region)
{
try {
try
{
region.save();
} catch (IOException e) {
}
catch(IOException e)
{
e.printStackTrace();
}
}
@ -69,7 +75,7 @@ public class ParallaxWorld implements ParallaxAccess {
save.remove(key);
}
loadedRegions.remove(key);
loadedRegions.remove(key).unload();
}
}
@ -111,32 +117,38 @@ public class ParallaxWorld implements ParallaxAccess {
}
@Override
public Hunk<BlockData> getBlocksR(int x, int z) {
return getR(x>>5, z>>5).getParallaxSlice().getR(x & 31,z & 31);
public Hunk<BlockData> getBlocksR(int x, int z)
{
return getR(x >> 5, z >> 5).getBlockSlice().getR(x & 31, z & 31);
}
@Override
public synchronized Hunk<BlockData> getBlocksRW(int x, int z) {
return getRW(x>>5, z>>5).getParallaxSlice().getRW(x & 31,z & 31);
public synchronized Hunk<BlockData> getBlocksRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
}
@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);
}
@Override
public synchronized Hunk<String> getObjectsRW(int x, int z) {
public synchronized Hunk<String> getObjectsRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
}
@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);
}
@Override
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z) {
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z)
{
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
}
}

View File

@ -1,38 +1,5 @@
package com.volmit.iris.util;
/*
* JNBT License
*
* Copyright (c) 2010 Graham Edgecombe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the JNBT team nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import java.util.Collections;
import java.util.Map;
/**
@ -41,7 +8,8 @@ import java.util.Map;
* @author Graham Edgecombe
*
*/
public final class CompoundTag extends Tag {
public final class CompoundTag extends Tag
{
/**
* The value.
@ -51,29 +19,36 @@ public final class CompoundTag extends Tag {
/**
* Creates the tag.
*
* @param name The name.
* @param value The value.
* @param name
* The name.
* @param value
* The value.
*/
public CompoundTag(String name, Map<String, Tag> value) {
public CompoundTag(String name, Map<String, Tag> value)
{
super(name);
this.value = Collections.unmodifiableMap(value);
this.value = value;
}
@Override
public Map<String, Tag> getValue() {
public Map<String, Tag> getValue()
{
return value;
}
@Override
public String toString() {
public String toString()
{
String name = getName();
String append = "";
if (name != null && !name.equals("")) {
if(name != null && !name.equals(""))
{
append = "(\"" + this.getName() + "\")";
}
StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n");
for (Map.Entry<String, Tag> entry : value.entrySet()) {
for(Map.Entry<String, Tag> entry : value.entrySet())
{
bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n");
}
bldr.append("}");

View File

@ -16,7 +16,7 @@ public class KMap<K, V> extends ConcurrentHashMap<K, V>
super();
}
public KMap(KMap<K, V> gMap)
public KMap(Map<K, V> gMap)
{
this();
put(gMap);