diff --git a/build.gradle.kts b/build.gradle.kts index 661757b56..080cd3997 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -59,7 +59,7 @@ repositories { buildscript { dependencies { - classpath("de.bixilon", "kutil", "1.18.3") + classpath("de.bixilon", "kutil", "1.19.1") } } diff --git a/gradle.properties b/gradle.properties index d810798b2..973b09eec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,4 @@ lwjgl.version=3.3.2-SNAPSHOT ikonli.version=12.3.1 netty.version=4.1.86.Final jackson.version=2.14.1 -kutil.version=1.18.3 +kutil.version=1.19.1 diff --git a/src/main/java/de/bixilon/minosoft/config/profile/delegate/BackingDelegate.kt b/src/main/java/de/bixilon/minosoft/config/profile/delegate/BackingDelegate.kt deleted file mode 100644 index 752fcaf7e..000000000 --- a/src/main/java/de/bixilon/minosoft/config/profile/delegate/BackingDelegate.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.config.profile.delegate - -import de.bixilon.kutil.observer.DataObserver -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty - -@Deprecated("Kutil") -class BackingDelegate( - private val get: () -> V, - private val set: (V) -> Unit, -) : DataObserver(get()), ReadWriteProperty { - - override fun getValue(thisRef: Any, property: KProperty<*>): V { - return get() - } - - override fun setValue(thisRef: Any, property: KProperty<*>, value: V) { - set(value) - super.setValue(thisRef, property, value) - } -} diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt index d48e95aea..1a9f0264d 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/account/AccountProfile.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -17,10 +17,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.delegates.BackingDelegate import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.random.RandomStringUtil.randomString import de.bixilon.minosoft.config.profile.ProfileManager -import de.bixilon.minosoft.config.profile.delegate.BackingDelegate import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate import de.bixilon.minosoft.config.profile.delegate.types.NullableStringDelegate import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/entries/ErosServer.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/entries/ErosServer.kt index b894d8a07..c95fda973 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/entries/ErosServer.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/eros/server/entries/ErosServer.kt @@ -18,9 +18,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.delegates.BackingDelegate import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.minosoft.assets.util.FileAssetsUtil -import de.bixilon.minosoft.config.profile.delegate.BackingDelegate import de.bixilon.minosoft.config.profile.delegate.SimpleDelegate import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate import de.bixilon.minosoft.config.profile.delegate.types.NullableStringDelegate diff --git a/src/main/java/de/bixilon/minosoft/data/registries/GenericUtil.kt b/src/main/java/de/bixilon/minosoft/data/registries/GenericUtil.kt deleted file mode 100644 index c6530c2e8..000000000 --- a/src/main/java/de/bixilon/minosoft/data/registries/GenericUtil.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.data.registries - -import de.bixilon.kutil.cast.CastUtil.unsafeCast -import de.bixilon.kutil.unsafe.UnsafeUtil -import java.lang.reflect.ParameterizedType -import java.lang.reflect.Type - -@Deprecated("Kutil") -object GenericUtil { - private val parameterizedClass = Class.forName("sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl") - private val rawTypeField = parameterizedClass.getDeclaredField("rawType") - private val offset = UnsafeUtil.UNSAFE.objectFieldOffset(rawTypeField) - - fun getClassOfFactory(type: Type): Class<*> { - val actualType = type.unsafeCast().actualTypeArguments.first() - return if (actualType is Class<*>) { - actualType - } else if (actualType::class.java == parameterizedClass) { - UnsafeUtil.UNSAFE.getObject(actualType, offset).unsafeCast>() - } else { - TODO() - } - } -} diff --git a/src/main/java/de/bixilon/minosoft/data/registries/factory/clazz/DefaultClassFactory.kt b/src/main/java/de/bixilon/minosoft/data/registries/factory/clazz/DefaultClassFactory.kt index 94ed3c3d2..14fa4c942 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/factory/clazz/DefaultClassFactory.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/factory/clazz/DefaultClassFactory.kt @@ -13,7 +13,7 @@ package de.bixilon.minosoft.data.registries.factory.clazz -import de.bixilon.minosoft.data.registries.GenericUtil +import de.bixilon.kutil.reflection.generic.GenericUtil import java.lang.reflect.ParameterizedType import kotlin.reflect.jvm.javaType @@ -25,7 +25,7 @@ open class DefaultClassFactory>(vararg factories: T) { for (factory in factories) { - val className = GenericUtil.getClassOfFactory(factory::class.supertypes[0].javaType as ParameterizedType).simpleName + val className = GenericUtil.getGeneric(factory::class.supertypes[0].javaType as ParameterizedType).simpleName ret[className] = factory if (factory is MultiClassFactory<*>) { for (name in factory.ALIASES) { diff --git a/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/AbstractRegistry.kt b/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/AbstractRegistry.kt index d7076bf8e..c2177cdaa 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/AbstractRegistry.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/AbstractRegistry.kt @@ -14,10 +14,10 @@ package de.bixilon.minosoft.data.registries.registries.registry import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.collections.primitive.Clearable import de.bixilon.kutil.json.JsonObject import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.data.registries.registries.Registries -import de.bixilon.minosoft.util.collections.Clearable import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap interface AbstractRegistry : Iterable, Clearable, Parentable> { diff --git a/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/EnumRegistry.kt b/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/EnumRegistry.kt index 47017ba87..ace15c690 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/EnumRegistry.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/EnumRegistry.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -14,10 +14,10 @@ package de.bixilon.minosoft.data.registries.registries.registry import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.collections.primitive.Clearable import de.bixilon.kutil.enums.ValuesEnum import de.bixilon.kutil.primitive.IntUtil.toInt import de.bixilon.minosoft.datafixer.enumeration.EnumFixer -import de.bixilon.minosoft.util.collections.Clearable import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap diff --git a/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/FakeEnumRegistry.kt b/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/FakeEnumRegistry.kt index bb2d919dc..3dac73736 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/FakeEnumRegistry.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/registries/registry/FakeEnumRegistry.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,11 +13,11 @@ package de.bixilon.minosoft.data.registries.registries.registry +import de.bixilon.kutil.collections.primitive.Clearable import de.bixilon.kutil.json.JsonObject import de.bixilon.kutil.primitive.IntUtil.toInt import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.registries.registries.registry.codec.IdCodec -import de.bixilon.minosoft.util.collections.Clearable import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt index 5aaa8d6b1..858e39b76 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/ServerListController.kt @@ -16,7 +16,6 @@ package de.bixilon.minosoft.gui.eros.main.play.server import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedSet import de.bixilon.kutil.concurrent.pool.DefaultThreadPool.async import de.bixilon.kutil.latch.CountUpAndDownLatch -import de.bixilon.kutil.observer.ObservedReference import de.bixilon.kutil.primitive.BooleanUtil.decide import de.bixilon.kutil.primitive.IntUtil.thousands import de.bixilon.kutil.unit.UnitFormatter.formatNanos @@ -63,7 +62,7 @@ import javafx.scene.input.KeyCode import javafx.scene.layout.Pane -class ServerListController : EmbeddedJavaFXController(), Refreshable, ObservedReference { +class ServerListController : EmbeddedJavaFXController(), Refreshable { @FXML private lateinit var hideOfflineFX: CheckBox @FXML private lateinit var hideFullFX: CheckBox @FXML private lateinit var hideEmptyFX: CheckBox @@ -163,7 +162,7 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable, Obse JavaFXUtil.runLater { updateServer(server, true) } } - connection.register(JavaFXEventListener.of { event -> + connection.events.register(JavaFXEventListener.of { event -> KickDialog( title = "minosoft:connection.kick.title".toResourceLocation(), header = "minosoft:connection.kick.header".toResourceLocation(), @@ -171,7 +170,7 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable, Obse reason = event.reason, ).show() }) - connection.register(JavaFXEventListener.of { event -> + connection.events.register(JavaFXEventListener.of { event -> KickDialog( title = "minosoft:connection.login_kick.title".toResourceLocation(), header = "minosoft:connection.login_kick.header".toResourceLocation(), @@ -410,13 +409,6 @@ class ServerListController : EmbeddedJavaFXController(), Refreshable, Obse serverType!!.refresh(serverListViewFX.items) } - override fun isValid(value: Any): Boolean { - if (value is ServerCard) { - return value === serverListViewFX.selectionModel.selectedItem - } - return value === this - } - companion object { val LAYOUT = "minosoft:eros/main/play/server/server_list.fxml".toResourceLocation() diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCardController.kt b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCardController.kt index 20a09d021..3fdc89b81 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCardController.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/main/play/server/card/ServerCardController.kt @@ -14,7 +14,6 @@ package de.bixilon.minosoft.gui.eros.main.play.server.card import de.bixilon.kutil.concurrent.pool.DefaultThreadPool -import de.bixilon.kutil.observer.ObservedReference import de.bixilon.kutil.primitive.IntUtil.thousands import de.bixilon.kutil.unit.UnitFormatter.formatNanos import de.bixilon.minosoft.Minosoft @@ -28,7 +27,6 @@ import de.bixilon.minosoft.gui.eros.main.play.server.card.FaviconManager.saveFav import de.bixilon.minosoft.gui.eros.util.JavaFXUtil import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text -import de.bixilon.minosoft.protocol.network.connection.status.StatusConnection import de.bixilon.minosoft.util.KUtil.text import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.PixelImageView @@ -39,7 +37,7 @@ import javafx.scene.image.Image import javafx.scene.text.TextFlow import java.io.ByteArrayInputStream -class ServerCardController : AbstractCardController(), ObservedReference { +class ServerCardController : AbstractCardController() { @FXML private lateinit var faviconFX: PixelImageView @FXML private lateinit var serverNameFX: TextFlow @FXML private lateinit var motdFX: TextFlow @@ -136,10 +134,6 @@ class ServerCardController : AbstractCardController(), ObservedRefer } } - override fun isValid(value: StatusConnection): Boolean { - return item.ping === value - } - companion object : CardFactory { override val LAYOUT: ResourceLocation = "minosoft:eros/main/play/server/server_card.fxml".toResourceLocation() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderLoader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderLoader.kt index 90e826335..889771f3d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderLoader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderLoader.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -14,6 +14,7 @@ package de.bixilon.minosoft.gui.rendering import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll import de.bixilon.kutil.latch.CountUpAndDownLatch import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.primitive.BooleanUtil.decide @@ -25,7 +26,6 @@ import de.bixilon.minosoft.gui.rendering.font.FontLoader import de.bixilon.minosoft.gui.rendering.input.key.DefaultKeyCombinations import de.bixilon.minosoft.gui.rendering.renderer.renderer.DefaultRenderer import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates -import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.Stopwatch import de.bixilon.minosoft.util.delegate.RenderingDelegate.observeRendering import de.bixilon.minosoft.util.logging.Log @@ -55,7 +55,7 @@ object RenderLoader { registerRenderer() window.init(connection.profiles.rendering) - KUtil.ignoreAll { window.setDefaultIcon(connection.assetsManager) } + ignoreAll { window.setDefaultIcon(connection.assetsManager) } camera.init() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt index 8bcce8e1c..6b75ecd3b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/font/FontLoader.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,7 @@ package de.bixilon.minosoft.gui.rendering.font +import de.bixilon.kutil.array.ArrayUtil.trim import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker import de.bixilon.kutil.latch.CountUpAndDownLatch import de.bixilon.minosoft.assets.util.FileUtil.readJsonObject @@ -20,7 +21,6 @@ import de.bixilon.minosoft.data.registries.factory.DefaultFactory import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.font.provider.* import de.bixilon.minosoft.util.KUtil.toResourceLocation -import de.bixilon.minosoft.util.KUtil.trim import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt index 12d8fc2dc..721b33dda 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextElement.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -38,7 +38,7 @@ import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.system.window.CursorShapes import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY import de.bixilon.minosoft.gui.rendering.util.vec.vec4.Vec4iUtil.offset -import de.bixilon.minosoft.util.KUtil.length +import de.bixilon.minosoft.util.KUtil.charCount open class TextElement( guiRenderer: GUIRenderer, @@ -50,7 +50,7 @@ open class TextElement( parent: Element? = null, scale: Float = 1.0f, shadow: Boolean = true, -) : Element(guiRenderer, text.length * 6 * GUIMesh.GUIMeshStruct.FLOATS_PER_VERTEX), Labeled { +) : Element(guiRenderer, text.charCount * 6 * GUIMesh.GUIMeshStruct.FLOATS_PER_VERTEX), Labeled { private var activeElement: TextComponent? = null lateinit var renderInfo: TextRenderInfo private set diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt index 6427f2b23..6b30eb028 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMesh.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.gui.mesh import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec2.Vec2t +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer @@ -23,7 +24,6 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderIdentifiable import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.orthoTimes -import de.bixilon.minosoft.util.collections.floats.AbstractFloatList class GUIMesh( context: RenderContext, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt index 5431f5e11..5d8018fad 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/mesh/GUIMeshCache.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -17,11 +17,11 @@ import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec2.Vec2t +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList +import de.bixilon.kutil.collections.primitive.floats.HeapArrayFloatList import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.system.base.texture.ShaderIdentifiable import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY -import de.bixilon.minosoft.util.collections.floats.AbstractFloatList -import de.bixilon.minosoft.util.collections.floats.HeapArrayFloatList class GUIMeshCache( var matrix: Mat4, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt index 9260eba35..d87e7bdaa 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleMesh.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.particle import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.Vec3d +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.MeshUtil.buffer @@ -23,7 +24,6 @@ import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveType import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.AbstractTexture import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct -import de.bixilon.minosoft.util.collections.floats.AbstractFloatList class ParticleMesh(context: RenderContext, data: AbstractFloatList) : Mesh(context, ParticleMeshStruct, PrimitiveTypes.POINT, -1, clearOnLoad = false, data = data) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt index 205ede70d..b55ab2e4e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/RenderSystem.kt @@ -14,6 +14,7 @@ package de.bixilon.minosoft.gui.rendering.system.base import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.data.text.formatting.color.Colors import de.bixilon.minosoft.data.text.formatting.color.RGBColor @@ -27,7 +28,6 @@ import de.bixilon.minosoft.gui.rendering.system.base.shader.NativeShader import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager import de.bixilon.minosoft.gui.rendering.util.mesh.MeshStruct import de.bixilon.minosoft.util.KUtil.toResourceLocation -import de.bixilon.minosoft.util.collections.floats.AbstractFloatList import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList import java.nio.ByteBuffer import java.nio.FloatBuffer diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/tint/FoliageTintCalculator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/tint/FoliageTintCalculator.kt index 8a07aabee..3e6843d82 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/tint/FoliageTintCalculator.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/tint/FoliageTintCalculator.kt @@ -13,13 +13,13 @@ package de.bixilon.minosoft.gui.rendering.tint +import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll import de.bixilon.minosoft.assets.AssetsManager import de.bixilon.minosoft.assets.util.FileUtil.readRGBArray import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.registries.biomes.Biome import de.bixilon.minosoft.data.registries.blocks.BlockState import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture -import de.bixilon.minosoft.util.KUtil.ignoreAll import de.bixilon.minosoft.util.KUtil.toResourceLocation private const val FALLBACK_COLOR = 0x48B518 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/tint/GrassTintCalculator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/tint/GrassTintCalculator.kt index 5df5641b8..1ed25ec93 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/tint/GrassTintCalculator.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/tint/GrassTintCalculator.kt @@ -13,6 +13,7 @@ package de.bixilon.minosoft.gui.rendering.tint +import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll import de.bixilon.minosoft.assets.AssetsManager import de.bixilon.minosoft.assets.util.FileUtil.readRGBArray import de.bixilon.minosoft.data.registries.biomes.Biome @@ -21,7 +22,6 @@ import de.bixilon.minosoft.data.registries.blocks.BlockState import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks import de.bixilon.minosoft.data.text.formatting.color.Colors import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture -import de.bixilon.minosoft.util.KUtil.ignoreAll import de.bixilon.minosoft.util.KUtil.toResourceLocation class GrassTintCalculator : TintProvider { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt index 99432eb82..fe6e3118c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/util/mesh/Mesh.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -16,10 +16,10 @@ package de.bixilon.minosoft.gui.rendering.util.mesh import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.FloatVertexBuffer import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes -import de.bixilon.minosoft.util.collections.floats.AbstractFloatList import de.bixilon.minosoft.util.collections.floats.DirectArrayFloatList import de.bixilon.minosoft.util.collections.floats.FloatListUtil diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/NamedThreadFactory.kt b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/NamedThreadFactory.kt deleted file mode 100644 index 84059da68..000000000 --- a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/NamedThreadFactory.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.protocol.network.network.client.netty - -import java.util.concurrent.ThreadFactory -import java.util.concurrent.atomic.AtomicInteger - -@Deprecated("Kutil") -class NamedThreadFactory( - val format: String, -) : ThreadFactory { - var count = AtomicInteger(0) - - override fun newThread(runnable: Runnable): Thread { - return Thread(runnable, format.format(count.incrementAndGet())) - } -} diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/EpollNatives.kt b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/EpollNatives.kt index 1544cd757..5b17f5f25 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/EpollNatives.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/EpollNatives.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,7 +13,7 @@ package de.bixilon.minosoft.protocol.network.network.client.netty.natives -import de.bixilon.minosoft.protocol.network.network.client.netty.NamedThreadFactory +import de.bixilon.kutil.concurrent.thread.NamedThreadFactory import io.netty.channel.Channel import io.netty.channel.epoll.Epoll import io.netty.channel.epoll.EpollEventLoopGroup diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/NioNatives.kt b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/NioNatives.kt index 67741b79e..b5eec365c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/NioNatives.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/natives/NioNatives.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,7 +13,7 @@ package de.bixilon.minosoft.protocol.network.network.client.netty.natives -import de.bixilon.minosoft.protocol.network.network.client.netty.NamedThreadFactory +import de.bixilon.kutil.concurrent.thread.NamedThreadFactory import io.netty.channel.Channel import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.socket.nio.NioSocketChannel diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/ByteBufferUnderflowException.kt b/src/main/java/de/bixilon/minosoft/protocol/protocol/ByteBufferUnderflowException.kt deleted file mode 100644 index 462df79ff..000000000 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/ByteBufferUnderflowException.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.protocol.protocol - -import java.nio.BufferUnderflowException - -@Deprecated("Kutil") -class ByteBufferUnderflowException( - val pointer: Int, - val size: Int, -) : BufferUnderflowException() { - override val message: String = "$pointer >= $size" -} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.kt b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.kt index 6a3bca942..8134893d1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.kt @@ -18,6 +18,7 @@ import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.kotlinglm.vec3.Vec3i +import de.bixilon.kutil.buffer.bytes.`in`.ByteBufferUnderflowException import de.bixilon.kutil.compression.zlib.GzipUtil.decompress import de.bixilon.kutil.uuid.UUIDUtil.toUUID import de.bixilon.minosoft.data.direction.Directions diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.kt b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.kt index 603651b53..bc301ed09 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.kt @@ -15,11 +15,11 @@ package de.bixilon.minosoft.protocol.protocol import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.kotlinglm.vec3.Vec3i +import de.bixilon.kutil.collections.primitive.bytes.HeapArrayByteList import de.bixilon.minosoft.data.registries.identified.Namespaces import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.protocol.ProtocolUtil.encodeNetwork -import de.bixilon.minosoft.util.collections.bytes.HeapArrayByteList import de.bixilon.minosoft.util.json.Jackson import de.bixilon.minosoft.util.nbt.tag.NBTTagTypes import de.bixilon.minosoft.util.nbt.tag.NBTUtil.nbtType diff --git a/src/main/java/de/bixilon/minosoft/util/KUtil.kt b/src/main/java/de/bixilon/minosoft/util/KUtil.kt index 54b3981e5..1ba9bea05 100644 --- a/src/main/java/de/bixilon/minosoft/util/KUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/KUtil.kt @@ -26,6 +26,7 @@ import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedSet import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.concurrent.time.TimeWorker import de.bixilon.kutil.primitive.BooleanUtil.decide +import de.bixilon.kutil.primitive.IntUtil.checkInt import de.bixilon.kutil.reflection.ReflectionUtil.forceInit import de.bixilon.kutil.reflection.ReflectionUtil.realName import de.bixilon.kutil.shutdown.ShutdownManager @@ -54,9 +55,6 @@ import org.kamranzafar.jtar.TarHeader import java.security.SecureRandom import java.util.* import javax.net.ssl.SSLContext -import kotlin.contracts.ExperimentalContracts -import kotlin.contracts.InvocationKind -import kotlin.contracts.contract object KUtil { @@ -220,18 +218,6 @@ object KUtil { return null } - @Deprecated("Kutil") - private inline fun String.checkInt(): Int? { - var first = true - for (point in codePoints()) { - if (point < '0'.code || point > '9'.code || (first && point == '-'.code)) { - return null - } - first = false - } - return this.toInt() - } - fun Any?.autoType(): Any? { if (this == null) { return null @@ -311,7 +297,7 @@ object KUtil { } } - val Any.length: Int + val Any.charCount: Int get() { if (this is ChatComponent) return this.length if (this is CharSequence) return this.length @@ -322,29 +308,4 @@ object KUtil { val random = SecureRandom() return UUID(random.nextLong(), random.nextLong()) } - - @Deprecated("Kutil") - @OptIn(ExperimentalContracts::class) - inline fun ignoreAll(executor: () -> T): T? { - contract { - callsInPlace(executor, InvocationKind.EXACTLY_ONCE) - } - try { - return executor() - } catch (error: Throwable) { - error.printStackTrace() - } - return null - } - - inline fun Array.trim(): Array { - val list: MutableList = mutableListOf() - for (entry in this) { - if (entry == null) { - continue - } - list += entry - } - return list.toTypedArray() - } } diff --git a/src/main/java/de/bixilon/minosoft/util/RegistriesUtil.kt b/src/main/java/de/bixilon/minosoft/util/RegistriesUtil.kt index 03bfe6768..f1151fc92 100644 --- a/src/main/java/de/bixilon/minosoft/util/RegistriesUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/RegistriesUtil.kt @@ -14,13 +14,13 @@ package de.bixilon.minosoft.util import de.bixilon.kutil.cast.CastUtil.unsafeCast +import de.bixilon.kutil.collections.primitive.Clearable import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.latch.CountUpAndDownLatch -import de.bixilon.minosoft.data.registries.GenericUtil +import de.bixilon.kutil.reflection.generic.GenericUtil import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.registries.registries.registry.Parentable import de.bixilon.minosoft.data.registries.registries.registry.Registry -import de.bixilon.minosoft.util.collections.Clearable import java.lang.reflect.Field object RegistriesUtil { @@ -57,7 +57,7 @@ object RegistriesUtil { } } - types[GenericUtil.getClassOfFactory(clazz)] = field + types[GenericUtil.getGeneric(clazz)] = field } diff --git a/src/main/java/de/bixilon/minosoft/util/collections/AbstractPrimitiveList.kt b/src/main/java/de/bixilon/minosoft/util/collections/AbstractPrimitiveList.kt deleted file mode 100644 index 99f34884e..000000000 --- a/src/main/java/de/bixilon/minosoft/util/collections/AbstractPrimitiveList.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.util.collections - -@Deprecated("Kutil") -abstract class AbstractPrimitiveList : Clearable { - var finished: Boolean = false - protected set - abstract val limit: Int - abstract val size: Int - abstract val isEmpty: Boolean - - abstract fun ensureSize(needed: Int) - abstract fun add(value: T) - - abstract fun finish() - - - protected fun checkFinished() { - if (finished) { - throw IllegalStateException("List is already finished!") - } - } -} diff --git a/src/main/java/de/bixilon/minosoft/util/collections/Clearable.kt b/src/main/java/de/bixilon/minosoft/util/collections/Clearable.kt deleted file mode 100644 index cac3ee5e7..000000000 --- a/src/main/java/de/bixilon/minosoft/util/collections/Clearable.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.util.collections - -@Deprecated("Kutil") -interface Clearable { - - fun clear() -} diff --git a/src/main/java/de/bixilon/minosoft/util/collections/bytes/AbstractByteList.kt b/src/main/java/de/bixilon/minosoft/util/collections/bytes/AbstractByteList.kt deleted file mode 100644 index ac0fa32bd..000000000 --- a/src/main/java/de/bixilon/minosoft/util/collections/bytes/AbstractByteList.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.util.collections.bytes - -import de.bixilon.minosoft.util.collections.AbstractPrimitiveList - -@Deprecated("Kutil") -abstract class AbstractByteList : AbstractPrimitiveList() { - - abstract fun addAll(bytes: ByteArray) - abstract fun addAll(byteList: AbstractByteList) - - abstract fun toArray(): ByteArray -} diff --git a/src/main/java/de/bixilon/minosoft/util/collections/bytes/HeapArrayByteList.kt b/src/main/java/de/bixilon/minosoft/util/collections/bytes/HeapArrayByteList.kt deleted file mode 100644 index 12ecd0ce4..000000000 --- a/src/main/java/de/bixilon/minosoft/util/collections/bytes/HeapArrayByteList.kt +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ -package de.bixilon.minosoft.util.collections.bytes - -@Deprecated("Kutil") -class HeapArrayByteList( - initialSize: Int = DEFAULT_INITIAL_SIZE, -) : AbstractByteList() { - private var data: ByteArray = ByteArray(initialSize) - override val limit: Int - get() = data.size - override var size = 0 - override val isEmpty: Boolean - get() = size == 0 - - private val nextGrowStep = when { - initialSize <= 0 -> DEFAULT_INITIAL_SIZE - initialSize <= 50 -> 50 - else -> initialSize - } - - private var output: ByteArray = ByteArray(0) - private var outputUpToDate = false - - private fun checkFinalized() { - if (finished) { - throw IllegalStateException("ByteArrayList is already finalized!") - } - } - - override fun clear() { - checkFinalized() - size = 0 - outputUpToDate = false - output = ByteArray(0) - } - - override fun ensureSize(needed: Int) { - checkFinalized() - if (limit - size >= needed) { - return - } - var newSize = data.size - while (newSize - size < needed) { - newSize += nextGrowStep - } - grow(newSize) - } - - private fun grow(size: Int) { - val oldData = data - data = ByteArray(size) - System.arraycopy(oldData, 0, data, 0, oldData.size) - } - - override fun add(value: Byte) { - ensureSize(1) - data[size++] = value - if (outputUpToDate) { - outputUpToDate = false - } - } - - override fun addAll(bytes: ByteArray) { - ensureSize(bytes.size) - System.arraycopy(bytes, 0, data, size, bytes.size) - size += bytes.size - if (outputUpToDate) { - outputUpToDate = false - } - } - - override fun addAll(byteList: AbstractByteList) { - ensureSize(byteList.size) - val source: ByteArray = if (byteList is HeapArrayByteList) { - if (byteList.finished) { - byteList.output - } else { - byteList.data - } - } else { - byteList.toArray() - } - System.arraycopy(source, 0, data, size, byteList.size) - size += byteList.size - - if (outputUpToDate) { - outputUpToDate = false - } - } - - private fun checkOutputArray() { - if (outputUpToDate) { - return - } - output = ByteArray(size) - System.arraycopy(data, 0, output, 0, size) - outputUpToDate = true - } - - override fun toArray(): ByteArray { - checkOutputArray() - return output - } - - override fun finish() { - finished = true - checkOutputArray() - data = ByteArray(0) - } - - - private companion object { - private const val DEFAULT_INITIAL_SIZE = 1000 - } -} diff --git a/src/main/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatList.kt b/src/main/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatList.kt deleted file mode 100644 index b8b64d770..000000000 --- a/src/main/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatList.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.util.collections.floats - -import de.bixilon.minosoft.util.collections.AbstractPrimitiveList -import java.nio.FloatBuffer - -@Deprecated("Kutil") -abstract class AbstractFloatList : AbstractPrimitiveList() { - - abstract fun add(array: FloatArray) - operator fun plusAssign(array: FloatArray) = add(array) - abstract fun add(floatList: AbstractFloatList) - operator fun plusAssign(floatList: AbstractFloatList) = add(floatList) - abstract fun add(buffer: FloatBuffer) - operator fun plusAssign(buffer: FloatBuffer) = add(buffer) - - abstract fun toArray(): FloatArray -} diff --git a/src/main/java/de/bixilon/minosoft/util/collections/floats/BufferedArrayFloatList.kt b/src/main/java/de/bixilon/minosoft/util/collections/floats/BufferedArrayFloatList.kt index c14272a87..5689e7fa8 100644 --- a/src/main/java/de/bixilon/minosoft/util/collections/floats/BufferedArrayFloatList.kt +++ b/src/main/java/de/bixilon/minosoft/util/collections/floats/BufferedArrayFloatList.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,7 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.minosoft.util.collections.floats.FloatListUtil.copy import de.bixilon.minosoft.util.collections.floats.FloatListUtil.finish import org.lwjgl.system.MemoryUtil.memAllocFloat diff --git a/src/main/java/de/bixilon/minosoft/util/collections/floats/FloatListUtil.kt b/src/main/java/de/bixilon/minosoft/util/collections/floats/FloatListUtil.kt index 58540954d..75c965c2c 100644 --- a/src/main/java/de/bixilon/minosoft/util/collections/floats/FloatListUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/collections/floats/FloatListUtil.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,7 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.kutil.exception.ExceptionUtil import org.lwjgl.system.MemoryUtil.memAllocFloat import org.lwjgl.system.MemoryUtil.memFree diff --git a/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt b/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt index 08d7e6170..6cf236738 100644 --- a/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt +++ b/src/main/java/de/bixilon/minosoft/util/collections/floats/FragmentedArrayFloatList.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,7 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import de.bixilon.kutil.exception.Broken import de.bixilon.minosoft.util.collections.floats.FloatListUtil.copy import org.lwjgl.system.MemoryUtil.memAllocFloat diff --git a/src/main/java/de/bixilon/minosoft/util/collections/floats/HeapArrayFloatList.kt b/src/main/java/de/bixilon/minosoft/util/collections/floats/HeapArrayFloatList.kt deleted file mode 100644 index 0bbfc50f9..000000000 --- a/src/main/java/de/bixilon/minosoft/util/collections/floats/HeapArrayFloatList.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ -package de.bixilon.minosoft.util.collections.floats - -import java.nio.FloatBuffer - -@Deprecated("Kutil") -class HeapArrayFloatList( - initialSize: Int = FloatListUtil.DEFAULT_INITIAL_SIZE, -) : AbstractFloatList() { - private var data: FloatArray = FloatArray(initialSize) - override val limit: Int - get() = data.size - override var size = 0 - override val isEmpty: Boolean - get() = size == 0 - - private val nextGrowStep = when { - initialSize <= 0 -> FloatListUtil.DEFAULT_INITIAL_SIZE - initialSize <= 50 -> 50 - else -> initialSize - } - - private var output: FloatArray = FloatArray(0) - private var outputUpToDate = false - - private fun checkFinalized() { - if (finished) { - throw IllegalStateException("ArrayFloatList is already finalized!") - } - } - - override fun clear() { - checkFinalized() - size = 0 - invalidateOutput() - output = FloatArray(0) - } - - override fun ensureSize(needed: Int) { - checkFinalized() - if (limit - size >= needed) { - return - } - var newSize = data.size - while (newSize - size < needed) { - newSize += nextGrowStep - } - grow(newSize) - } - - private fun grow(size: Int) { - val oldData = data - data = FloatArray(size) - System.arraycopy(oldData, 0, data, 0, oldData.size) - } - - override fun add(value: Float) { - ensureSize(1) - data[size++] = value - invalidateOutput() - } - - override fun add(array: FloatArray) { - ensureSize(array.size) - System.arraycopy(array, 0, data, size, array.size) - size += array.size - invalidateOutput() - } - - override fun add(buffer: FloatBuffer) { - val position = buffer.position() - ensureSize(position) - for (i in 0 until position) { - data[size + i] = buffer.get(i) - } - size += position - invalidateOutput() - } - - override fun add(floatList: AbstractFloatList) { - ensureSize(floatList.size) - val source: FloatArray = if (floatList is HeapArrayFloatList) { - if (floatList.finished) { - floatList.output - } else { - floatList.data - } - } else { - floatList.toArray() - } - System.arraycopy(source, 0, data, size, floatList.size) - size += floatList.size - invalidateOutput() - } - - private fun checkOutputArray() { - if (outputUpToDate) { - return - } - output = FloatArray(size) - System.arraycopy(data, 0, output, 0, size) - outputUpToDate = true - } - - override fun toArray(): FloatArray { - checkOutputArray() - return output - } - - override fun finish() { - finished = true - checkOutputArray() - data = FloatArray(0) - } - - private fun invalidateOutput() { - if (outputUpToDate) { - outputUpToDate = false - } - } -} diff --git a/src/test/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatListTest.kt b/src/test/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatListTest.kt index ff72db6c8..49becc043 100644 --- a/src/test/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatListTest.kt +++ b/src/test/java/de/bixilon/minosoft/util/collections/floats/AbstractFloatListTest.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,8 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList +import de.bixilon.kutil.collections.primitive.floats.HeapArrayFloatList import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import java.nio.FloatBuffer diff --git a/src/test/java/de/bixilon/minosoft/util/collections/floats/BufferedFloatListTest.kt b/src/test/java/de/bixilon/minosoft/util/collections/floats/BufferedFloatListTest.kt index 0635cf107..7286ea91d 100644 --- a/src/test/java/de/bixilon/minosoft/util/collections/floats/BufferedFloatListTest.kt +++ b/src/test/java/de/bixilon/minosoft/util/collections/floats/BufferedFloatListTest.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,8 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList + class BufferedFloatListTest : DirectFloatListTest() { override fun create(initialSize: Int): AbstractFloatList { diff --git a/src/test/java/de/bixilon/minosoft/util/collections/floats/FragmentedFloatListTest.kt b/src/test/java/de/bixilon/minosoft/util/collections/floats/FragmentedFloatListTest.kt index cf7953bef..7f8b314ce 100644 --- a/src/test/java/de/bixilon/minosoft/util/collections/floats/FragmentedFloatListTest.kt +++ b/src/test/java/de/bixilon/minosoft/util/collections/floats/FragmentedFloatListTest.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,7 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList import org.junit.jupiter.api.Test import kotlin.test.assertEquals diff --git a/src/test/java/de/bixilon/minosoft/util/collections/floats/HeapFloatListTest.kt b/src/test/java/de/bixilon/minosoft/util/collections/floats/HeapFloatListTest.kt index 596ccdc28..dfd161b84 100644 --- a/src/test/java/de/bixilon/minosoft/util/collections/floats/HeapFloatListTest.kt +++ b/src/test/java/de/bixilon/minosoft/util/collections/floats/HeapFloatListTest.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -13,6 +13,9 @@ package de.bixilon.minosoft.util.collections.floats +import de.bixilon.kutil.collections.primitive.floats.AbstractFloatList +import de.bixilon.kutil.collections.primitive.floats.HeapArrayFloatList + class HeapFloatListTest : AbstractFloatListTest() { override fun create(initialSize: Int): AbstractFloatList {