diff --git a/build.gradle.kts b/build.gradle.kts index 4d25ed1a..d0d1a0b0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,8 +11,8 @@ plugins { group = "ru.dbotthepony" version = "0.1-SNAPSHOT" -val lwjglVersion = "3.3.0" -val lwjglNatives = "natives-windows" +val lwjglVersion: String by project +val lwjglNatives: String by project repositories { mavenCentral() @@ -37,6 +37,8 @@ tasks.compileKotlin { } dependencies { + val kommonsVersion: String by project + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.10") implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.10") @@ -50,7 +52,7 @@ dependencies { implementation("it.unimi.dsi:fastutil:8.5.6") - implementation("com.google.guava:guava:31.0.1-jre") + implementation("com.google.guava:guava:33.0.0-jre") implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion")) @@ -79,10 +81,16 @@ dependencies { runtimeOnly("org.lwjgl", "lwjgl-par", classifier = lwjglNatives) runtimeOnly("org.lwjgl", "lwjgl-stb", classifier = lwjglNatives) - implementation("net.java.dev.jna:jna:5.13.0") - implementation("com.github.jnr:jnr-ffi:2.2.13") + val ffiVersion: String by project - implementation("ru.dbotthepony:kvector:2.12.0") + implementation("net.java.dev.jna:jna:5.13.0") + implementation("com.github.jnr:jnr-ffi:$ffiVersion") + + implementation("ru.dbotthepony.kommons:kommons:[$kommonsVersion,)") + implementation("ru.dbotthepony.kommons:gson:[$kommonsVersion,)") + implementation("ru.dbotthepony.kommons:guava:[$kommonsVersion,)") + implementation("ru.dbotthepony.kommons:linear-algebra:[$kommonsVersion,)") + implementation("ru.dbotthepony.kommons:gson-linear-algebra:[$kommonsVersion,)") implementation("com.github.ben-manes.caffeine:caffeine:3.1.5") implementation("org.classdump.luna:luna-all-shaded:0.4.1") @@ -103,16 +111,3 @@ jmh { tasks.getByName("test") { useJUnitPlatform() } - -tasks { - create("buildlua", type = Exec::class.java) { - commandLine( - "clang", "lua_glue.c", - "-I", "${Jvm.current().javaHome}/include", - "-I", "${Jvm.current().javaHome}/include/win32", - "-I", "${Jvm.current().javaHome}/include/win32/bridge", - "-o", "lua_glue.dll", "-shared", "lua54.lib" - ) - } -} - diff --git a/gradle.properties b/gradle.properties index 75ea1583..c44946ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,9 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m + +kotlinVersion=1.9.0 +kommonsVersion=1.7.1 + +ffiVersion=2.2.13 +lwjglVersion=3.3.0 +lwjglNatives=natives-windows diff --git a/src/main/java/ru/dbotthepony/kstarbound/client/freetype/struct/FT_Vector.java b/src/main/java/ru/dbotthepony/kstarbound/client/freetype/struct/FT_Vector.java index f1b70408..fd80a70f 100644 --- a/src/main/java/ru/dbotthepony/kstarbound/client/freetype/struct/FT_Vector.java +++ b/src/main/java/ru/dbotthepony/kstarbound/client/freetype/struct/FT_Vector.java @@ -1,7 +1,7 @@ package ru.dbotthepony.kstarbound.client.freetype.struct; import com.sun.jna.Structure; -import ru.dbotthepony.kvector.vector.Vector2i; +import ru.dbotthepony.kommons.vector.Vector2i; @Structure.FieldOrder({"x", "y"}) public class FT_Vector extends Structure { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Ext.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Ext.kt index 0b8b9520..051f0850 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Ext.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Ext.kt @@ -7,7 +7,7 @@ import com.google.gson.TypeAdapter import com.google.gson.TypeAdapterFactory import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonReader -import ru.dbotthepony.kstarbound.util.KOptional +import ru.dbotthepony.kommons.core.KOptional import java.util.Arrays import java.util.concurrent.Callable import java.util.concurrent.ForkJoinPool diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt index 57b7b308..65d44044 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Main.kt @@ -3,24 +3,15 @@ package ru.dbotthepony.kstarbound import org.apache.logging.log4j.LogManager import org.lwjgl.Version -import org.lwjgl.glfw.GLFW.glfwSetWindowShouldClose +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.client.StarboundClient -import ru.dbotthepony.kstarbound.client.network.ClientConnection import ru.dbotthepony.kstarbound.io.BTreeDB -import ru.dbotthepony.kstarbound.io.readVarInt -import ru.dbotthepony.kstarbound.json.VersionedJson import ru.dbotthepony.kstarbound.server.IntegratedStarboundServer import ru.dbotthepony.kstarbound.server.world.LegacyChunkSource import ru.dbotthepony.kstarbound.server.world.ServerWorld -import ru.dbotthepony.kstarbound.util.AssetPathStack -import ru.dbotthepony.kstarbound.world.Direction import ru.dbotthepony.kstarbound.world.WorldGeometry -import ru.dbotthepony.kstarbound.world.api.MutableCell import ru.dbotthepony.kstarbound.world.entities.ItemEntity -import ru.dbotthepony.kstarbound.world.entities.PlayerEntity -import ru.dbotthepony.kstarbound.world.entities.WorldObject -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2i import java.io.BufferedInputStream import java.io.ByteArrayInputStream import java.io.DataInputStream diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Registry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Registry.kt index 09b015f6..fd65c15d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Registry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Registry.kt @@ -20,8 +20,8 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap import it.unimi.dsi.fastutil.objects.Object2ObjectMaps import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.json.consumeNull -import ru.dbotthepony.kstarbound.util.Either import java.lang.reflect.ParameterizedType import java.util.concurrent.locks.ReentrantLock import java.util.function.Supplier diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index ddb2bd20..5146762f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -5,6 +5,18 @@ import com.google.gson.* import it.unimi.dsi.fastutil.objects.Object2ObjectFunction import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.gson.AABBTypeAdapter +import ru.dbotthepony.kommons.gson.AABBiTypeAdapter +import ru.dbotthepony.kommons.gson.ColorTypeAdapter +import ru.dbotthepony.kommons.gson.EitherTypeAdapter +import ru.dbotthepony.kommons.gson.KOptionalTypeAdapter +import ru.dbotthepony.kommons.gson.NothingAdapter +import ru.dbotthepony.kommons.gson.Vector2dTypeAdapter +import ru.dbotthepony.kommons.gson.Vector2fTypeAdapter +import ru.dbotthepony.kommons.gson.Vector2iTypeAdapter +import ru.dbotthepony.kommons.gson.Vector4dTypeAdapter +import ru.dbotthepony.kommons.gson.Vector4iTypeAdapter +import ru.dbotthepony.kommons.util.MailboxExecutorService import ru.dbotthepony.kstarbound.defs.* import ru.dbotthepony.kstarbound.defs.image.Image import ru.dbotthepony.kstarbound.defs.image.SpriteReference @@ -15,20 +27,10 @@ import ru.dbotthepony.kstarbound.defs.`object`.ObjectDefinition import ru.dbotthepony.kstarbound.defs.`object`.ObjectOrientation import ru.dbotthepony.kstarbound.defs.player.BlueprintLearnList import ru.dbotthepony.kstarbound.io.* -import ru.dbotthepony.kstarbound.json.ColorTypeAdapter -import ru.dbotthepony.kstarbound.json.EitherTypeAdapter import ru.dbotthepony.kstarbound.json.FastutilTypeAdapterFactory import ru.dbotthepony.kstarbound.json.InternedJsonElementAdapter import ru.dbotthepony.kstarbound.json.InternedStringAdapter -import ru.dbotthepony.kstarbound.json.KOptionalTypeAdapter import ru.dbotthepony.kstarbound.json.LongRangeAdapter -import ru.dbotthepony.kstarbound.json.NothingAdapter -import ru.dbotthepony.kstarbound.json.OneOfTypeAdapter -import ru.dbotthepony.kstarbound.json.Vector2dTypeAdapter -import ru.dbotthepony.kstarbound.json.Vector2fTypeAdapter -import ru.dbotthepony.kstarbound.json.Vector2iTypeAdapter -import ru.dbotthepony.kstarbound.json.Vector4dTypeAdapter -import ru.dbotthepony.kstarbound.json.Vector4iTypeAdapter import ru.dbotthepony.kstarbound.json.builder.EnumAdapter import ru.dbotthepony.kstarbound.json.builder.BuilderAdapter import ru.dbotthepony.kstarbound.json.builder.FactoryAdapter @@ -40,7 +42,6 @@ import ru.dbotthepony.kstarbound.math.* import ru.dbotthepony.kstarbound.util.ItemStack import ru.dbotthepony.kstarbound.util.SBPattern import ru.dbotthepony.kstarbound.util.HashTableInterner -import ru.dbotthepony.kstarbound.util.MailboxExecutorService import ru.dbotthepony.kstarbound.util.traverseJsonPath import ru.dbotthepony.kstarbound.world.physics.Poly import java.io.* @@ -141,8 +142,6 @@ object Starbound : ISBFileLocator { // Either<> registerTypeAdapterFactory(EitherTypeAdapter) - // OneOf<> - registerTypeAdapterFactory(OneOfTypeAdapter) // KOptional<> registerTypeAdapterFactory(KOptionalTypeAdapter) @@ -163,8 +162,8 @@ object Starbound : ISBFileLocator { registerTypeAdapter(StatModifier::Adapter) // математические классы - registerTypeAdapter(ru.dbotthepony.kstarbound.json.AABBTypeAdapter) - registerTypeAdapter(ru.dbotthepony.kstarbound.json.AABBiTypeAdapter) + registerTypeAdapter(AABBTypeAdapter) + registerTypeAdapter(AABBiTypeAdapter) registerTypeAdapter(Vector2dTypeAdapter) registerTypeAdapter(Vector2fTypeAdapter) registerTypeAdapter(Vector2iTypeAdapter) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt index 3dea8e15..f35e4d02 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/StarboundClient.kt @@ -18,7 +18,15 @@ import org.lwjgl.stb.STBImage import org.lwjgl.system.MemoryStack import org.lwjgl.system.MemoryUtil import org.lwjgl.system.MemoryUtil.memAddressSafe -import ru.dbotthepony.kstarbound.util.MailboxExecutorService +import ru.dbotthepony.kommons.core.IStruct4f +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.matrix.Matrix3f +import ru.dbotthepony.kommons.matrix.Matrix3fStack +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.util.MailboxExecutorService +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2f +import ru.dbotthepony.kommons.vector.Vector4f import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNIT import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITf import ru.dbotthepony.kstarbound.Starbound @@ -61,14 +69,6 @@ import ru.dbotthepony.kstarbound.world.Direction import ru.dbotthepony.kstarbound.world.LightCalculator import ru.dbotthepony.kstarbound.world.api.ICellAccess import ru.dbotthepony.kstarbound.world.api.AbstractCell -import ru.dbotthepony.kvector.api.IStruct4f -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.arrays.Matrix3fStack -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2f -import ru.dbotthepony.kvector.vector.Vector4f import java.io.Closeable import java.io.File import java.lang.ref.PhantomReference diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLTexture.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLTexture.kt index 974d4067..9dcaaa2f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLTexture.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/GLTexture.kt @@ -1,14 +1,9 @@ package ru.dbotthepony.kstarbound.client.gl import org.apache.logging.log4j.LogManager -import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL45.* -import org.lwjgl.stb.STBImage +import ru.dbotthepony.kommons.core.IStruct2i import ru.dbotthepony.kstarbound.client.StarboundClient -import ru.dbotthepony.kstarbound.defs.image.Image -import ru.dbotthepony.kvector.vector.Vector2i -import java.io.File -import java.io.FileNotFoundException import java.nio.ByteBuffer import kotlin.reflect.KProperty @@ -96,7 +91,7 @@ class GLTexture2D(val width: Int, val height: Int, val format: Int, val levels: return UVCoord(x.toFloat() / width, y.toFloat() / height) } - fun pixelToUV(pos: Vector2i) = pixelToUV(pos.x, pos.y) + fun pixelToUV(pos: IStruct2i) = pixelToUV(pos.component1(), pos.component2()) fun upload(level: Int, bufferFormat: Int, dataFormat: Int, data: ByteBuffer): GLTexture2D { return upload(level, 0, 0, width, height, bufferFormat, dataFormat, data) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/ScissorRect.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/ScissorRect.kt index 9a34e2d8..f42d490f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/ScissorRect.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/ScissorRect.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.client.gl -import ru.dbotthepony.kvector.util2d.intersectRectangles +import ru.dbotthepony.kommons.math.intersectRectangles data class ScissorRect(val x: Int, val y: Int, val width: Int, val height: Int) { fun withinBounds(x: Int, y: Int): Boolean { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt index 003f6620..636923b9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/GLShaderProgram.kt @@ -5,18 +5,18 @@ import it.unimi.dsi.fastutil.objects.Object2BooleanFunction import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap import it.unimi.dsi.fastutil.objects.Object2ObjectFunction import org.lwjgl.opengl.GL45.* +import ru.dbotthepony.kommons.core.IStruct2f +import ru.dbotthepony.kommons.core.IStruct3f +import ru.dbotthepony.kommons.core.IStruct4f +import ru.dbotthepony.kommons.matrix.Matrix3f +import ru.dbotthepony.kommons.matrix.Matrix4f +import ru.dbotthepony.kommons.vector.Vector2f +import ru.dbotthepony.kommons.vector.Vector3f +import ru.dbotthepony.kommons.vector.Vector4f import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.gl.GLObject import ru.dbotthepony.kstarbound.client.gl.checkForGLError import ru.dbotthepony.kstarbound.client.gl.vertex.VertexAttributes -import ru.dbotthepony.kvector.api.IStruct2f -import ru.dbotthepony.kvector.api.IStruct3f -import ru.dbotthepony.kvector.api.IStruct4f -import ru.dbotthepony.kvector.arrays.Matrix4f -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.vector.Vector2f -import ru.dbotthepony.kvector.vector.Vector3f -import ru.dbotthepony.kvector.vector.Vector4f import java.nio.ByteBuffer import java.nio.ByteOrder import java.nio.FloatBuffer diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Programs.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Programs.kt index 548df0d4..732da4f0 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Programs.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/Programs.kt @@ -1,16 +1,13 @@ package ru.dbotthepony.kstarbound.client.gl.shader -import com.google.common.collect.ImmutableList -import org.lwjgl.opengl.GL20.GL_FRAGMENT_SHADER -import org.lwjgl.opengl.GL20.GL_VERTEX_SHADER +import ru.dbotthepony.kommons.core.IStruct4f +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.matrix.Matrix3f import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.gl.vertex.GeometryType import ru.dbotthepony.kstarbound.client.gl.vertex.StreamVertexBuilder import ru.dbotthepony.kstarbound.client.gl.vertex.VertexAttributes import ru.dbotthepony.kstarbound.client.render.FONT_VERTEX_FORMAT -import ru.dbotthepony.kvector.api.IStruct4f -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.vector.RGBAColor private fun shaders(name: String): List { val client = StarboundClient.current() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/UberShader.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/UberShader.kt index 0361f7c3..7ab93945 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/UberShader.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/shader/UberShader.kt @@ -8,15 +8,15 @@ import it.unimi.dsi.fastutil.objects.ObjectArraySet import it.unimi.dsi.fastutil.objects.Reference2ObjectFunction import org.lwjgl.opengl.GL20.GL_FRAGMENT_SHADER import org.lwjgl.opengl.GL20.GL_VERTEX_SHADER +import ru.dbotthepony.kommons.core.IStruct4f +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.matrix.Matrix3f import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.gl.GLTexture2D import ru.dbotthepony.kstarbound.client.gl.vertex.StreamVertexBuilder import ru.dbotthepony.kstarbound.client.gl.vertex.VertexAttributeType import ru.dbotthepony.kstarbound.client.gl.vertex.VertexAttributes import ru.dbotthepony.kstarbound.client.render.RenderConfig -import ru.dbotthepony.kvector.api.IStruct4f -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.vector.RGBAColor import java.time.Duration import java.util.Collections import java.util.EnumSet diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/VertexBuilder.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/VertexBuilder.kt index fde89cae..02e6aef8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/VertexBuilder.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/gl/vertex/VertexBuilder.kt @@ -4,11 +4,11 @@ import org.lwjgl.opengl.GL45 import org.lwjgl.opengl.GL45.GL_UNSIGNED_INT import org.lwjgl.opengl.GL45.GL_UNSIGNED_SHORT import org.lwjgl.opengl.GL45.GL_UNSIGNED_BYTE +import ru.dbotthepony.kommons.core.IStruct2d +import ru.dbotthepony.kommons.core.IStruct2f +import ru.dbotthepony.kommons.core.IStruct4f +import ru.dbotthepony.kommons.matrix.Matrix3f import ru.dbotthepony.kstarbound.client.gl.BufferObject -import ru.dbotthepony.kvector.api.IStruct2d -import ru.dbotthepony.kvector.api.IStruct2f -import ru.dbotthepony.kvector.api.IStruct4f -import ru.dbotthepony.kvector.arrays.Matrix3f import java.nio.ByteBuffer import java.nio.ByteOrder diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/InitialChunkDataPacket.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/InitialChunkDataPacket.kt index 0f02ff77..40081361 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/InitialChunkDataPacket.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/InitialChunkDataPacket.kt @@ -1,10 +1,10 @@ package ru.dbotthepony.kstarbound.client.network.packets +import ru.dbotthepony.kommons.io.readCollection +import ru.dbotthepony.kommons.io.writeCollection import ru.dbotthepony.kstarbound.client.network.ClientConnection import ru.dbotthepony.kstarbound.network.IClientPacket import ru.dbotthepony.kstarbound.io.readChunkPos -import ru.dbotthepony.kstarbound.io.readCollection -import ru.dbotthepony.kstarbound.io.writeCollection import ru.dbotthepony.kstarbound.io.writeVec2i import ru.dbotthepony.kstarbound.world.CHUNK_SIZE import ru.dbotthepony.kstarbound.world.Chunk diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/JoinWorldPacket.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/JoinWorldPacket.kt index 6eece38f..4e80b9d3 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/JoinWorldPacket.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/network/packets/JoinWorldPacket.kt @@ -1,19 +1,15 @@ package ru.dbotthepony.kstarbound.client.network.packets -import io.netty.buffer.ByteBuf import ru.dbotthepony.kstarbound.client.network.ClientConnection import ru.dbotthepony.kstarbound.client.world.ClientWorld -import ru.dbotthepony.kstarbound.network.IClientPacket import ru.dbotthepony.kstarbound.io.readUUID -import ru.dbotthepony.kstarbound.io.readVec2i import ru.dbotthepony.kstarbound.io.writeUUID -import ru.dbotthepony.kstarbound.io.writeVec2i +import ru.dbotthepony.kstarbound.network.IClientPacket import ru.dbotthepony.kstarbound.world.World import ru.dbotthepony.kstarbound.world.WorldGeometry -import ru.dbotthepony.kvector.vector.Vector2i import java.io.DataInputStream import java.io.DataOutputStream -import java.util.UUID +import java.util.* data class JoinWorldPacket(val uuid: UUID, val seed: Long, val geometry: WorldGeometry) : IClientPacket { constructor(buff: DataInputStream) : this(buff.readUUID(), buff.readLong(), WorldGeometry(buff)) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Camera.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Camera.kt index 8b266ca2..77afb81b 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Camera.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Camera.kt @@ -1,9 +1,8 @@ package ru.dbotthepony.kstarbound.client.render import org.lwjgl.glfw.GLFW.* +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.client.StarboundClient -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2f class Camera(val client: StarboundClient) { /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt index cd0e4ac6..219573f3 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Font.kt @@ -7,6 +7,11 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import org.lwjgl.opengl.GL45.* import org.lwjgl.system.MemoryUtil +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.matrix.Matrix3f +import ru.dbotthepony.kommons.util.AABBi +import ru.dbotthepony.kommons.vector.Vector2i +import ru.dbotthepony.kommons.vector.Vector4f import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.freetype.LoadFlag import ru.dbotthepony.kstarbound.client.gl.* @@ -18,13 +23,6 @@ import ru.dbotthepony.kstarbound.client.gl.vertex.VertexBuilder import ru.dbotthepony.kstarbound.defs.image.IUVCoordinates import ru.dbotthepony.kstarbound.math.roundTowardsNegativeInfinity import ru.dbotthepony.kstarbound.math.roundTowardsPositiveInfinity -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.util2d.AABBi -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2i -import ru.dbotthepony.kvector.vector.Vector4f private fun breakLines(text: String): List { var nextLineBreak = text.indexOf('\n', 0) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Mesh.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Mesh.kt index 19e5d32c..cb03c057 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Mesh.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/Mesh.kt @@ -5,7 +5,6 @@ import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.gl.checkForGLError import ru.dbotthepony.kstarbound.client.gl.shader.GLShaderProgram import ru.dbotthepony.kstarbound.client.gl.vertex.VertexBuilder -import ru.dbotthepony.kvector.arrays.Matrix4f /** * mesh is container for paired VAO, VBO and EBO, and metadata for them diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/RenderConfig.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/RenderConfig.kt index 8c7ace3d..cb3986f3 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/RenderConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/RenderConfig.kt @@ -1,7 +1,6 @@ package ru.dbotthepony.kstarbound.client.render import ru.dbotthepony.kstarbound.client.gl.shader.GLShaderProgram -import ru.dbotthepony.kvector.arrays.Matrix4f abstract class RenderConfig(val program: T) { val client get() = program.client diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt index 124b9977..c984068b 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/render/TileRenderer.kt @@ -5,6 +5,8 @@ import com.github.benmanes.caffeine.cache.Caffeine import com.github.benmanes.caffeine.cache.Scheduler import org.apache.logging.log4j.LogManager import org.lwjgl.opengl.GL45.* +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITf import ru.dbotthepony.kstarbound.Registries import ru.dbotthepony.kstarbound.client.StarboundClient @@ -15,8 +17,6 @@ import ru.dbotthepony.kstarbound.defs.tile.* import ru.dbotthepony.kstarbound.world.api.ITileAccess import ru.dbotthepony.kstarbound.world.api.AbstractTileState import ru.dbotthepony.kstarbound.world.api.TileColor -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2i import java.time.Duration import java.util.concurrent.Callable diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/world/ClientWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/world/ClientWorld.kt index 760b0095..d133a5c6 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/world/ClientWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/world/ClientWorld.kt @@ -5,6 +5,11 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectFunction import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap import it.unimi.dsi.fastutil.longs.LongArraySet import it.unimi.dsi.fastutil.objects.ReferenceArraySet +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.vector.Vector2f +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITf import ru.dbotthepony.kstarbound.client.StarboundClient @@ -23,11 +28,6 @@ import ru.dbotthepony.kstarbound.world.api.ITileAccess import ru.dbotthepony.kstarbound.world.api.OffsetCellAccess import ru.dbotthepony.kstarbound.world.api.TileView import ru.dbotthepony.kstarbound.world.positiveModulo -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2f -import ru.dbotthepony.kvector.vector.Vector2i import java.util.concurrent.CompletableFuture import java.util.concurrent.Future import java.util.concurrent.TimeUnit diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/Drawable.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/Drawable.kt index b2c52827..3db66bd3 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/Drawable.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/Drawable.kt @@ -8,6 +8,11 @@ import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.core.Either +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.matrix.Matrix3f +import ru.dbotthepony.kommons.vector.Vector2f +import ru.dbotthepony.kommons.vector.Vector3f import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITf import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.gl.vertex.GeometryType @@ -16,12 +21,7 @@ import ru.dbotthepony.kstarbound.defs.image.SpriteReference import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.consumeNull import ru.dbotthepony.kstarbound.math.LineF -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.json.contains -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2f -import ru.dbotthepony.kvector.vector.Vector3f sealed class Drawable(val position: Vector2f, val color: RGBAColor, val fullbright: Boolean) { @JsonFactory diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonDriven.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonDriven.kt index 3bf72e82..eec8d3b3 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonDriven.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonDriven.kt @@ -5,9 +5,9 @@ import com.google.gson.JsonObject import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.util.AssetPathStack -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.json.set import java.util.function.Consumer import java.util.function.Function diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonFunction.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonFunction.kt index ea053dd0..73730d5d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonFunction.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JsonFunction.kt @@ -10,10 +10,10 @@ import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.gson.Vector2dTypeAdapter +import ru.dbotthepony.kommons.math.linearInterpolation +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.json.builder.EnumAdapter -import ru.dbotthepony.kstarbound.json.Vector2dTypeAdapter -import ru.dbotthepony.kvector.util.linearInterpolation -import ru.dbotthepony.kvector.vector.Vector2d enum class JsonFunctionInterpolation { LINEAR { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JumpProfile.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JumpProfile.kt index ef6cde41..ae50242a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JumpProfile.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/JumpProfile.kt @@ -1,7 +1,6 @@ package ru.dbotthepony.kstarbound.defs import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kstarbound.util.KOptional @JsonFactory data class JumpProfile( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt index ac49e454..bd8c634b 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/MovementParameters.kt @@ -2,10 +2,9 @@ package ru.dbotthepony.kstarbound.defs import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.json.builder.JsonAlias import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kstarbound.json.builder.JsonImplementation -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.world.physics.Poly sealed class BaseMovementParameters { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TouchDamage.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TouchDamage.kt index 9e5a7549..59db0908 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TouchDamage.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/TouchDamage.kt @@ -2,8 +2,8 @@ package ru.dbotthepony.kstarbound.defs import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class TouchDamage( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/AnimationDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/AnimationDefinition.kt index 64003000..21ca71d7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/AnimationDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/animation/AnimationDefinition.kt @@ -2,11 +2,11 @@ package ru.dbotthepony.kstarbound.defs.animation import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap +import ru.dbotthepony.kommons.core.Either +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.defs.image.SpriteReference import ru.dbotthepony.kstarbound.defs.particle.ParticleEmitter import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kstarbound.util.Either -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class AnimationDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/IUVCoordinates.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/IUVCoordinates.kt index ede7e374..7dcace97 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/IUVCoordinates.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/IUVCoordinates.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.defs.image -import ru.dbotthepony.kvector.api.IStruct4f +import ru.dbotthepony.kommons.core.IStruct4f interface IUVCoordinates : IStruct4f { val u0: Float diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/Image.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/Image.kt index 4d50d168..9ba2f256 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/Image.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/image/Image.kt @@ -23,6 +23,8 @@ import org.lwjgl.stb.STBIReadCallbackI import org.lwjgl.stb.STBISkipCallback import org.lwjgl.stb.STBImage import org.lwjgl.system.MemoryUtil +import ru.dbotthepony.kommons.vector.Vector2i +import ru.dbotthepony.kommons.vector.Vector4i import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNIT import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITi import ru.dbotthepony.kstarbound.Starbound @@ -33,8 +35,6 @@ import ru.dbotthepony.kstarbound.json.consumeNull import ru.dbotthepony.kstarbound.json.contains import ru.dbotthepony.kstarbound.json.get import ru.dbotthepony.kstarbound.json.getObject -import ru.dbotthepony.kvector.vector.Vector2i -import ru.dbotthepony.kvector.vector.Vector4i import java.io.BufferedInputStream import java.io.FileNotFoundException import java.lang.ref.WeakReference diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt index f6908a9d..cec98b3e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/ItemDescriptor.kt @@ -10,10 +10,10 @@ import org.classdump.luna.ByteString import org.classdump.luna.LuaRuntimeException import org.classdump.luna.Table import org.classdump.luna.TableFactory +import ru.dbotthepony.kommons.core.KOptional import ru.dbotthepony.kstarbound.lua.StateMachine import ru.dbotthepony.kstarbound.lua.from import ru.dbotthepony.kstarbound.lua.toJsonObject -import ru.dbotthepony.kstarbound.util.KOptional import ru.dbotthepony.kstarbound.json.get import java.util.function.Supplier diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt index 4bdccc15..97df7917 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/TreasurePoolDefinition.kt @@ -12,11 +12,11 @@ import com.google.gson.internal.bind.JsonTreeReader import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.defs.ItemReference import ru.dbotthepony.kstarbound.json.consumeNull import ru.dbotthepony.kstarbound.json.stream -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.util.ItemStack import ru.dbotthepony.kstarbound.util.WriteOnce import java.util.Random diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IFlashlightDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IFlashlightDefinition.kt index 60eecc54..8b837872 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IFlashlightDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IFlashlightDefinition.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.kstarbound.defs.item.api -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d interface IFlashlightDefinition : IItemDefinition, IItemInHandDefinition { /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IItemInHandDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IItemInHandDefinition.kt index 8760f75c..d2ea4d37 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IItemInHandDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IItemInHandDefinition.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.defs.item.api -import ru.dbotthepony.kvector.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2d interface IItemInHandDefinition : IItemDefinition { /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/ILiquidItem.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/ILiquidItem.kt index f6757add..79bbaec7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/ILiquidItem.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/ILiquidItem.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.defs.item.api -import ru.dbotthepony.kstarbound.util.Either +import ru.dbotthepony.kommons.core.Either interface ILiquidItem : IItemDefinition { /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IMaterialItem.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IMaterialItem.kt index d78570eb..3382d0bc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IMaterialItem.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/api/IMaterialItem.kt @@ -1,7 +1,6 @@ package ru.dbotthepony.kstarbound.defs.item.api -import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition -import ru.dbotthepony.kstarbound.util.Either +import ru.dbotthepony.kommons.core.Either interface IMaterialItem : IItemDefinition { /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/FlashlightDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/FlashlightDefinition.kt index 0c175d34..f0e4adef 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/FlashlightDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/FlashlightDefinition.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.defs.item.impl +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.defs.item.api.IFlashlightDefinition import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory(logMisses = false) class FlashlightDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/HarvestingToolPrototype.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/HarvestingToolPrototype.kt index cb6554ca..91fe2f1f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/HarvestingToolPrototype.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/HarvestingToolPrototype.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.defs.item.impl import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.defs.item.api.IHarvestingToolDefinition import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory(logMisses = false) class HarvestingToolPrototype( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/LiquidItemDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/LiquidItemDefinition.kt index 079a54f0..6500a12b 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/LiquidItemDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/LiquidItemDefinition.kt @@ -1,12 +1,11 @@ package ru.dbotthepony.kstarbound.defs.item.impl +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition import ru.dbotthepony.kstarbound.defs.item.api.ILiquidItem import ru.dbotthepony.kstarbound.json.builder.JsonAlias -import ru.dbotthepony.kstarbound.json.builder.JsonBuilder import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat -import ru.dbotthepony.kstarbound.util.Either @JsonFactory data class LiquidItemDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/MaterialItemDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/MaterialItemDefinition.kt index a74e2fd2..2fe9b865 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/MaterialItemDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/item/impl/MaterialItemDefinition.kt @@ -1,13 +1,11 @@ package ru.dbotthepony.kstarbound.defs.item.impl +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition -import ru.dbotthepony.kstarbound.defs.item.api.ILiquidItem import ru.dbotthepony.kstarbound.defs.item.api.IMaterialItem import ru.dbotthepony.kstarbound.json.builder.JsonAlias -import ru.dbotthepony.kstarbound.json.builder.JsonBuilder import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat -import ru.dbotthepony.kstarbound.util.Either @JsonFactory data class MaterialItemDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt index aef681c5..b9664668 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/monster/MonsterTypeDefinition.kt @@ -3,6 +3,7 @@ package ru.dbotthepony.kstarbound.defs.monster import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap import com.google.common.collect.ImmutableSet +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.defs.ActorMovementParameters import ru.dbotthepony.kstarbound.defs.AssetReference @@ -12,7 +13,6 @@ import ru.dbotthepony.kstarbound.defs.animation.AnimationDefinition import ru.dbotthepony.kstarbound.defs.item.TreasurePoolDefinition import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat -import ru.dbotthepony.kstarbound.util.Either @JsonFactory data class MonsterTypeDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt index 27c50618..bda21028 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/Anchor.kt @@ -1,5 +1,5 @@ package ru.dbotthepony.kstarbound.defs.`object` -import ru.dbotthepony.kvector.vector.Vector2i +import ru.dbotthepony.kommons.vector.Vector2i data class Anchor(val isForeground: Boolean, val pos: Vector2i, val isTilled: Boolean, val isSoil: Boolean, val anchorMaterial: String?) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectDefinition.kt index 9f326c71..30599b5f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectDefinition.kt @@ -11,6 +11,8 @@ import com.google.gson.JsonSyntaxException import com.google.gson.TypeAdapter import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.core.Either +import ru.dbotthepony.kommons.math.RGBAColor import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.defs.AssetPath import ru.dbotthepony.kstarbound.defs.ItemReference @@ -23,12 +25,10 @@ import ru.dbotthepony.kstarbound.json.consumeNull import ru.dbotthepony.kstarbound.json.listAdapter import ru.dbotthepony.kstarbound.json.stream import ru.dbotthepony.kstarbound.math.PeriodicFunction -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.json.contains import ru.dbotthepony.kstarbound.json.get import ru.dbotthepony.kstarbound.json.getArray import ru.dbotthepony.kstarbound.json.set -import ru.dbotthepony.kvector.vector.RGBAColor data class ObjectDefinition( val objectName: String, diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt index 40150278..ae811d33 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/object/ObjectOrientation.kt @@ -10,6 +10,11 @@ import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.util.AABBi +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2f +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.world.PIXELS_IN_STARBOUND_UNITf import ru.dbotthepony.kstarbound.client.render.RenderLayer import ru.dbotthepony.kstarbound.defs.Drawable @@ -23,11 +28,6 @@ import ru.dbotthepony.kstarbound.json.contains import ru.dbotthepony.kstarbound.json.get import ru.dbotthepony.kstarbound.json.set import ru.dbotthepony.kstarbound.world.Side -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.util2d.AABBi -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2f -import ru.dbotthepony.kvector.vector.Vector2i import kotlin.math.PI data class ObjectOrientation( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt index d6614dce..df1abea8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleConfig.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.defs.particle import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.defs.animation.DestructionAction import ru.dbotthepony.kstarbound.json.builder.JsonImplementation import ru.dbotthepony.kstarbound.util.VirtualProperty import ru.dbotthepony.kstarbound.util.SBPattern -import ru.dbotthepony.kvector.vector.Vector2d @JsonImplementation(ParticleConfig::class) interface IParticleConfig : IParticleVariance { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt index ea69aa6d..e4234687 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/IParticleVariance.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.defs.particle import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector4d import ru.dbotthepony.kstarbound.json.builder.JsonImplementation import ru.dbotthepony.kstarbound.util.VirtualProperty -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector4d @JsonImplementation(ParticleVariance::class) interface IParticleVariance { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleConfig.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleConfig.kt index c46aa72b..20656a45 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleConfig.kt @@ -1,14 +1,14 @@ package ru.dbotthepony.kstarbound.defs.particle +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector4d import ru.dbotthepony.kstarbound.defs.AssetReference import ru.dbotthepony.kstarbound.defs.animation.AnimationDefinition import ru.dbotthepony.kstarbound.defs.animation.DestructionAction import ru.dbotthepony.kstarbound.defs.image.SpriteReference import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.util.SBPattern -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector4d @JsonFactory data class ParticleConfig( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleCreator.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleCreator.kt index c1db3671..0ca40046 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleCreator.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleCreator.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.defs.particle +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kstarbound.util.Either @JsonFactory data class ParticleCreator( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleEmitter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleEmitter.kt index 91314bf7..aae6d37d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleEmitter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleEmitter.kt @@ -1,12 +1,12 @@ package ru.dbotthepony.kstarbound.defs.particle import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector4d import ru.dbotthepony.kstarbound.defs.animation.DestructionAction import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.util.SBPattern -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector4d @JsonFactory data class ParticleEmitter( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleVariance.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleVariance.kt index 8a0f3671..bbd8cbee 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleVariance.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/particle/ParticleVariance.kt @@ -1,9 +1,9 @@ package ru.dbotthepony.kstarbound.defs.particle +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector4d import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector4d @JsonFactory data class ParticleVariance( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/MatterManipulatorConfig.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/MatterManipulatorConfig.kt index c67c4ef1..fb74bc81 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/MatterManipulatorConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/MatterManipulatorConfig.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.defs.player import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class MatterManipulatorConfig( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerDefinition.kt index 35401737..3a0a5fb8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/PlayerDefinition.kt @@ -4,6 +4,9 @@ import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap import com.google.common.collect.ImmutableSet import com.google.gson.JsonObject +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.defs.ActorMovementParameters import ru.dbotthepony.kstarbound.defs.AssetReference @@ -12,9 +15,6 @@ import ru.dbotthepony.kstarbound.util.SBPattern import ru.dbotthepony.kstarbound.defs.animation.AnimationDefinition import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class PlayerDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/SplashConfig.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/SplashConfig.kt index 20458e41..9d10e498 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/SplashConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/SplashConfig.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.defs.player +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class SplashConfig( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/StatusControllerSettings.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/StatusControllerSettings.kt index 0dd7d39d..6d5a4332 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/StatusControllerSettings.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/player/StatusControllerSettings.kt @@ -2,8 +2,8 @@ package ru.dbotthepony.kstarbound.defs.player import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.vector.Vector2d @JsonFactory data class StatusControllerSettings( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt index 60645c5e..f9cf6fe1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt @@ -1,10 +1,10 @@ package ru.dbotthepony.kstarbound.defs.tile import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.math.RGBAColor import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.defs.StatusEffectDefinition import ru.dbotthepony.kstarbound.json.builder.JsonFactory -import ru.dbotthepony.kvector.vector.RGBAColor @JsonFactory data class LiquidDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/RenderTemplate.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/RenderTemplate.kt index 264785a7..056a84d0 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/RenderTemplate.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/RenderTemplate.kt @@ -4,12 +4,12 @@ import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableMap import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.defs.image.Image import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.util.WriteOnce import ru.dbotthepony.kstarbound.world.api.ITileAccess import ru.dbotthepony.kstarbound.world.api.AbstractTileState -import ru.dbotthepony.kvector.vector.Vector2i @JsonFactory data class RenderPiece( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt index 2334058d..021bf35e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt @@ -1,6 +1,7 @@ package ru.dbotthepony.kstarbound.defs.tile import com.google.common.collect.ImmutableList +import ru.dbotthepony.kommons.math.RGBAColor import ru.dbotthepony.kstarbound.defs.AssetReference import ru.dbotthepony.kstarbound.world.physics.CollisionType import ru.dbotthepony.kstarbound.defs.IThingWithDescription @@ -8,7 +9,6 @@ import ru.dbotthepony.kstarbound.defs.ThingDescription import ru.dbotthepony.kstarbound.json.builder.JsonFactory import ru.dbotthepony.kstarbound.json.builder.JsonFlat import ru.dbotthepony.kstarbound.json.builder.JsonIgnore -import ru.dbotthepony.kvector.vector.RGBAColor @JsonFactory data class TileDefinition( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/BTreeDB.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/BTreeDB.kt index 59eb924b..a7b2c469 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/BTreeDB.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/BTreeDB.kt @@ -1,6 +1,8 @@ package ru.dbotthepony.kstarbound.io import it.unimi.dsi.fastutil.ints.IntArraySet +import ru.dbotthepony.kommons.io.readVarInt +import ru.dbotthepony.kommons.io.readVarIntInfo import java.io.* import java.util.* import java.util.concurrent.locks.ReentrantLock diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt index 2bee5715..5c46fe44 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/StarboundPak.kt @@ -2,6 +2,9 @@ package ru.dbotthepony.kstarbound.io import it.unimi.dsi.fastutil.objects.Object2ObjectFunction import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap +import ru.dbotthepony.kommons.io.readBinaryString +import ru.dbotthepony.kommons.io.readVarInt +import ru.dbotthepony.kommons.io.readVarLong import ru.dbotthepony.kstarbound.IStarboundFile import ru.dbotthepony.kstarbound.getValue import ru.dbotthepony.kstarbound.json.readJsonObject @@ -212,8 +215,7 @@ class StarboundPak(val path: File, callback: (finished: Boolean, status: String) try { callback(false, "Reading index node $i") - val readLength = stream.readVarInt() - name = stream.readString(readLength) + name = stream.readBinaryString() require(name[0] == '/') { "index node at $i with '$name' appears to be not an absolute filename" } val offset = stream.readLong() val length = stream.readLong() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/Streams.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/Streams.kt index 9b6b5be3..c01d95f1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/Streams.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/Streams.kt @@ -1,158 +1,28 @@ package ru.dbotthepony.kstarbound.io import it.unimi.dsi.fastutil.bytes.ByteArrayList +import ru.dbotthepony.kommons.core.IStruct2d +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.io.readDouble +import ru.dbotthepony.kommons.io.readLong +import ru.dbotthepony.kommons.io.readSignedVarInt +import ru.dbotthepony.kommons.io.writeDouble +import ru.dbotthepony.kommons.io.writeLong +import ru.dbotthepony.kommons.io.writeSignedVarInt +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.world.ChunkPos -import ru.dbotthepony.kvector.api.IStruct2d -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2i import java.io.DataInput import java.io.DataOutput import java.io.IOException import java.io.InputStream import java.io.OutputStream import java.io.RandomAccessFile -import java.math.BigDecimal import java.util.* import java.util.function.IntConsumer import java.util.function.IntSupplier import kotlin.collections.ArrayList -data class VarIntReadResult(val value: Int, val cells: Int) -data class VarLongReadResult(val value: Long, val cells: Int) - -private fun readVarLongInfo(supplier: IntSupplier): VarLongReadResult { - var result = 0L - var read = supplier.asInt - var i = 1 - - while (true) { - result = (result shl 7) or (read.toLong() and 0x7F) - - if (read and 0x80 == 0) - break - - read = supplier.asInt - i++ - } - - return VarLongReadResult(result, i) -} - -private fun readVarIntInfo(supplier: IntSupplier): VarIntReadResult { - val read = readVarLongInfo(supplier) - return VarIntReadResult(read.value.toInt(), read.cells) -} - -private fun readVarInt(supplier: IntSupplier): Int { - return readVarIntInfo(supplier).value -} - -private fun readVarLong(supplier: IntSupplier): Long { - return readVarLongInfo(supplier).value -} - -private fun Int.fromSignedVar(): Int { - val sign = this and 1 - - if (sign == 0) - return this ushr 1 - else - return -(this ushr 1) - 1 -} - -private fun VarIntReadResult.fromSignedVar(): VarIntReadResult { - val sign = this.value and 1 - - if (sign == 0) - return VarIntReadResult(this.value ushr 1, this.cells) - else - return VarIntReadResult(-(this.value ushr 1) - 1, this.cells) -} - -private fun Long.fromSignedVar(): Long { - val sign = this and 1 - - if (sign == 0L) - return this ushr 1 - else - return -(this ushr 1) - 1L -} - -private fun VarLongReadResult.fromSignedVar(): VarLongReadResult { - val sign = this.value and 1 - - if (sign == 0L) - return VarLongReadResult(this.value ushr 1, this.cells) - else - return VarLongReadResult(-(this.value ushr 1) - 1, this.cells) -} - -fun RandomAccessFile.readVarLong() = readVarLong(::read) -fun RandomAccessFile.readVarInt() = readVarInt(::read) -fun RandomAccessFile.readVarLongInfo() = readVarLongInfo(::read) -fun RandomAccessFile.readVarIntInfo() = readVarIntInfo(::read) -fun InputStream.readVarLong() = readVarLong(::read) -fun InputStream.readVarInt() = readVarInt(::read) -fun InputStream.readVarLongInfo() = readVarLongInfo(::read) -fun InputStream.readVarIntInfo() = readVarIntInfo(::read) - -fun RandomAccessFile.readSignedVarLong() = readVarLong(::read).fromSignedVar() -fun RandomAccessFile.readSignedVarInt() = readVarInt(::read).fromSignedVar() -fun RandomAccessFile.readSignedVarLongInfo() = readVarLongInfo(::read).fromSignedVar() -fun RandomAccessFile.readSignedVarIntInfo() = readVarIntInfo(::read).fromSignedVar() -fun InputStream.readSignedVarLong() = readVarLong(::read).fromSignedVar() -fun InputStream.readSignedVarInt() = readVarInt(::read).fromSignedVar() -fun InputStream.readSignedVarLongInfo() = readVarLongInfo(::read).fromSignedVar() -fun InputStream.readSignedVarIntInfo() = readVarIntInfo(::read).fromSignedVar() - -private fun writeVarLong(write: IntConsumer, value: Long): Int { - var value = value - var i = 0 - - do { - val toWrite = (value and 0x7F).toInt() - value = value ushr 7 - - if (value == 0L) - write.accept(toWrite) - else - write.accept(toWrite or 0x80) - - i++ - } while (value != 0L) - - return i -} - -private fun writeVarInt(write: IntConsumer, value: Int): Int { - return writeVarLong(write, value.toLong()) -} - -private fun Int.toSignedVar(): Int { - if (this >= 0) - return this shl 1 - else - return (this shl 1) or 1 -} - -private fun Long.toSignedVar(): Long { - if (this >= 0) - return this shl 1 - else - return ((-this - 1) shl 1) or 1L -} - -fun RandomAccessFile.writeVarLong(value: Long) = writeVarLong(::write, value) -fun RandomAccessFile.writeVarInt(value: Int) = writeVarInt(::write, value) -fun OutputStream.writeVarLong(value: Long) = writeVarLong(::write, value) -fun OutputStream.writeVarInt(value: Int) = writeVarInt(::write, value) - -fun RandomAccessFile.writeSignedVarLong(value: Long) = writeVarLong(::write, value.toSignedVar()) -fun RandomAccessFile.writeSignedVarInt(value: Int) = writeVarInt(::write, value.toSignedVar()) -fun OutputStream.writeSignedVarLong(value: Long) = writeVarLong(::write, value.toSignedVar()) -fun OutputStream.writeSignedVarInt(value: Int) = writeVarInt(::write, value.toSignedVar()) - fun RandomAccessFile.readString(length: Int): String { require(length >= 0) { "Invalid length $length" } @@ -244,92 +114,3 @@ fun InputStream.readVec2d(): Vector2d { fun InputStream.readChunkPos(): ChunkPos { return ChunkPos(readSignedVarInt(), readSignedVarInt()) } - -fun S.writeCollection(collection: Collection, writer: S.(V) -> Unit) { - writeVarInt(collection.size) - - for (value in collection) { - writer(this, value) - } -} - -fun > S.readCollection(reader: S.() -> V, factory: (Int) -> C): C { - val size = readVarInt() - val collection = factory.invoke(size) - - for (i in 0 until size) { - collection.add(reader(this)) - } - - return collection -} - -fun S.readCollection(reader: S.() -> V) = readCollection(reader, ::ArrayList) - -fun OutputStream.writeInt(value: Int) { - if (this is DataOutput) { - writeInt(value) - return - } - - write(value ushr 24) - write(value ushr 16) - write(value ushr 8) - write(value) -} - -fun InputStream.readInt(): Int { - if (this is DataInput) { - return readInt() - } - - return (read() shl 24) or (read() shl 16) or (read() shl 8) or read() -} - -fun OutputStream.writeLong(value: Long) { - if (this is DataOutput) { - writeLong(value) - return - } - - write((value ushr 48).toInt()) - write((value ushr 40).toInt()) - write((value ushr 32).toInt()) - write((value ushr 24).toInt()) - write((value ushr 16).toInt()) - write((value ushr 8).toInt()) - write(value.toInt()) -} - -fun InputStream.readLong(): Long { - if (this is DataInput) { - return readLong() - } - - return (read().toLong() shl 48) or - (read().toLong() shl 40) or - (read().toLong() shl 32) or - (read().toLong() shl 24) or - (read().toLong() shl 16) or - (read().toLong() shl 8) or - read().toLong() -} - -fun OutputStream.writeFloat(value: Float) = writeInt(value.toBits()) -fun InputStream.readFloat() = Float.fromBits(readInt()) -fun OutputStream.writeDouble(value: Double) = writeLong(value.toBits()) -fun InputStream.readDouble() = Double.fromBits(readLong()) - -fun InputStream.readBinaryString(): String { - val size = readVarInt() - require(size >= 0) { "Negative payload size: $size" } - val bytes = ByteArray(size) - read(bytes) - return bytes.decodeToString() -} - -fun OutputStream.writeBinaryString(input: String) { - val bytes = input.encodeToByteArray() - writeVarInt(bytes.size) - write(bytes) -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/AABBJson.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/AABBJson.kt deleted file mode 100644 index 839911fb..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/AABBJson.kt +++ /dev/null @@ -1,68 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.TypeAdapter -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.util2d.AABBi -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2i - -object AABBTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: AABB) { - `out`.beginArray() - `out`.value(value.mins.x) - `out`.value(value.mins.y) - `out`.value(value.maxs.x) - `out`.value(value.maxs.y) - `out`.endArray() - } - - override fun read(`in`: JsonReader): AABB { - `in`.beginArray() - val (x1, x2) = Vector2d(`in`.nextDouble(), `in`.nextDouble()) - val (y1, y2) = Vector2d(`in`.nextDouble(), `in`.nextDouble()) - `in`.endArray() - - val xMins = x1.coerceAtMost(x2) - val xMaxs = x1.coerceAtLeast(x2) - - val yMins = y1.coerceAtMost(y2) - val yMaxs = y1.coerceAtLeast(y2) - - return AABB( - Vector2d(xMins, yMins), - Vector2d(xMaxs, yMaxs), - ) - } -} - -object AABBiTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: AABBi) { - `out`.beginArray() - `out`.value(value.mins.x) - `out`.value(value.mins.y) - `out`.value(value.maxs.x) - `out`.value(value.maxs.y) - `out`.endArray() - } - - override fun read(`in`: JsonReader): AABBi { - `in`.beginArray() - val (x1, x2) = Vector2i(`in`.nextInt(), `in`.nextInt()) - val (y1, y2) = Vector2i(`in`.nextInt(), `in`.nextInt()) - `in`.endArray() - - val xMins = x1.coerceAtMost(x2) - val xMaxs = x1.coerceAtLeast(x2) - - val yMins = y1.coerceAtMost(y2) - val yMaxs = y1.coerceAtLeast(y2) - - return AABBi( - Vector2i(xMins, yMins), - Vector2i(xMaxs, yMaxs), - ) - } -} - diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonReader.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonReader.kt index 6ed4426e..a20e47dc 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonReader.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonReader.kt @@ -9,10 +9,10 @@ import com.google.gson.JsonPrimitive import com.google.gson.JsonSyntaxException import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonToken -import ru.dbotthepony.kstarbound.io.readBinaryString -import ru.dbotthepony.kstarbound.io.readSignedVarLong +import ru.dbotthepony.kommons.io.readBinaryString +import ru.dbotthepony.kommons.io.readSignedVarLong +import ru.dbotthepony.kommons.io.readVarInt import ru.dbotthepony.kstarbound.io.readString -import ru.dbotthepony.kstarbound.io.readVarInt import java.io.DataInputStream import java.io.EOFException import java.io.InputStream @@ -117,7 +117,7 @@ class BinaryJsonReader(private val stream: DataInputStream) : JsonReader(unreada if (last.readingName) { last.readingName = false - stack.addLast(NameReader(stream.readString(stream.readVarInt()))) + stack.addLast(NameReader(stream.readBinaryString())) } else { last.readingName = true last.readPairs++ diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt index 07b6bf0d..e4c70cfe 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/BinaryJsonWriter.kt @@ -5,9 +5,9 @@ import com.google.gson.JsonElement import com.google.gson.JsonNull import com.google.gson.JsonObject import com.google.gson.JsonPrimitive -import ru.dbotthepony.kstarbound.io.writeBinaryString -import ru.dbotthepony.kstarbound.io.writeSignedVarLong -import ru.dbotthepony.kstarbound.io.writeVarInt +import ru.dbotthepony.kommons.io.writeBinaryString +import ru.dbotthepony.kommons.io.writeSignedVarLong +import ru.dbotthepony.kommons.io.writeVarInt import java.io.DataOutputStream fun DataOutputStream.writeJsonElement(value: JsonElement) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/ColorJson.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/ColorJson.kt deleted file mode 100644 index ef4894e3..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/ColorJson.kt +++ /dev/null @@ -1,96 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.TypeAdapter -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonToken -import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kvector.vector.RGBAColor - -object ColorTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: RGBAColor) { - TODO("Not yet implemented") - } - - override fun read(`in`: JsonReader): RGBAColor { - when (val type = `in`.peek()) { - JsonToken.BEGIN_ARRAY -> { - `in`.beginArray() - val red = `in`.nextDouble() - val green = `in`.nextDouble() - val blue = `in`.nextDouble() - - if (red % 1.0 == 0.0 && green % 1.0 == 0.0 && blue % 1.0 == 0.0) { - val alpha = `in`.peek().let { if (it == JsonToken.END_ARRAY) 255.0 else `in`.nextDouble() } - `in`.endArray() - - return RGBAColor( - red.toFloat() / 255f, - green.toFloat() / 255f, - blue.toFloat() / 255f, - alpha.toFloat() / 255f, - ) - } else { - val alpha = `in`.peek().let { if (it == JsonToken.END_ARRAY) 1.0 else `in`.nextDouble() } - `in`.endArray() - - return RGBAColor( - red.toFloat(), - green.toFloat(), - blue.toFloat(), - alpha.toFloat(), - ) - } - } - - JsonToken.BEGIN_OBJECT -> { - `in`.beginObject() - - val keyed = mutableMapOf() - - while (`in`.peek() != JsonToken.END_OBJECT) { - keyed[`in`.nextName()] = `in`.nextDouble() - } - - if (keyed.isEmpty()) - throw IllegalArgumentException("Object is empty") - - var values = 0 - - val red = keyed["red"]?.also { values++ } ?: keyed["r"]?.also { values++ } ?: 255.0 - val green = keyed["green"]?.also { values++ } ?: keyed["g"]?.also { values++ } ?: 255.0 - val blue = keyed["blue"]?.also { values++ } ?: keyed["b"]?.also { values++ } ?: 255.0 - val alpha = keyed["alpha"]?.also { values++ } ?: keyed["a"]?.also { values++ } ?: 255.0 - `in`.endObject() - - if (values == 0) { - throw IllegalArgumentException("Object is not a RGBAColor") - } - - if (red % 1.0 == 0.0 && green % 1.0 == 0.0 && blue % 1.0 == 0.0 && alpha % 1.0 == 0.0) { - return RGBAColor( - red.toFloat() / 255f, - green.toFloat() / 255f, - blue.toFloat() / 255f, - alpha.toFloat() / 255f, - ) - } else { - return RGBAColor( - red.toFloat(), - green.toFloat(), - blue.toFloat(), - alpha.toFloat(), - ) - } - } - - JsonToken.NUMBER -> return RGBAColor.rgb(`in`.nextInt()) - JsonToken.STRING -> { - val name = `in`.nextString() - //return RGBAColor.PRE_DEFINED_MAP[name] ?: throw IllegalArgumentException("Unknown pre defined RGBAColor name $name") - TODO("Can't determine color from name yet") - } - - else -> throw IllegalArgumentException("Expected array, object or number; got $type") - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/EitherTypeAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/EitherTypeAdapter.kt deleted file mode 100644 index 03375d6d..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/EitherTypeAdapter.kt +++ /dev/null @@ -1,58 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.Gson -import com.google.gson.JsonElement -import com.google.gson.JsonSyntaxException -import com.google.gson.TypeAdapter -import com.google.gson.TypeAdapterFactory -import com.google.gson.internal.bind.JsonTreeReader -import com.google.gson.reflect.TypeToken -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonToken -import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kstarbound.util.Either -import java.lang.reflect.ParameterizedType - -object EitherTypeAdapter : TypeAdapterFactory { - override fun create(gson: Gson, type: TypeToken): TypeAdapter? { - if (type.rawType == Either::class.java) { - val params = type.type as? ParameterizedType ?: return null - val (left, right) = params.actualTypeArguments - - return object : TypeAdapter>() { - private val leftAdapter = gson.getAdapter(TypeToken.get(left)) as TypeAdapter - private val rightAdapter = gson.getAdapter(TypeToken.get(right)) as TypeAdapter - private val elemAdapter = gson.getAdapter(JsonElement::class.java) - - override fun write(out: JsonWriter, value: Either?) { - if (value == null) - out.nullValue() - else - value.map({ leftAdapter.write(out, it) }, { rightAdapter.write(out, it) }) - } - - override fun read(`in`: JsonReader): Either? { - if (`in`.peek() == JsonToken.NULL) - return null - - val elem = elemAdapter.read(`in`) - - return try { - Either.left(leftAdapter.read(JsonTreeReader(elem)) ?: throw NullPointerException("left was empty")) - } catch(leftError: Throwable) { - try { - Either.right(rightAdapter.read(JsonTreeReader(elem)) ?: throw NullPointerException("right was empty")) - } catch(rightError: Throwable) { - val error = JsonSyntaxException("Can't read Either of values (left is $left, right is $right)") - error.addSuppressed(leftError) - error.addSuppressed(rightError) - throw error - } - } - } - } as TypeAdapter - } - - return null - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/KOptionalTypeAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/KOptionalTypeAdapter.kt deleted file mode 100644 index 09b6c2a9..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/KOptionalTypeAdapter.kt +++ /dev/null @@ -1,53 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.Gson -import com.google.gson.JsonSyntaxException -import com.google.gson.TypeAdapter -import com.google.gson.TypeAdapterFactory -import com.google.gson.reflect.TypeToken -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kstarbound.util.KOptional -import java.lang.reflect.ParameterizedType - -@Suppress("DEPRECATION") -object KOptionalTypeAdapter : TypeAdapterFactory { - override fun create(gson: Gson, type: TypeToken): TypeAdapter? { - if (type.rawType === KOptional.Nullable::class.java || type.rawType === KOptional::class.java || type.rawType === KOptional.NotNull::class.java) { - val notnull = type.rawType === KOptional.NotNull::class.java - val param = (type.type as? ParameterizedType ?: return null).actualTypeArguments[0] - val token = TypeToken.get(param) - val isBool = token.rawType === Boolean::class.java - - return object : TypeAdapter>() { - private val adapter0 = gson.getAdapter(token) as TypeAdapter - - override fun write(out: JsonWriter, value: KOptional?) { - if (value === null) { - out.nullValue() - } else if (value.isPresent) { - adapter0.write(out, value.value) - } - } - - override fun read(`in`: JsonReader): KOptional { - if (isBool) { - if (notnull) { - return KOptional((adapter0.read(`in`) ?: throw JsonSyntaxException("This KOptional does not accept nulls")) as Boolean) as KOptional - } else { - return KOptional(adapter0.read(`in`) as Boolean?) as KOptional - } - } else { - if (notnull) { - return KOptional(adapter0.read(`in`) ?: throw JsonSyntaxException("This KOptional does not accept nulls")) - } else { - return KOptional(adapter0.read(`in`)) - } - } - } - } as TypeAdapter - } else { - return null - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/NothingAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/NothingAdapter.kt deleted file mode 100644 index 472f1d2e..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/NothingAdapter.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.TypeAdapter -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonWriter - -object NothingAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: Nothing?) { - out.nullValue() - } - - override fun read(`in`: JsonReader): Nothing? { - `in`.skipValue() - return null - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/OneOfTypeAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/OneOfTypeAdapter.kt deleted file mode 100644 index 29ed8e60..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/OneOfTypeAdapter.kt +++ /dev/null @@ -1,71 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.Gson -import com.google.gson.JsonElement -import com.google.gson.JsonSyntaxException -import com.google.gson.TypeAdapter -import com.google.gson.TypeAdapterFactory -import com.google.gson.reflect.TypeToken -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kstarbound.util.OneOf -import java.lang.reflect.ParameterizedType - -object OneOfTypeAdapter : TypeAdapterFactory { - private class Adapter(gson: Gson, a: TypeToken, b: TypeToken, c: TypeToken) : TypeAdapter>() { - private val adapter0 = gson.getAdapter(a) - private val adapter1 = gson.getAdapter(b) - private val adapter2 = gson.getAdapter(c) - private val elements = gson.getAdapter(JsonElement::class.java) - - override fun write(out: JsonWriter, value: OneOf?) { - if (value == null) { - out.nullValue() - } else { - value.v0.ifPresent { adapter0.write(out, it) } - value.v1.ifPresent { adapter1.write(out, it) } - value.v2.ifPresent { adapter2.write(out, it) } - } - } - - override fun read(`in`: JsonReader): OneOf? { - if (`in`.consumeNull()) { - return null - } else { - val read = elements.read(`in`) - val errors = ArrayList(3) - - try { - return OneOf.first(adapter0.fromJsonTree(read)) - } catch (err: Exception) { - errors.add(err) - } - - try { - return OneOf.second(adapter1.fromJsonTree(read)) - } catch (err: Exception) { - errors.add(err) - } - - try { - return OneOf.third(adapter2.fromJsonTree(read)) - } catch (err: Exception) { - errors.add(err) - } - - throw JsonSyntaxException("None of type adapters consumed the input: $read").also { errors.forEach(it::addSuppressed) } - } - } - } - - override fun create(gson: Gson, type: TypeToken): TypeAdapter? { - if (type.rawType === OneOf::class.java) { - val p = type.type as? ParameterizedType ?: return null - val (a, b, c) = p.actualTypeArguments - - return Adapter(gson, TypeToken.get(a), TypeToken.get(b), TypeToken.get(c)) as TypeAdapter - } - - return null - } -} \ No newline at end of file diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/VectorJson.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/VectorJson.kt deleted file mode 100644 index c822cee5..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/VectorJson.kt +++ /dev/null @@ -1,118 +0,0 @@ -package ru.dbotthepony.kstarbound.json - -import com.google.gson.TypeAdapter -import com.google.gson.stream.JsonReader -import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector4d -import ru.dbotthepony.kvector.vector.Vector2f -import ru.dbotthepony.kvector.vector.Vector2i -import ru.dbotthepony.kvector.vector.Vector4i - -object Vector4iTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: Vector4i) { - `out`.beginArray() - `out`.value(value.x) - `out`.value(value.y) - `out`.value(value.z) - `out`.value(value.w) - `out`.endArray() - } - - override fun read(`in`: JsonReader): Vector4i { - `in`.beginArray() - - val x = `in`.nextInt() - val y = `in`.nextInt() - val z = `in`.nextInt() - val w = `in`.nextInt() - - `in`.endArray() - - return Vector4i(x, y, z, w) - } -} - -object Vector4dTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: Vector4d) { - `out`.beginArray() - `out`.value(value.x) - `out`.value(value.y) - `out`.value(value.z) - `out`.value(value.w) - `out`.endArray() - } - - override fun read(`in`: JsonReader): Vector4d { - `in`.beginArray() - - val x = `in`.nextDouble() - val y = `in`.nextDouble() - val z = `in`.nextDouble() - val w = `in`.nextDouble() - - `in`.endArray() - - return Vector4d(x, y, z, w) - } -} - -object Vector2iTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: Vector2i) { - `out`.beginArray() - `out`.value(value.x) - `out`.value(value.y) - `out`.endArray() - } - - override fun read(`in`: JsonReader): Vector2i { - `in`.beginArray() - - val x = `in`.nextInt() - val y = `in`.nextInt() - - `in`.endArray() - - return Vector2i(x, y) - } -} - -object Vector2fTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: Vector2f) { - `out`.beginArray() - `out`.value(value.x) - `out`.value(value.y) - `out`.endArray() - } - - override fun read(`in`: JsonReader): Vector2f { - `in`.beginArray() - - val x = `in`.nextDouble().toFloat() - val y = `in`.nextDouble().toFloat() - - `in`.endArray() - - return Vector2f(x, y) - } -} - -object Vector2dTypeAdapter : TypeAdapter() { - override fun write(out: JsonWriter, value: Vector2d) { - `out`.beginArray() - `out`.value(value.x) - `out`.value(value.y) - `out`.endArray() - } - - override fun read(`in`: JsonReader): Vector2d { - `in`.beginArray() - - val x = `in`.nextDouble() - val y = `in`.nextDouble() - - `in`.endArray() - - return Vector2d(x, y) - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/VersionedJson.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/VersionedJson.kt index 1f6747c2..f605ac30 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/VersionedJson.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/VersionedJson.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.kstarbound.json import com.google.gson.JsonElement -import ru.dbotthepony.kstarbound.io.readBinaryString +import ru.dbotthepony.kommons.io.readBinaryString import java.io.DataInputStream data class VersionedJson(val identifier: String, val version: Int?, val content: JsonElement) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/FactoryAdapter.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/FactoryAdapter.kt index ebd488eb..cab570b9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/FactoryAdapter.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/FactoryAdapter.kt @@ -22,13 +22,13 @@ import it.unimi.dsi.fastutil.ints.IntArrayList import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap import it.unimi.dsi.fastutil.objects.ObjectArraySet import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.core.Either import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.defs.util.enrollList import ru.dbotthepony.kstarbound.defs.util.enrollMap import ru.dbotthepony.kstarbound.defs.util.flattenJsonElement import ru.dbotthepony.kstarbound.json.consumeNull import ru.dbotthepony.kstarbound.json.value -import ru.dbotthepony.kstarbound.util.Either import java.lang.reflect.Constructor import java.util.Collections import java.util.function.Function diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/Properties.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/Properties.kt index 6c999ee1..bafb9622 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/Properties.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/builder/Properties.kt @@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.json.builder import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken -import ru.dbotthepony.kstarbound.util.KOptional +import ru.dbotthepony.kommons.core.KOptional import kotlin.properties.Delegates import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KProperty1 diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Functions.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Functions.kt index fe43039c..f63098a1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Functions.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/Functions.kt @@ -24,13 +24,10 @@ import org.classdump.luna.runtime.AbstractFunction4 import org.classdump.luna.runtime.AbstractFunctionAnyArg import org.classdump.luna.runtime.ExecutionContext import org.classdump.luna.runtime.LuaFunction +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.core.IStruct3i +import ru.dbotthepony.kommons.core.IStruct4i import ru.dbotthepony.kstarbound.json.InternedJsonElementAdapter -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.api.IStruct3i -import ru.dbotthepony.kvector.api.IStruct4i -import java.lang.ClassCastException -import java.lang.IllegalArgumentException -import java.lang.IndexOutOfBoundsException fun ArgumentIterator.nextOptionalFloat(): Double? { if (hasNext()) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/StateMachine.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/StateMachine.kt index de6f4193..7543d0a9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/StateMachine.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/StateMachine.kt @@ -6,8 +6,8 @@ import org.classdump.luna.runtime.Dispatch import org.classdump.luna.runtime.ExecutionContext import org.classdump.luna.runtime.Resumable import org.classdump.luna.runtime.UnresolvedControlThrowable -import ru.dbotthepony.kstarbound.util.KOptional -import ru.dbotthepony.kvector.vector.Vector2i +import ru.dbotthepony.kommons.core.KOptional +import ru.dbotthepony.kommons.vector.Vector2i import java.util.function.Supplier class StateMachine : Resumable { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/math/AABB.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/math/AABB.kt index b6fee9a5..cc49ec66 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/math/AABB.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/math/AABB.kt @@ -1,9 +1,9 @@ package ru.dbotthepony.kstarbound.math +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.util.AABBi +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.world.ChunkPos -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.util2d.AABBi -import ru.dbotthepony.kvector.vector.Vector2i fun AABB.encasingIntAABB(): AABBi { return AABBi( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/math/LineF.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/math/LineF.kt index 7d4b8de9..a238a250 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/math/LineF.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/math/LineF.kt @@ -4,9 +4,8 @@ import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter -import ru.dbotthepony.kstarbound.Starbound +import ru.dbotthepony.kommons.vector.Vector2f import ru.dbotthepony.kstarbound.json.consumeNull -import ru.dbotthepony.kvector.vector.Vector2f data class LineF(val start: Vector2f, val end: Vector2f) { class Adapter(gson: Gson) : TypeAdapter() { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/math/PeriodicFunction.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/math/PeriodicFunction.kt index 2ebb6d7b..f7830d4f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/math/PeriodicFunction.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/math/PeriodicFunction.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.math -import ru.dbotthepony.kvector.util.linearInterpolation +import ru.dbotthepony.kommons.math.linearInterpolation import java.util.random.RandomGenerator import kotlin.math.PI import kotlin.math.sin diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt index 2d12f53c..6c8dcc1d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/StarboundServer.kt @@ -1,10 +1,10 @@ package ru.dbotthepony.kstarbound.server +import ru.dbotthepony.kommons.util.MailboxExecutorService import ru.dbotthepony.kstarbound.client.network.packets.JoinWorldPacket import ru.dbotthepony.kstarbound.server.network.ServerChannels import ru.dbotthepony.kstarbound.server.network.ServerConnection import ru.dbotthepony.kstarbound.server.world.ServerWorld -import ru.dbotthepony.kstarbound.util.MailboxExecutorService import java.io.Closeable import java.io.File import java.util.Collections diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/ServerConnection.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/ServerConnection.kt index 11c4f8a4..7a029349 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/ServerConnection.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/ServerConnection.kt @@ -4,6 +4,7 @@ import io.netty.channel.ChannelHandlerContext import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.client.network.packets.ForgetChunkPacket import ru.dbotthepony.kstarbound.client.network.packets.InitialChunkDataPacket import ru.dbotthepony.kstarbound.client.network.packets.SpawnWorldObjectPacket @@ -15,7 +16,6 @@ import ru.dbotthepony.kstarbound.network.packets.HelloPacket import ru.dbotthepony.kstarbound.server.StarboundServer import ru.dbotthepony.kstarbound.server.world.ServerWorld import ru.dbotthepony.kstarbound.world.ChunkPos -import ru.dbotthepony.kvector.vector.Vector2d import java.util.* class ServerConnection(val server: StarboundServer, type: ConnectionType) : Connection(ConnectionSide.SERVER, type, UUID(0L, 0L)) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/packets/TrackedPositionPacket.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/packets/TrackedPositionPacket.kt index 0400b5c9..54ca75a5 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/packets/TrackedPositionPacket.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/network/packets/TrackedPositionPacket.kt @@ -1,10 +1,10 @@ package ru.dbotthepony.kstarbound.server.network.packets +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.network.IServerPacket import ru.dbotthepony.kstarbound.server.network.ServerConnection import ru.dbotthepony.kstarbound.io.readVec2d import ru.dbotthepony.kstarbound.io.writeVec2d -import ru.dbotthepony.kvector.vector.Vector2d import java.io.DataInputStream import java.io.DataOutputStream diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSaver.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSaver.kt index e00b4cd5..088e4183 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSaver.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSaver.kt @@ -1,9 +1,9 @@ package ru.dbotthepony.kstarbound.server.world +import ru.dbotthepony.kommons.arrays.Object2DArray import ru.dbotthepony.kstarbound.world.ChunkPos import ru.dbotthepony.kstarbound.world.api.AbstractCell import ru.dbotthepony.kstarbound.world.entities.WorldObject -import ru.dbotthepony.kvector.arrays.Object2DArray interface IChunkSaver { fun saveCells(pos: ChunkPos, data: Object2DArray) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSource.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSource.kt index 9e4ab34b..e07ce2d7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSource.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/IChunkSource.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.server.world -import ru.dbotthepony.kstarbound.util.KOptional +import ru.dbotthepony.kommons.arrays.Object2DArray +import ru.dbotthepony.kommons.core.KOptional import ru.dbotthepony.kstarbound.world.CHUNK_SIZE import ru.dbotthepony.kstarbound.world.ChunkPos import ru.dbotthepony.kstarbound.world.api.AbstractCell import ru.dbotthepony.kstarbound.world.entities.WorldObject -import ru.dbotthepony.kvector.arrays.Object2DArray import java.util.concurrent.CompletableFuture interface IChunkSource { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/LegacyChunkSource.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/LegacyChunkSource.kt index 38fb3285..e6f0e447 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/LegacyChunkSource.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/LegacyChunkSource.kt @@ -1,18 +1,18 @@ package ru.dbotthepony.kstarbound.server.world import org.apache.logging.log4j.LogManager +import ru.dbotthepony.kommons.arrays.Object2DArray +import ru.dbotthepony.kommons.core.KOptional +import ru.dbotthepony.kommons.io.readVarInt +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.io.BTreeDB -import ru.dbotthepony.kstarbound.io.readVarInt import ru.dbotthepony.kstarbound.json.VersionedJson -import ru.dbotthepony.kstarbound.util.KOptional import ru.dbotthepony.kstarbound.world.CHUNK_SIZE import ru.dbotthepony.kstarbound.world.ChunkPos import ru.dbotthepony.kstarbound.world.api.AbstractCell import ru.dbotthepony.kstarbound.world.api.MutableCell import ru.dbotthepony.kstarbound.world.entities.WorldObject -import ru.dbotthepony.kvector.arrays.Object2DArray -import ru.dbotthepony.kvector.vector.Vector2i import java.io.BufferedInputStream import java.io.ByteArrayInputStream import java.io.DataInputStream diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt index c43847df..3fcde367 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt @@ -1,12 +1,12 @@ package ru.dbotthepony.kstarbound.server.world import it.unimi.dsi.fastutil.objects.ObjectArraySet +import ru.dbotthepony.kommons.arrays.Object2DArray import ru.dbotthepony.kstarbound.world.CHUNK_SIZE import ru.dbotthepony.kstarbound.world.Chunk import ru.dbotthepony.kstarbound.world.ChunkPos import ru.dbotthepony.kstarbound.world.api.AbstractCell import ru.dbotthepony.kstarbound.world.api.ImmutableCell -import ru.dbotthepony.kvector.arrays.Object2DArray class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk(world, pos) { fun copyCells(): Object2DArray { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorld.kt index c0896629..4e84b954 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorld.kt @@ -4,10 +4,10 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectFunction import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet import it.unimi.dsi.fastutil.objects.ObjectArraySet +import ru.dbotthepony.kommons.core.KOptional import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.server.StarboundServer import ru.dbotthepony.kstarbound.server.network.ServerConnection -import ru.dbotthepony.kstarbound.util.KOptional import ru.dbotthepony.kstarbound.util.composeFutures import ru.dbotthepony.kstarbound.world.ChunkPos import ru.dbotthepony.kstarbound.world.World diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/tools/Sbon2Json.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/tools/Sbon2Json.kt index 0ea8a54a..a0071b0e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/tools/Sbon2Json.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/tools/Sbon2Json.kt @@ -1,9 +1,9 @@ package ru.dbotthepony.kstarbound.tools import com.google.gson.GsonBuilder +import ru.dbotthepony.kommons.io.readVarInt import ru.dbotthepony.kstarbound.io.readHeader import ru.dbotthepony.kstarbound.io.readString -import ru.dbotthepony.kstarbound.io.readVarInt import ru.dbotthepony.kstarbound.json.readJsonElement import java.io.BufferedInputStream import java.io.DataInputStream diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt deleted file mode 100644 index 94842bab..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Either.kt +++ /dev/null @@ -1,81 +0,0 @@ -package ru.dbotthepony.kstarbound.util - -import ru.dbotthepony.kstarbound.json.EitherTypeAdapter - -/** - * Представляет собой контейнер с "или тот или другой" значениями - * - * JSON адаптер реализуется через [EitherTypeAdapter] - */ -class Either private constructor(val left: KOptional, val right: KOptional) { - val isLeft: Boolean get() = left.isPresent - val isRight: Boolean get() = right.isPresent - - inline fun map(left: (L) -> T, right: (R) -> T): T { - this.left.ifPresent { - return left.invoke(it) - } - - return right.invoke(this.right.value) - } - - inline fun flatMap(left: (L) -> NL, right: (R) -> NR): Either { - this.left.ifPresent { - return left(left.invoke(it)) - } - - return right(right.invoke(this.right.value)) - } - - /** - * @throws NoSuchElementException - */ - fun left(): L = left.value - - /** - * @throws NoSuchElementException - */ - fun right(): R = right.value - - inline fun leftOrElse(orElse: () -> L): L { - if (isLeft) - return left() - else - return orElse.invoke() - } - - inline fun rightOrElse(orElse: () -> R): R { - if (isRight) - return right() - else - return orElse.invoke() - } - - override fun equals(other: Any?): Boolean { - return other === this || other is Either<*, *> && other.left == left && other.right == right - } - - override fun hashCode(): Int { - return left.hashCode() * 31 + right.hashCode() - } - - override fun toString(): String { - if (isLeft) { - return "Either.left[${left.value}]" - } else { - return "Either.right[${right.value}]" - } - } - - companion object { - @JvmStatic - fun left(value: L): Either { - return Either(KOptional.of(value), KOptional.empty()) - } - - @JvmStatic - fun right(value: R): Either { - return Either(KOptional.empty(), KOptional.of(value)) - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/JsonArrayCollector.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/JsonArrayCollector.kt deleted file mode 100644 index e7c086d4..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/JsonArrayCollector.kt +++ /dev/null @@ -1,31 +0,0 @@ -package ru.dbotthepony.kstarbound.util - -import com.google.gson.JsonArray -import com.google.gson.JsonElement -import java.util.function.BiConsumer -import java.util.function.BinaryOperator -import java.util.function.Function -import java.util.function.Supplier -import java.util.stream.Collector - -object JsonArrayCollector : Collector { - override fun supplier(): Supplier { - return Supplier { JsonArray() } - } - - override fun accumulator(): BiConsumer { - return BiConsumer { t, u -> t.add(u) } - } - - override fun combiner(): BinaryOperator { - return BinaryOperator { t, u -> t.addAll(u); t } - } - - override fun finisher(): Function { - return Function.identity() - } - - override fun characteristics(): Set { - return setOf(Collector.Characteristics.IDENTITY_FINISH) - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/KOptional.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/KOptional.kt deleted file mode 100644 index a144bdb8..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/KOptional.kt +++ /dev/null @@ -1,152 +0,0 @@ -package ru.dbotthepony.kstarbound.util - -import java.util.function.Supplier - -fun KOptional(value: T) = KOptional.of(value) -fun KOptional(value: Boolean) = KOptional.of(value) -fun KOptional(value: Boolean?) = KOptional.of(value) - -/** - * [java.util.Optional] supporting nulls - * - * This is done for structures, where value can be absent, - * or can be present, including literal "null" as possible present value, - * in more elegant solution than handling nullable Optionals - */ -class KOptional private constructor(private val _value: T, val isPresent: Boolean) : Supplier { - /** - * @throws NoSuchElementException - */ - val value: T get() { - if (isPresent) { - return _value - } - - throw NoSuchElementException("No value is present") - } - - inline fun ifPresent(block: (T) -> Unit): KOptional { - if (isPresent) { - block.invoke(value) - } - - return this - } - - inline fun ifNotPresent(block: () -> Unit): KOptional { - if (!isPresent) { - block.invoke() - } - - return this - } - - inline fun map(block: (T) -> R): KOptional { - if (isPresent) { - return of(block.invoke(value)) - } else { - return empty() - } - } - - @Suppress("NOTHING_TO_INLINE") - inline fun orElse(value: T): T { - if (isPresent) { - return this.value - } else { - return value - } - } - - inline fun orElse(value: () -> T): T { - if (isPresent) { - return this.value - } else { - return value.invoke() - } - } - - infix fun or(value: KOptional): KOptional { - if (isPresent) { - return this - } else { - return value - } - } - - override fun equals(other: Any?): Boolean { - return this === other || other is KOptional<*> && isPresent == other.isPresent && _value == other._value - } - - override fun hashCode(): Int { - return _value.hashCode() + 43839429 - } - - override fun toString(): String { - if (isPresent) { - return "KOptional[value = $value]" - } else { - return "KOptional[empty]" - } - } - - override fun get(): T { - return value - } - - // gson hack since type token can't diff between nullable and non-null types - @Deprecated("internal class") - internal class Nullable private constructor() - @Deprecated("internal class") - internal class NotNull private constructor() - - companion object { - private val EMPTY = KOptional(null, false) - private val NULL = KOptional(null, true) - private val TRUE = KOptional(true, true) - private val FALSE = KOptional(false, true) - - @JvmStatic - fun empty(): KOptional { - return EMPTY as KOptional - } - - @JvmStatic - fun of(value: T): KOptional { - if (value == null) { - return NULL as KOptional - } else { - return KOptional(value, true) - } - } - - @JvmStatic - fun ofNullable(value: T): KOptional { - if (value == null) { - return EMPTY as KOptional - } else { - return KOptional(value, true) - } - } - - @JvmStatic - fun of(value: Boolean): KOptional { - if (value) { - return TRUE - } else { - return FALSE - } - } - - @JvmStatic - fun of(value: Boolean?): KOptional { - if (value == null) { - return NULL as KOptional - } else if (value) { - return TRUE - } else { - return FALSE - } - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/MailboxExecutorService.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/MailboxExecutorService.kt deleted file mode 100644 index c92d7f8c..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/MailboxExecutorService.kt +++ /dev/null @@ -1,396 +0,0 @@ -package ru.dbotthepony.kstarbound.util - -import com.google.common.util.concurrent.Futures -import java.util.LinkedList -import java.util.concurrent.Callable -import java.util.concurrent.ConcurrentLinkedQueue -import java.util.concurrent.Delayed -import java.util.concurrent.Future -import java.util.concurrent.FutureTask -import java.util.concurrent.RejectedExecutionException -import java.util.concurrent.ScheduledExecutorService -import java.util.concurrent.ScheduledFuture -import java.util.concurrent.TimeUnit -import java.util.concurrent.locks.LockSupport -import java.util.concurrent.locks.ReentrantLock -import kotlin.concurrent.withLock - -private fun > LinkedList.enqueue(value: E) { - if (isEmpty()) { - add(value) - } else if (first >= value) { - addFirst(value) - } else if (last <= value) { - addLast(value) - } else { - val iterator = listIterator() - - while (iterator.hasNext()) { - val i = iterator.next() - - if (i >= value) { - iterator.previous() - iterator.add(value) - break - } - } - } -} - -class MailboxExecutorService(thread: Thread = Thread.currentThread()) : ScheduledExecutorService { - @Volatile - var thread: Thread = thread - private set - - private val futureQueue = ConcurrentLinkedQueue>() - - private val timers = LinkedList>() - private val repeatableTimers = LinkedList() - private val executionLock = ReentrantLock() - - @Volatile - private var isShutdown = false - @Volatile - private var isTerminated = false - - private val timeOrigin = JVMTimeSource() - - private inner class Timer(task: Callable, val executeAt: Long) : FutureTask(task), ScheduledFuture { - override fun compareTo(other: Delayed): Int { - return getDelay(TimeUnit.NANOSECONDS).compareTo(other.getDelay(TimeUnit.NANOSECONDS)) - } - - override fun getDelay(unit: TimeUnit): Long { - return unit.convert(executeAt, TimeUnit.NANOSECONDS) - timeOrigin.nanos - } - } - - private inner class RepeatableTimer( - task: Runnable, - initialDelay: Long, - val period: Long, - val fixedDelay: Boolean, - ): FutureTask({ task.run() }), ScheduledFuture { - var next = initialDelay - private set - - public override fun runAndReset(): Boolean { - if (fixedDelay) { - next += period - return super.runAndReset() - } else { - try { - return super.runAndReset() - } finally { - next += period - } - } - } - - override fun compareTo(other: Delayed): Int { - return getDelay(TimeUnit.NANOSECONDS).compareTo(other.getDelay(TimeUnit.NANOSECONDS)) - } - - override fun getDelay(unit: TimeUnit): Long { - return unit.convert(next, TimeUnit.NANOSECONDS) - timeOrigin.nanos - } - } - - fun isSameThread(): Boolean { - return Thread.currentThread() === thread - } - - fun executeQueuedTasks() { - thread = Thread.currentThread() - - if (isShutdown) { - if (!isTerminated) { - isTerminated = true - - executionLock.withLock { - timers.clear() - repeatableTimers.clear() - } - - return - } - } - - executionLock.withLock { - var next = futureQueue.poll() - - while (next != null) { - if (isTerminated) return - next.run() - Thread.interrupted() - next = futureQueue.poll() - } - - while (!timers.isEmpty()) { - if (isTerminated) return - val first = timers.first - - if (first.isCancelled) { - timers.removeFirst() - } else if (first.executeAt <= timeOrigin.nanos) { - first.run() - Thread.interrupted() - timers.removeFirst() - } else { - break - } - } - - if (repeatableTimers.isNotEmpty()) { - val executed = LinkedList() - - while (repeatableTimers.isNotEmpty()) { - if (isTerminated) return - val first = repeatableTimers.first - - if (first.isDone) { - repeatableTimers.removeFirst() - } else if (first.next <= timeOrigin.nanos) { - first.runAndReset() - executed.add(first) - repeatableTimers.removeFirst() - } else { - break - } - } - - executed.forEach { repeatableTimers.enqueue(it) } - } - } - } - - override fun execute(command: Runnable) { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - if (isSameThread()) { - command.run() - } else { - futureQueue.add(FutureTask(command, Unit)) - LockSupport.unpark(thread) - } - } - - override fun shutdown() { - isShutdown = true - } - - override fun shutdownNow(): MutableList { - isShutdown = true - isTerminated = true - - val result = ArrayList() - - executionLock.withLock { - futureQueue.forEach { - it.cancel(false) - result.add(it) - } - - futureQueue.clear() - - timers.forEach { it.cancel(false) } - repeatableTimers.forEach { it.cancel(false) } - - timers.clear() - repeatableTimers.clear() - } - - return result - } - - override fun isShutdown(): Boolean { - return isShutdown - } - - override fun isTerminated(): Boolean { - return isTerminated - } - - override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean { - throw UnsupportedOperationException() - } - - override fun submit(task: Callable): Future { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - if (isSameThread()) return Futures.immediateFuture(task.call()) - return FutureTask(task).also { futureQueue.add(it); LockSupport.unpark(thread) } - } - - override fun submit(task: Runnable, result: T): Future { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - if (isSameThread()) { task.run(); return Futures.immediateFuture(result) } - return FutureTask { task.run(); result }.also { futureQueue.add(it); LockSupport.unpark(thread) } - } - - override fun submit(task: Runnable): Future<*> { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - if (isSameThread()) { task.run(); return Futures.immediateVoidFuture() } - return FutureTask { task.run() }.also { futureQueue.add(it); LockSupport.unpark(thread) } - } - - override fun invokeAll(tasks: Collection>): List> { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - if (isSameThread()) { - return tasks.map { Futures.immediateFuture(it.call()) } - } else { - return tasks.map { submit(it) }.onEach { it.get() } - } - } - - override fun invokeAll( - tasks: Collection>, - timeout: Long, - unit: TimeUnit - ): List> { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - if (isSameThread()) { - return tasks.map { Futures.immediateFuture(it.call()) } - } else { - return tasks.map { submit(it) }.onEach { it.get(timeout, unit) } - } - } - - override fun invokeAny(tasks: Collection>): T { - if (tasks.isEmpty()) - throw NoSuchElementException("Provided task list is empty") - - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - if (isSameThread()) { - return tasks.first().call() - } else { - return submit(tasks.first()).get() - } - } - - override fun invokeAny(tasks: Collection>, timeout: Long, unit: TimeUnit): T { - if (tasks.isEmpty()) - throw NoSuchElementException("Provided task list is empty") - - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - if (isSameThread()) { - return tasks.first().call() - } else { - return submit(tasks.first()).get(timeout, unit) - } - } - - fun join(future: Future): V { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - if (!isSameThread()) - return future.get() - - while (!future.isDone) { - executeQueuedTasks() - LockSupport.parkNanos(1_000_000L) - } - - return future.get() - } - - override fun schedule(command: Runnable, delay: Long, unit: TimeUnit): ScheduledFuture<*> { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - val timer = Timer({ command.run() }, timeOrigin.nanos + TimeUnit.NANOSECONDS.convert(delay, unit)) - - if (isSameThread() && delay <= 0L) { - timer.run() - Thread.interrupted() - } else if (isSameThread()) { - timers.enqueue(timer) - } else { - execute { - if (timer.isCancelled) { - // do nothing - } else if (timer.executeAt <= timeOrigin.nanos) { - timer.run() - Thread.interrupted() - } else { - timers.enqueue(timer) - } - } - } - - return timer - } - - override fun schedule(callable: Callable, delay: Long, unit: TimeUnit): ScheduledFuture { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - val timer = Timer(callable, timeOrigin.nanos + TimeUnit.NANOSECONDS.convert(delay, unit)) - - if (isSameThread() && delay <= 0L) { - timer.run() - Thread.interrupted() - } else if (isSameThread()) { - timers.enqueue(timer) - } else { - execute { - if (timer.isCancelled) { - // do nothing - } else if (timer.executeAt <= timeOrigin.nanos) { - timer.run() - Thread.interrupted() - } else { - timers.enqueue(timer) - } - } - } - - return timer - } - - override fun scheduleAtFixedRate( - command: Runnable, - initialDelay: Long, - period: Long, - unit: TimeUnit - ): ScheduledFuture<*> { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - return RepeatableTimer( - command, - timeOrigin.nanos + TimeUnit.NANOSECONDS.convert(initialDelay, unit), - TimeUnit.NANOSECONDS.convert(period, unit), true) - .also { - execute { - if (it.isCancelled) { - // do nothing - } else { - repeatableTimers.enqueue(it) - } - } - } - } - - override fun scheduleWithFixedDelay( - command: Runnable, - initialDelay: Long, - delay: Long, - unit: TimeUnit - ): ScheduledFuture<*> { - if (isShutdown) throw RejectedExecutionException("This mailbox is shutting down") - - return RepeatableTimer( - command, - timeOrigin.nanos + TimeUnit.NANOSECONDS.convert(initialDelay, unit), - TimeUnit.NANOSECONDS.convert(delay, unit), false) - .also { - execute { - if (it.isCancelled) { - // do nothing - } else { - repeatableTimers.enqueue(it) - } - } - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/OneOf.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/OneOf.kt deleted file mode 100644 index cd9b4337..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/OneOf.kt +++ /dev/null @@ -1,36 +0,0 @@ -package ru.dbotthepony.kstarbound.util - -/** - * [Either] but with 3 values - */ -class OneOf private constructor( - val v0: KOptional, - val v1: KOptional, - val v2: KOptional, -) { - override fun equals(other: Any?): Boolean { - return other === this || other is OneOf<*, *, *> && v0 == other.v0 && v1 == other.v1 && v2 == other.v2 - } - - override fun hashCode(): Int { - return v0.hashCode() + v1.hashCode() * 31 + v2.hashCode() * 31 * 31 - } - - override fun toString(): String { - return "OneOf[$v0, $v1, $v2]" - } - - companion object { - fun first(value: A): OneOf { - return OneOf(KOptional.of(value), KOptional.empty(), KOptional.empty()) - } - - fun second(value: B): OneOf { - return OneOf(KOptional.empty(), KOptional.of(value), KOptional.empty()) - } - - fun third(value: C): OneOf { - return OneOf(KOptional.empty(), KOptional.empty(), KOptional.of(value)) - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/TimeSource.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/TimeSource.kt deleted file mode 100644 index f2135803..00000000 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/TimeSource.kt +++ /dev/null @@ -1,68 +0,0 @@ -package ru.dbotthepony.kstarbound.util - -interface ITimeSource { - /** - * Время в наносекундах - */ - val nanos: Long - - /** - * Время в микросекундах - */ - val micros: Long get() = nanos / 1_000L - - /** - * Время в миллисекундах - */ - val millis: Long get() = nanos / 1_000_000L - - /** - * Время в секундах, с точностью до микросекунд - */ - val seconds: Double get() = (nanos / 1_000L) / 1_000_000.0 -} - -class JVMTimeSource : ITimeSource { - private val origin = System.nanoTime() - - override val nanos: Long - get() = System.nanoTime() - origin - - companion object { - @JvmField - val INSTANCE = JVMTimeSource() - } -} - -class ArtificialTimeSource(nanos: Long = 0L) : ITimeSource { - override var nanos: Long = nanos - private set - - fun advance(nanos: Long) { - this.nanos += nanos - } -} - -class PausableTimeSource(private val parent: ITimeSource) : ITimeSource { - override val nanos: Long get() { - if (isPaused) { - return pausedSince - skipped - } else { - return parent.nanos - skipped - } - } - - private var isPaused = false - private var pausedSince = 0L - private var skipped = 0L - - fun pause() { - if (!isPaused) { - isPaused = true - pausedSince = parent.nanos - } else { - isPaused = false - skipped += parent.nanos - pausedSince - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt index cecebdbe..4cf6ca67 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject +import ru.dbotthepony.kommons.core.KOptional import ru.dbotthepony.kstarbound.Starbound import java.lang.ref.Reference import java.util.* diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt index 5d92128c..ab69517e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Chunk.kt @@ -3,6 +3,9 @@ package ru.dbotthepony.kstarbound.world import it.unimi.dsi.fastutil.objects.ObjectArrayList import it.unimi.dsi.fastutil.objects.ObjectArraySet import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet +import ru.dbotthepony.kommons.arrays.Object2DArray +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.world.api.AbstractCell import ru.dbotthepony.kstarbound.world.api.ICellAccess import ru.dbotthepony.kstarbound.world.api.ImmutableCell @@ -10,9 +13,6 @@ import ru.dbotthepony.kstarbound.world.api.OffsetCellAccess import ru.dbotthepony.kstarbound.world.api.TileView import ru.dbotthepony.kstarbound.world.entities.Entity import ru.dbotthepony.kstarbound.world.entities.WorldObject -import ru.dbotthepony.kvector.arrays.Object2DArray -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.Vector2d import kotlin.concurrent.withLock /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt index fd93e886..621bdd15 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/ChunkPos.kt @@ -1,10 +1,7 @@ package ru.dbotthepony.kstarbound.world -import ru.dbotthepony.kstarbound.math.roundByAbsoluteValue -import ru.dbotthepony.kstarbound.world.CHUNK_SIZE_BITS -import ru.dbotthepony.kvector.api.IStruct2d -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.vector.Vector2i +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.vector.Vector2i private fun circulate(value: Int, bounds: Int): Int { require(bounds > 0) { "Bounds must be positive ($bounds given)" } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Direction.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Direction.kt index 71c38d4b..c16a2269 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Direction.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Direction.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.world -import ru.dbotthepony.kvector.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2d enum class Direction(val normal: Vector2d) { UP(Vector2d.POSITIVE_Y), diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/LightCalculator.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/LightCalculator.kt index 31ac6433..c7c83285 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/LightCalculator.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/LightCalculator.kt @@ -2,11 +2,11 @@ package ru.dbotthepony.kstarbound.world import it.unimi.dsi.fastutil.ints.IntArraySet import org.lwjgl.BufferUtils +import ru.dbotthepony.kommons.arrays.Object2DArray +import ru.dbotthepony.kommons.core.IStruct4f +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.math.linearInterpolation import ru.dbotthepony.kstarbound.world.api.ICellAccess -import ru.dbotthepony.kvector.api.IStruct4f -import ru.dbotthepony.kvector.arrays.Object2DArray -import ru.dbotthepony.kvector.util.linearInterpolation -import ru.dbotthepony.kvector.vector.RGBAColor import java.nio.ByteBuffer import java.util.concurrent.Callable import java.util.concurrent.CompletableFuture diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt index f6094e80..ab6b9b65 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Raycasting.kt @@ -1,10 +1,10 @@ package ru.dbotthepony.kstarbound.world +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.math.roundTowardsNegativeInfinity import ru.dbotthepony.kstarbound.world.api.ICellAccess import ru.dbotthepony.kstarbound.world.api.AbstractCell -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.Vector2i import kotlin.collections.ArrayList import kotlin.math.pow import kotlin.math.sqrt diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt index 2e1f3729..cf551084 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/World.kt @@ -5,8 +5,13 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList import it.unimi.dsi.fastutil.objects.ObjectArraySet import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet +import ru.dbotthepony.kommons.arrays.Object2DArray +import ru.dbotthepony.kommons.core.IStruct2d +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.util.MailboxExecutorService +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.math.* -import ru.dbotthepony.kstarbound.util.MailboxExecutorService import ru.dbotthepony.kstarbound.util.ParallelPerform import ru.dbotthepony.kstarbound.util.filterNotNull import ru.dbotthepony.kstarbound.world.api.ICellAccess @@ -19,11 +24,6 @@ import ru.dbotthepony.kstarbound.world.physics.CollisionType import ru.dbotthepony.kstarbound.world.physics.Poly import ru.dbotthepony.kstarbound.world.physics.getBlockPlatforms import ru.dbotthepony.kstarbound.world.physics.getBlocksMarchingSquares -import ru.dbotthepony.kvector.api.IStruct2d -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.arrays.Object2DArray -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.Vector2d import java.io.Closeable import java.util.concurrent.ForkJoinPool import java.util.concurrent.locks.ReentrantLock diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt index d5214f56..06037e62 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.world +import ru.dbotthepony.kommons.core.IStruct2d +import ru.dbotthepony.kommons.core.IStruct2f +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.io.readVec2i import ru.dbotthepony.kstarbound.io.writeVec2i -import ru.dbotthepony.kvector.api.IStruct2d -import ru.dbotthepony.kvector.api.IStruct2f -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.vector.Vector2i import java.io.DataInputStream import java.io.DataOutputStream diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ICellAccess.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ICellAccess.kt index 0d78e4cb..4e3c1a9f 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ICellAccess.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ICellAccess.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.kstarbound.world.api -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.vector.Vector2i +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.vector.Vector2i interface ICellAccess { /** diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileAccess.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileAccess.kt index 05817424..ea475508 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileAccess.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/ITileAccess.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.world.api +import ru.dbotthepony.kommons.core.IStruct2i import ru.dbotthepony.kstarbound.world.physics.CollisionType import ru.dbotthepony.kstarbound.world.physics.CollisionTypeGetter -import ru.dbotthepony.kvector.api.IStruct2i // for getting tiles directly, avoiding manual layer specification interface ITileAccess : ICellAccess, CollisionTypeGetter { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/OffsetCellAccess.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/OffsetCellAccess.kt index 29f66c93..e1f5eb27 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/OffsetCellAccess.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/api/OffsetCellAccess.kt @@ -1,7 +1,7 @@ package ru.dbotthepony.kstarbound.world.api -import ru.dbotthepony.kvector.api.IStruct2i -import ru.dbotthepony.kvector.vector.Vector2i +import ru.dbotthepony.kommons.core.IStruct2i +import ru.dbotthepony.kommons.vector.Vector2i class OffsetCellAccess(private val parent: ICellAccess, var x: Int, var y: Int) : ICellAccess { constructor(parent: ICellAccess, offset: IStruct2i) : this(parent, offset.component1(), offset.component2()) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractActorMovementController.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractActorMovementController.kt index 14709296..04424464 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractActorMovementController.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractActorMovementController.kt @@ -1,5 +1,6 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.defs.ActorMovementParameters import ru.dbotthepony.kstarbound.defs.JumpProfile @@ -8,7 +9,6 @@ import ru.dbotthepony.kstarbound.defs.player.ActorMovementModifiers import ru.dbotthepony.kstarbound.util.GameTimer import ru.dbotthepony.kstarbound.world.Direction import ru.dbotthepony.kstarbound.world.physics.CollisionType -import ru.dbotthepony.kvector.vector.Vector2d import kotlin.math.PI import kotlin.math.absoluteValue import kotlin.math.sign diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractMovementController.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractMovementController.kt index 76300ff4..316af504 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractMovementController.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/AbstractMovementController.kt @@ -1,15 +1,15 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.math.linearInterpolation +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.vector.Vector2d +import ru.dbotthepony.kommons.vector.times import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.defs.MovementParameters import ru.dbotthepony.kstarbound.world.World import ru.dbotthepony.kstarbound.world.physics.CollisionPoly import ru.dbotthepony.kstarbound.world.physics.CollisionType import ru.dbotthepony.kstarbound.world.physics.Poly -import ru.dbotthepony.kvector.util.linearInterpolation -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.Vector2d -import ru.dbotthepony.kvector.vector.times import java.util.stream.Stream import kotlin.math.PI import kotlin.math.absoluteValue diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/Entity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/Entity.kt index f75351fb..675fe658 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/Entity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/Entity.kt @@ -1,12 +1,12 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.util.MailboxExecutorService +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.client.StarboundClient -import ru.dbotthepony.kstarbound.util.MailboxExecutorService import ru.dbotthepony.kstarbound.world.Chunk import ru.dbotthepony.kstarbound.world.World -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d import kotlin.concurrent.withLock abstract class Entity(val world: World<*, *>) { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityActorMovementController.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityActorMovementController.kt index 35dea239..38921534 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityActorMovementController.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityActorMovementController.kt @@ -1,13 +1,11 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.GlobalDefaults import ru.dbotthepony.kstarbound.defs.ActorMovementParameters -import ru.dbotthepony.kstarbound.defs.MovementParameters import ru.dbotthepony.kstarbound.defs.player.ActorMovementModifiers import ru.dbotthepony.kstarbound.world.Direction import ru.dbotthepony.kstarbound.world.World -import ru.dbotthepony.kstarbound.world.physics.Poly -import ru.dbotthepony.kvector.vector.Vector2d class EntityActorMovementController(val entity: Entity) : AbstractActorMovementController() { override val world: World<*, *> by entity::world diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityMovementController.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityMovementController.kt index f1a772ba..113000a7 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityMovementController.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/EntityMovementController.kt @@ -1,10 +1,9 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.GlobalDefaults import ru.dbotthepony.kstarbound.defs.MovementParameters import ru.dbotthepony.kstarbound.world.World -import ru.dbotthepony.kstarbound.world.physics.Poly -import ru.dbotthepony.kvector.vector.Vector2d class EntityMovementController(val entity: Entity) : AbstractMovementController() { override val world: World<*, *> by entity::world diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt index ed4e1828..57be5fb9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/ItemEntity.kt @@ -1,11 +1,11 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.core.Either +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.defs.item.api.IItemDefinition -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.world.World import ru.dbotthepony.kstarbound.world.physics.Poly -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.vector.Vector2d class ItemEntity(world: World<*, *>, val def: IItemDefinition) : Entity(world) { override val movement = EntityMovementController(this) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PathController.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PathController.kt index c895bc6e..8a0f5b00 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PathController.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PathController.kt @@ -1,8 +1,8 @@ package ru.dbotthepony.kstarbound.world.entities +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.world.Direction import ru.dbotthepony.kstarbound.world.World -import ru.dbotthepony.kvector.vector.Vector2d class PathController(val world: World<*, *>, var edgeTimer: Double = 0.0) { var startPosition: Vector2d? = null diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PlayerEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PlayerEntity.kt index 832d2f84..3c74ff30 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PlayerEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/PlayerEntity.kt @@ -2,10 +2,7 @@ package ru.dbotthepony.kstarbound.world.entities import ru.dbotthepony.kstarbound.Starbound import ru.dbotthepony.kstarbound.defs.ActorMovementParameters -import ru.dbotthepony.kstarbound.fromJson -import ru.dbotthepony.kstarbound.util.Either import ru.dbotthepony.kstarbound.world.World -import ru.dbotthepony.kstarbound.world.physics.Poly class PlayerEntity(world: World<*, *>) : Entity(world) { override val movement = EntityActorMovementController(this) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/WorldObject.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/WorldObject.kt index 2a3e5a76..4ea7893d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/WorldObject.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/WorldObject.kt @@ -5,6 +5,9 @@ import com.google.gson.JsonObject import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.util.MailboxExecutorService +import ru.dbotthepony.kommons.vector.Vector2i import ru.dbotthepony.kstarbound.Registries import ru.dbotthepony.kstarbound.Registry import ru.dbotthepony.kstarbound.Starbound @@ -15,15 +18,12 @@ import ru.dbotthepony.kstarbound.defs.image.SpriteReference import ru.dbotthepony.kstarbound.defs.`object`.ObjectDefinition import ru.dbotthepony.kstarbound.defs.`object`.ObjectOrientation import ru.dbotthepony.kstarbound.server.world.ServerWorld -import ru.dbotthepony.kstarbound.util.MailboxExecutorService import ru.dbotthepony.kstarbound.json.get import ru.dbotthepony.kstarbound.json.set import ru.dbotthepony.kstarbound.world.Side import ru.dbotthepony.kstarbound.world.LightCalculator import ru.dbotthepony.kstarbound.world.World import ru.dbotthepony.kstarbound.world.api.TileColor -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2i import kotlin.properties.Delegates open class WorldObject( diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/CollisionPoly.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/CollisionPoly.kt index b0f18f18..73625606 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/CollisionPoly.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/CollisionPoly.kt @@ -1,6 +1,6 @@ package ru.dbotthepony.kstarbound.world.physics -import ru.dbotthepony.kvector.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2d data class CollisionPoly( val poly: Poly, diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Functions.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Functions.kt index d47b8353..0be00833 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Functions.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Functions.kt @@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.world.physics import com.google.common.collect.ImmutableList import it.unimi.dsi.fastutil.ints.IntList -import ru.dbotthepony.kvector.vector.Vector2d +import ru.dbotthepony.kommons.vector.Vector2d private val POLY_VERTICES: ImmutableList = ImmutableList.of( Vector2d(0.5, 0.5), diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Poly.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Poly.kt index 16ece1ee..32bdb41e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Poly.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/physics/Poly.kt @@ -9,16 +9,16 @@ import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import org.lwjgl.opengl.GL11.GL_LINES +import ru.dbotthepony.kommons.core.IStruct2d +import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.kommons.math.intersectSegments +import ru.dbotthepony.kommons.matrix.Matrix3f +import ru.dbotthepony.kommons.util.AABB +import ru.dbotthepony.kommons.vector.Vector2d import ru.dbotthepony.kstarbound.client.StarboundClient import ru.dbotthepony.kstarbound.client.gl.vertex.GeometryType import ru.dbotthepony.kstarbound.json.consumeNull import ru.dbotthepony.kstarbound.json.listAdapter -import ru.dbotthepony.kvector.api.IStruct2d -import ru.dbotthepony.kvector.arrays.Matrix3f -import ru.dbotthepony.kvector.util2d.AABB -import ru.dbotthepony.kvector.util2d.intersectSegments -import ru.dbotthepony.kvector.vector.RGBAColor -import ru.dbotthepony.kvector.vector.Vector2d import kotlin.math.absoluteValue import kotlin.math.cos import kotlin.math.sin