9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-28 11:39:07 +00:00
This commit is contained in:
Daniel Mills
2021-08-05 18:42:34 -04:00
parent fff7cd53cc
commit ef5ba0f1d1
31 changed files with 382 additions and 329 deletions

View File

@@ -32,23 +32,17 @@ public class IrisContext {
private static ChronoLatch cl = new ChronoLatch(60000);
private static KMap<Thread, IrisContext> context = new KMap<>();
public static IrisContext get()
{
public static IrisContext get() {
return context.get(Thread.currentThread());
}
public static void touch(IrisContext c)
{
synchronized (context)
{
public static void touch(IrisContext c) {
synchronized (context) {
context.put(Thread.currentThread(), c);
if(cl.flip())
{
for(Thread i : context.k())
{
if(!i.isAlive())
{
if (cl.flip()) {
for (Thread i : context.k()) {
if (!i.isAlive()) {
context.remove(i);
}
}
@@ -58,18 +52,15 @@ public class IrisContext {
private final Engine engine;
public void touch()
{
public void touch() {
IrisContext.touch(this);
}
public IrisData getData()
{
public IrisData getData() {
return engine.getData();
}
public IrisComplex getComplex()
{
public IrisComplex getComplex() {
return engine.getFramework().getComplex();
}
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.hunk;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.basic.IrisPosition;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.function.*;
@@ -29,8 +28,6 @@ import com.volmit.iris.util.interpolation.InterpolationMethod;
import com.volmit.iris.util.interpolation.InterpolationMethod3D;
import com.volmit.iris.util.interpolation.IrisInterpolation;
import com.volmit.iris.util.math.BlockPosition;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.MathHelper;
import com.volmit.iris.util.oldnbt.ByteArrayTag;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
@@ -40,7 +37,6 @@ import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.util.Vector;
import java.io.File;
import java.io.IOException;
@@ -1273,24 +1269,23 @@ public interface Hunk<T> {
return t;
}
static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z)
{
int[] iii = {0,0,0};
int[] aaa = {w,h,d};
int[] aai = {w,h,0};
int[] iaa = {0,h,d};
int[] aia = {w,0,d};
int[] iai = {0,h,0};
int[] iia = {0,0,d};
int[] aii = {w,0,0};
rotate(x,y,z,iii);
rotate(x,y,z,aaa);
rotate(x,y,z,aai);
rotate(x,y,z,iaa);
rotate(x,y,z,aia);
rotate(x,y,z,iai);
rotate(x,y,z,iia);
rotate(x,y,z,aii);
static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) {
int[] iii = {0, 0, 0};
int[] aaa = {w, h, d};
int[] aai = {w, h, 0};
int[] iaa = {0, h, d};
int[] aia = {w, 0, d};
int[] iai = {0, h, 0};
int[] iia = {0, 0, d};
int[] aii = {w, 0, 0};
rotate(x, y, z, iii);
rotate(x, y, z, aaa);
rotate(x, y, z, aai);
rotate(x, y, z, iaa);
rotate(x, y, z, aia);
rotate(x, y, z, iai);
rotate(x, y, z, iia);
rotate(x, y, z, aii);
int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]);
@@ -1300,30 +1295,29 @@ public interface Hunk<T> {
return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ);
}
default Hunk<T> rotate(double x, double y, double z, Supplier3R<Integer, Integer, Integer, Hunk<T>> builder)
{
default Hunk<T> rotate(double x, double y, double z, Supplier3R<Integer, Integer, Integer, Hunk<T>> builder) {
int w = getWidth();
int h = getHeight();
int d = getDepth();
int i,j,k;
int[] c = {w/2,h/2,d/2};
int[] b = {0,0,0};
int[] iii = {0,0,0};
int[] aaa = {w,h,d};
int[] aai = {w,h,0};
int[] iaa = {0,h,d};
int[] aia = {w,0,d};
int[] iai = {0,h,0};
int[] iia = {0,0,d};
int[] aii = {w,0,0};
rotate(x,y,z,iii);
rotate(x,y,z,aaa);
rotate(x,y,z,aai);
rotate(x,y,z,iaa);
rotate(x,y,z,aia);
rotate(x,y,z,iai);
rotate(x,y,z,iia);
rotate(x,y,z,aii);
int i, j, k;
int[] c = {w / 2, h / 2, d / 2};
int[] b = {0, 0, 0};
int[] iii = {0, 0, 0};
int[] aaa = {w, h, d};
int[] aai = {w, h, 0};
int[] iaa = {0, h, d};
int[] aia = {w, 0, d};
int[] iai = {0, h, 0};
int[] iia = {0, 0, d};
int[] aii = {w, 0, 0};
rotate(x, y, z, iii);
rotate(x, y, z, aaa);
rotate(x, y, z, aai);
rotate(x, y, z, iaa);
rotate(x, y, z, aia);
rotate(x, y, z, iai);
rotate(x, y, z, iia);
rotate(x, y, z, aii);
int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]);
@@ -1331,26 +1325,19 @@ public interface Hunk<T> {
int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]);
int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]);
Hunk<T> r = builder.get(maxX - minX, maxY - minY, maxZ - minZ);
int[] cr = {(maxX - minX)/2,(maxY - minY)/2,(maxZ - minZ)/2};
int[] cr = {(maxX - minX) / 2, (maxY - minY) / 2, (maxZ - minZ) / 2};
for(i = 0; i < w; i++)
{
for(j = 0; j < h; j++)
{
for(k = 0; k < d; k++)
{
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
for (k = 0; k < d; k++) {
b[0] = i - c[0];
b[1] = j - c[1];
b[2] = k - c[2];
rotate(x, y, z, b);
try
{
try {
r.set(b[0] + cr[0], b[1] + cr[1], b[2] + cr[2], get(i, j, k));
}
catch(Throwable e)
{
} catch (Throwable e) {
}
}
@@ -1360,30 +1347,24 @@ public interface Hunk<T> {
return r;
}
static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{
static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
return Math.max(Math.max(Math.max(a5, a6), Math.max(a7, a8)), Math.max(Math.max(a1, a2), Math.max(a3, a4)));
}
static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
{
static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
return Math.min(Math.min(Math.min(a5, a6), Math.min(a7, a8)), Math.min(Math.min(a1, a2), Math.min(a3, a4)));
}
static void rotate(double x, double y, double z, int[] c)
{
if(x % 360 != 0)
{
static void rotate(double x, double y, double z, int[] c) {
if (x % 360 != 0) {
rotateAroundX(Math.toRadians(x), c);
}
if(y % 360 != 0)
{
if (y % 360 != 0) {
rotateAroundY(Math.toRadians(y), c);
}
if(z % 360 != 0)
{
if (z % 360 != 0) {
rotateAroundZ(Math.toRadians(z), c);
}
}
@@ -1393,8 +1374,8 @@ public interface Hunk<T> {
}
static void rotateAroundX(double cos, double sin, int[] c) {
int y = (int) Math.floor(cos * (double)(c[1]+0.5) - sin * (double)(c[2]+0.5));
int z = (int) Math.floor(sin * (double)(c[1]+0.5) + cos * (double)(c[2]+0.5));
int y = (int) Math.floor(cos * (double) (c[1] + 0.5) - sin * (double) (c[2] + 0.5));
int z = (int) Math.floor(sin * (double) (c[1] + 0.5) + cos * (double) (c[2] + 0.5));
c[1] = y;
c[2] = z;
}
@@ -1404,8 +1385,8 @@ public interface Hunk<T> {
}
static void rotateAroundY(double cos, double sin, int[] c) {
int x = (int) Math.floor(cos * (double)(c[0]+0.5) + sin * (double)(c[2]+0.5));
int z = (int) Math.floor(-sin * (double)(c[0]+0.5) + cos * (double)(c[2]+0.5));
int x = (int) Math.floor(cos * (double) (c[0] + 0.5) + sin * (double) (c[2] + 0.5));
int z = (int) Math.floor(-sin * (double) (c[0] + 0.5) + cos * (double) (c[2] + 0.5));
c[0] = x;
c[2] = z;
}
@@ -1415,8 +1396,8 @@ public interface Hunk<T> {
}
static void rotateAroundZ(double cos, double sin, int[] c) {
int x = (int) Math.floor(cos * (double)(c[0]+0.5) - sin * (double)(c[1]+0.5));
int y = (int) Math.floor(sin * (double)(c[0]+0.5) + cos * (double)(c[1]+0.5));
int x = (int) Math.floor(cos * (double) (c[0] + 0.5) - sin * (double) (c[1] + 0.5));
int y = (int) Math.floor(sin * (double) (c[0] + 0.5) + cos * (double) (c[1] + 0.5));
c[0] = x;
c[1] = y;
}

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.hunk.storage;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.hunk.Hunk;

View File

@@ -22,8 +22,6 @@ import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
import lombok.Getter;
import java.lang.reflect.InvocationTargetException;
public class IrisMatter implements Matter {
private static final KMap<Class<?>, MatterSlice<?>> slicers = buildSlicers();
@@ -40,7 +38,7 @@ public class IrisMatter implements Matter {
private final int depth;
@Getter
private KMap<Class<?>, MatterSlice<?>> sliceMap;
private final KMap<Class<?>, MatterSlice<?>> sliceMap;
public IrisMatter(int width, int height, int depth) {
this.width = width;

View File

@@ -181,20 +181,19 @@ public interface Matter {
/**
* Rotate a matter object into a new object
*
* @param x the x rotation (degrees)
* @param y the y rotation (degrees)
* @param z the z rotation (degrees)
* @return the new rotated matter object
*/
default Matter rotate(double x, double y, double z)
{
default Matter rotate(double x, double y, double z) {
IrisPosition rs = Hunk.rotatedBounding(getWidth(), getHeight(), getDepth(), x, y, z);
Matter n = new IrisMatter(rs.getX(), rs.getY(), rs.getZ());
n.getHeader().setAuthor(getHeader().getAuthor());
n.getHeader().setCreatedAt(getHeader().getCreatedAt());
for(Class<?> i : getSliceTypes())
{
for (Class<?> i : getSliceTypes()) {
getSlice(i).rotateSliceInto(n, x, y, z);
}
@@ -234,8 +233,7 @@ public interface Matter {
*/
Map<Class<?>, MatterSlice<?>> getSliceMap();
default void write(File f) throws IOException
{
default void write(File f) throws IOException {
FileOutputStream out = new FileOutputStream(f);
GZIPOutputStream gzo = new GZIPOutputStream(out);
write(gzo);
@@ -265,8 +263,7 @@ public interface Matter {
dos.flush();
}
static Matter read(File f) throws IOException, ClassNotFoundException
{
static Matter read(File f) throws IOException, ClassNotFoundException {
FileInputStream in = new FileInputStream(f);
GZIPInputStream gzi = new GZIPInputStream(in);
Matter m = read(gzi);
@@ -274,8 +271,7 @@ public interface Matter {
return m;
}
static Matter read(InputStream in) throws IOException, ClassNotFoundException
{
static Matter read(InputStream in) throws IOException, ClassNotFoundException {
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
}

View File

@@ -25,7 +25,6 @@ import com.volmit.iris.util.hunk.storage.MappedHunk;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.objectweb.asm.ClassWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -42,39 +41,30 @@ public interface MatterSlice<T> extends Hunk<T> {
<W> MatterReader<W, T> readFrom(Class<W> mediumType);
default Class<?> getClass(Object w)
{
default Class<?> getClass(Object w) {
Class<?> c = w.getClass();
if(w instanceof World)
{
if (w instanceof World) {
c = World.class;
}else if(w instanceof BlockData)
{
} else if (w instanceof BlockData) {
c = BlockData.class;
}else if(w instanceof Entity)
{
} else if (w instanceof Entity) {
c = Entity.class;
}
return c;
}
default <W> boolean writeInto(W w, int x, int y, int z)
{
default <W> boolean writeInto(W w, int x, int y, int z) {
MatterWriter<W, T> injector = (MatterWriter<W, T>) writeInto(getClass(w));
if(injector == null)
{
if (injector == null) {
return false;
}
for(int i = x; i < x + getWidth(); i++)
{
for(int j = y; j < y + getHeight(); j++)
{
for(int k = z; k < z + getDepth(); k++)
{
for (int i = x; i < x + getWidth(); i++) {
for (int j = y; j < y + getHeight(); j++) {
for (int k = z; k < z + getDepth(); k++) {
injector.writeMatter(w, get(i - x, j - y, k - z), i, j, k);
}
}
@@ -83,21 +73,16 @@ public interface MatterSlice<T> extends Hunk<T> {
return true;
}
default <W> boolean readFrom(W w, int x, int y, int z)
{
default <W> boolean readFrom(W w, int x, int y, int z) {
MatterReader<W, T> ejector = (MatterReader<W, T>) readFrom(getClass(w));
if(ejector == null)
{
if (ejector == null) {
return false;
}
for(int i = x; i < x + getWidth(); i++)
{
for(int j = y; j < y + getHeight(); j++)
{
for(int k = z; k < z + getDepth(); k++)
{
for (int i = x; i < x + getWidth(); i++) {
for (int j = y; j < y + getHeight(); j++) {
for (int k = z; k < z + getDepth(); k++) {
set(i - x, j - y, k - z, ejector.readMatter(w, i, j, k));
}
}
@@ -110,18 +95,15 @@ public interface MatterSlice<T> extends Hunk<T> {
// RawMatter<T> ex MappedHunk<T>
// IMatterSlice<T> ex Hunk<T>
default int getCount()
{
return ((MappedHunk<?>)this).getEntryCount();
default int getCount() {
return ((MappedHunk<?>) this).getEntryCount();
}
default boolean canWrite(Class<?> mediumType)
{
default boolean canWrite(Class<?> mediumType) {
return writeInto(mediumType) != null;
}
default boolean canRead(Class<?> mediumType)
{
default boolean canRead(Class<?> mediumType) {
return readFrom(mediumType) != null;
}
@@ -153,8 +135,7 @@ public interface MatterSlice<T> extends Hunk<T> {
}
}
default void rotateSliceInto(Matter n, double x, double y, double z)
{
rotate(x,y,z, (_x, _y, _z) -> n.slice(getType()));
default void rotateSliceInto(Matter n, double x, double y, double z) {
rotate(x, y, z, (_x, _y, _z) -> n.slice(getType()));
}
}

View File

@@ -18,15 +18,9 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.project.loader.IrisRegistrant;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.matter.Sliced;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BiomeMatter extends RegistryMatter<IrisBiome> {
public BiomeMatter() {

View File

@@ -22,9 +22,6 @@ import com.volmit.iris.engine.parallax.ParallaxAccess;
import com.volmit.iris.engine.parallax.ParallaxWorld;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.matter.Sliced;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
@@ -40,9 +37,9 @@ public class BlockMatter extends RawMatter<BlockData> {
public BlockMatter(int width, int height, int depth) {
super(width, height, depth, BlockData.class);
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x,y,z).setBlockData(d)));
registerWriter(ParallaxWorld.class, (w, d, x, y, z) -> w.setBlock(x,y,z,d));
registerReader(World.class, (w, x, y, z) -> w.getBlockAt(x,y,z).getBlockData());
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x, y, z).setBlockData(d)));
registerWriter(ParallaxWorld.class, (w, d, x, y, z) -> w.setBlock(x, y, z, d));
registerReader(World.class, (w, x, y, z) -> w.getBlockAt(x, y, z).getBlockData());
registerReader(ParallaxWorld.class, ParallaxAccess::getBlock);
}

View File

@@ -21,8 +21,8 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.hunk.storage.MappedHunk;
import com.volmit.iris.util.matter.MatterReader;
import com.volmit.iris.util.matter.MatterWriter;
import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.matter.MatterWriter;
import lombok.Getter;
import java.io.DataInputStream;
@@ -42,25 +42,21 @@ public abstract class RawMatter<T> extends MappedHunk<T> implements MatterSlice<
this.type = type;
}
protected <W> void registerWriter(Class<W> mediumType, MatterWriter<W, T> injector)
{
protected <W> void registerWriter(Class<W> mediumType, MatterWriter<W, T> injector) {
injectors.put(mediumType, injector);
}
protected <W> void registerReader(Class<W> mediumType, MatterReader<W, T> injector)
{
protected <W> void registerReader(Class<W> mediumType, MatterReader<W, T> injector) {
ejectors.put(mediumType, injector);
}
@Override
public <W> MatterWriter<W, T> writeInto(Class<W> mediumType)
{
public <W> MatterWriter<W, T> writeInto(Class<W> mediumType) {
return (MatterWriter<W, T>) injectors.get(mediumType);
}
@Override
public <W> MatterReader<W, T> readFrom(Class<W> mediumType)
{
public <W> MatterReader<W, T> readFrom(Class<W> mediumType) {
return (MatterReader<W, T>) ejectors.get(mediumType);
}

View File

@@ -19,7 +19,6 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.project.loader.IrisRegistrant;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.util.matter.Sliced;
@Sliced
@@ -27,6 +26,7 @@ public class RegionMatter extends RegistryMatter<IrisRegistrant> {
public RegionMatter() {
this(1, 1, 1);
}
public RegionMatter(int width, int height, int depth) {
super(width, height, depth, IrisRegistrant.class);
}

View File

@@ -20,8 +20,6 @@ package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.project.loader.IrisRegistrant;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.tag.Tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;

View File

@@ -18,7 +18,6 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.spawners.IrisSpawner;
import com.volmit.iris.util.matter.Sliced;
@@ -27,6 +26,7 @@ public class SpawnerMatter extends RegistryMatter<IrisSpawner> {
public SpawnerMatter() {
this(1, 1, 1);
}
public SpawnerMatter(int width, int height, int depth) {
super(width, height, depth, IrisSpawner.class);
}

View File

@@ -0,0 +1,54 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.engine.parallax.ParallaxAccess;
import com.volmit.iris.engine.parallax.ParallaxWorld;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.World;
import org.bukkit.block.Chest;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class TileMatter extends RawMatter<TileState> {
public TileMatter() {
this(1, 1, 1);
}
public TileMatter(int width, int height, int depth) {
super(width, height, depth, TileState.class);
}
@Override
public void writeNode(TileState b, DataOutputStream dos) throws IOException {
}
@Override
public TileState readNode(DataInputStream din) throws IOException {
return null;
}
}