From b2480980e9c327a19bc8114641f34231fdaf3c10 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Mon, 3 Feb 2025 22:12:37 +0100 Subject: [PATCH] port to kutil 1.27 This update has some qol updates and a lot of juicy performance updates. Locking now uses javas integrated ReentrantLock which is 10 times faster than the synchronized lock (benchmarked it). Due to minosofts async nature, a lot of locking is needed (especially for time critical parts like in rendering). Locking is already reduced to a minimum, but it should still give a small performance boost. (more ports in there) --- gradle.properties | 4 ++-- .../minosoft/data/world/chunk/LightTestingUtil.kt | 6 +++--- .../minosoft/config/profile/test/TestProfile.kt | 5 ++--- .../de/bixilon/minosoft/data/world/WorldTestUtil.kt | 6 +++--- .../minosoft/data/world/chunk/LightTestingUtil.kt | 6 +++--- .../bixilon/minosoft/config/profile/ProfileLock.kt | 6 +++--- .../minosoft/config/profile/profiles/Profile.kt | 6 +++--- .../config/profile/storage/ProfileIOManager.kt | 6 +++--- .../config/profile/storage/StorageProfileManager.kt | 6 +++--- .../accounts/types/microsoft/MicrosoftAccount.kt | 6 +++--- .../de/bixilon/minosoft/data/container/Container.kt | 6 +++--- .../minosoft/data/container/stack/ItemStack.kt | 8 ++++---- .../minosoft/data/entities/data/EntityData.kt | 8 ++++---- .../entities/player/local/SignatureKeyManagement.kt | 6 +++--- .../java/de/bixilon/minosoft/data/world/World.kt | 7 +++---- .../bixilon/minosoft/data/world/chunk/chunk/Chunk.kt | 6 +++--- .../minosoft/data/world/entities/WorldEntities.kt | 6 +++--- .../de/bixilon/minosoft/gui/eros/util/StageList.kt | 6 +++--- .../minosoft/gui/rendering/RenderConstants.kt | 5 +++-- .../minosoft/gui/rendering/camera/MatrixHandler.kt | 7 ++++--- .../gui/rendering/camera/shaking/CameraShaking.kt | 9 +++++---- .../minosoft/gui/rendering/chunk/ChunkRenderer.kt | 6 +++--- .../minosoft/gui/rendering/chunk/LoadedMeshes.kt | 6 +++--- .../gui/rendering/chunk/queue/CulledQueue.kt | 6 +++--- .../chunk/queue/loading/MeshLoadingQueue.kt | 6 +++--- .../chunk/queue/loading/MeshUnloadingQueue.kt | 6 +++--- .../chunk/queue/meshing/ChunkMeshingQueue.kt | 6 +++--- .../queue/meshing/tasks/MeshPrepareTaskManager.kt | 6 +++--- .../gui/rendering/entities/EntityRendererManager.kt | 6 +++--- .../entities/visibility/VisibilityManager.kt | 6 +++--- .../overlay/overlays/simple/PowderSnowOverlay.kt | 7 ++++--- .../minosoft/gui/rendering/gui/gui/GUIManager.kt | 6 +++--- .../minosoft/gui/rendering/particle/ParticleList.kt | 6 +++--- .../minosoft/gui/rendering/particle/ParticleQueue.kt | 6 +++--- .../rendering/skeletal/instance/AnimationManager.kt | 6 +++--- .../minosoft/gui/rendering/sound/AudioPlayer.kt | 5 +++-- .../gui/rendering/stats/AbstractRenderStats.kt | 8 ++++---- .../gui/rendering/stats/ExperimentalRenderStats.kt | 12 +++++------- .../minosoft/gui/rendering/stats/RenderStats.kt | 9 +++++---- .../system/base/texture/array/StaticTextureArray.kt | 6 +++--- .../base/texture/array/font/FontTextureArray.kt | 6 +++--- .../system/base/texture/dynamic/DynamicTexture.kt | 6 +++--- .../base/texture/dynamic/DynamicTextureArray.kt | 6 +++--- .../rendering/system/opengl/OpenGLRenderSystem.kt | 5 ++--- .../minosoft/modding/event/master/EventMaster.kt | 8 ++++---- .../minosoft/protocol/network/NetworkConnection.kt | 6 +++--- .../netty/pipeline/compression/PacketInflater.kt | 4 ++-- .../client/netty/pipeline/encoding/PacketDecoder.kt | 4 ++-- .../network/session/play/tick/SessionTicker.kt | 6 +++--- .../protocol/packets/s2c/common/ChannelS2CP.kt | 4 ++-- .../protocol/packets/s2c/login/ChannelS2CP.kt | 4 ++-- .../packets/s2c/play/map/legacy/DataLegacyMapS2CP.kt | 4 ++-- src/main/java/de/bixilon/minosoft/util/KUtil.kt | 4 ++-- 53 files changed, 162 insertions(+), 161 deletions(-) diff --git a/gradle.properties b/gradle.properties index 85f50a69d..d3231af5c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # # Minosoft -# Copyright (C) 2020-2024 Moritz Zwerger +# Copyright (C) 2020-2025 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,5 +17,5 @@ lwjgl.version=3.3.5 ikonli.version=12.3.1 netty.version=4.1.115.Final jackson.version=2.18.2 -kutil.version=1.26.5 +kutil.version=1.27.0 glm.version=0.9.9.1-12 diff --git a/src/benchmark/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt b/src/benchmark/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt index 998971111..15ed64ffd 100644 --- a/src/benchmark/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt +++ b/src/benchmark/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.data.world.chunk import de.bixilon.kotlinglm.vec2.Vec2i -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.locks.reentrant.ReentrantRWLock import de.bixilon.kutil.observer.DataObserver import de.bixilon.kutil.reflection.ReflectionUtil.forceSet import de.bixilon.kutil.reflection.ReflectionUtil.jvmField @@ -66,7 +66,7 @@ object LightTestingUtil { fun createEmptyChunk(position: ChunkPosition): Chunk { val objenesis = ObjenesisStd() val chunk = objenesis.newInstance(Chunk::class.java) - chunk::lock.forceSet(ThreadLock()) + chunk::lock.forceSet(ReentrantRWLock()) chunk::chunkPosition.forceSet(position) chunk::world.forceSet(world) chunk::maxSection.forceSet(chunk.world.dimension.maxSection) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/config/profile/test/TestProfile.kt b/src/integration-test/kotlin/de/bixilon/minosoft/config/profile/test/TestProfile.kt index 6068d34e6..4ece2beb1 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/config/profile/test/TestProfile.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/config/profile/test/TestProfile.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,6 @@ package de.bixilon.minosoft.config.profile.test -import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.minosoft.config.profile.ProfileLock import de.bixilon.minosoft.config.profile.ProfileType import de.bixilon.minosoft.config.profile.delegate.primitive.IntDelegate @@ -24,7 +23,7 @@ import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft class TestProfile( override var storage: ProfileStorage? = null, - override val lock: Lock = ProfileLock(), + override val lock: ProfileLock = ProfileLock(), ) : Profile { val config = ConfigC(this) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/WorldTestUtil.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/WorldTestUtil.kt index a6bea25af..c4465d7b3 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/WorldTestUtil.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/WorldTestUtil.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.world import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec3.Vec3i -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.observer.DataObserver import de.bixilon.kutil.reflection.ReflectionUtil.forceSet import de.bixilon.kutil.reflection.ReflectionUtil.getFieldOrNull @@ -44,7 +44,7 @@ object WorldTestUtil { fun createWorld(session: PlaySession?, light: Boolean = false, capacity: Int = 0): World { val world = IT.OBJENESIS.newInstance(World::class.java) world::occlusion.forceSet(DataObserver(0)) - world::lock.forceSet(SimpleLock()) + world::lock.forceSet(RWLock.rwlock()) world::chunks.forceSet(ChunkManager(world, maxOf(0, capacity), 0)) world::border.forceSet(WorldBorder()) world::dimension.forceSet(DataObserver(DimensionProperties(light = light, skyLight = light))) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt index 43c2ef843..aee63fcb7 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/LightTestingUtil.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.data.world.chunk import de.bixilon.kotlinglm.vec2.Vec2i -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.observer.DataObserver import de.bixilon.kutil.reflection.ReflectionUtil.forceSet import de.bixilon.kutil.reflection.ReflectionUtil.jvmField @@ -57,7 +57,7 @@ object LightTestingUtil { fun createEmptyChunk(position: ChunkPosition): Chunk { val objenesis = ObjenesisStd() val chunk = objenesis.newInstance(Chunk::class.java) - chunk::lock.forceSet(ThreadLock()) + chunk::lock.forceSet(RWLock.rwlock()) chunk::chunkPosition.forceSet(position) chunk::world.forceSet(world) chunk::maxSection.forceSet(chunk.world.dimension.maxSection) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/ProfileLock.kt b/src/main/java/de/bixilon/minosoft/config/profile/ProfileLock.kt index c8a3b7e89..ec5bd7f07 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/ProfileLock.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/ProfileLock.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,6 @@ package de.bixilon.minosoft.config.profile -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.locks.reentrant.ReentrantRWLock -typealias ProfileLock = ThreadLock +typealias ProfileLock = ReentrantRWLock diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/Profile.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/Profile.kt index 8a162bdcf..f0e82ed08 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/Profile.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/Profile.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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.config.profile.profiles import com.fasterxml.jackson.annotation.JsonIgnore -import de.bixilon.kutil.concurrent.lock.Lock +import de.bixilon.minosoft.config.profile.ProfileLock import de.bixilon.minosoft.config.profile.storage.ProfileStorage interface Profile { @get:JsonIgnore var storage: ProfileStorage? - @get:JsonIgnore val lock: Lock + @get:JsonIgnore val lock: ProfileLock } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/storage/ProfileIOManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/storage/ProfileIOManager.kt index 16c35425a..a72badd80 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/storage/ProfileIOManager.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/storage/ProfileIOManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -15,7 +15,7 @@ package de.bixilon.minosoft.config.profile.storage import com.fasterxml.jackson.databind.node.ObjectNode import de.bixilon.kutil.cast.CastUtil.unsafeCast -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll import de.bixilon.kutil.latch.SimpleLatch import de.bixilon.minosoft.config.profile.profiles.Profile @@ -27,7 +27,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType import java.io.FileInputStream object ProfileIOManager { - private val lock = SimpleLock() + private val lock = Lock.lock() private val notify = SimpleLatch(0) private val save: MutableSet = mutableSetOf() private val delete: MutableSet = mutableSetOf() diff --git a/src/main/java/de/bixilon/minosoft/config/profile/storage/StorageProfileManager.kt b/src/main/java/de/bixilon/minosoft/config/profile/storage/StorageProfileManager.kt index 97239124f..7db9f42d5 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/storage/StorageProfileManager.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/storage/StorageProfileManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -20,7 +20,7 @@ import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.kutil.cast.CastUtil.unsafeNull import de.bixilon.kutil.collections.CollectionUtil.mutableBiMapOf import de.bixilon.kutil.collections.map.bi.AbstractMutableBiMap -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.exception.Broken import de.bixilon.kutil.file.FileUtil.mkdirParent import de.bixilon.kutil.file.watcher.FileWatcherService @@ -57,7 +57,7 @@ abstract class StorageProfileManager

: Iterable

, Identified { abstract val type: ProfileType

- private val lock = SimpleLock() + private val lock = RWLock.rwlock() val profiles: AbstractMutableBiMap by observedBiMap(mutableBiMapOf()) var selected: P by observed(unsafeNull()) diff --git a/src/main/java/de/bixilon/minosoft/data/accounts/types/microsoft/MicrosoftAccount.kt b/src/main/java/de/bixilon/minosoft/data/accounts/types/microsoft/MicrosoftAccount.kt index 6f4c883ab..14fc5f668 100644 --- a/src/main/java/de/bixilon/minosoft/data/accounts/types/microsoft/MicrosoftAccount.kt +++ b/src/main/java/de/bixilon/minosoft/data/accounts/types/microsoft/MicrosoftAccount.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +16,7 @@ package de.bixilon.minosoft.data.accounts.types.microsoft import com.fasterxml.jackson.annotation.JacksonInject import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonProperty -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.exception.Broken import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.kutil.latch.AbstractLatch.Companion.child @@ -52,7 +52,7 @@ class MicrosoftAccount( override val type: ResourceLocation = identifier @JsonIgnore - private val keyLock = SimpleLock() + private val keyLock = Lock.lock() @Synchronized override fun join(serverId: String) { diff --git a/src/main/java/de/bixilon/minosoft/data/container/Container.kt b/src/main/java/de/bixilon/minosoft/data/container/Container.kt index 2e5716c23..2627c9cfb 100644 --- a/src/main/java/de/bixilon/minosoft/data/container/Container.kt +++ b/src/main/java/de/bixilon/minosoft/data/container/Container.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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.data.container -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.locks.reentrant.ReentrantRWLock import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.observer.DataObserver.Companion.observed import de.bixilon.kutil.observer.map.MapObserver.Companion.observedMap @@ -39,7 +39,7 @@ abstract class Container( ) : Iterable> { @Deprecated("Should not be accessed directly") val slots: MutableMap by observedMap(Int2ObjectOpenHashMap()) - val lock = ThreadLock() + val lock = ReentrantRWLock() var propertiesRevision by observed(0L) var revision by observed(0L) var serverRevision = 0 diff --git a/src/main/java/de/bixilon/minosoft/data/container/stack/ItemStack.kt b/src/main/java/de/bixilon/minosoft/data/container/stack/ItemStack.kt index 5f8ae94fa..2f8ccaa2a 100644 --- a/src/main/java/de/bixilon/minosoft/data/container/stack/ItemStack.kt +++ b/src/main/java/de/bixilon/minosoft/data/container/stack/ItemStack.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -12,8 +12,8 @@ */ package de.bixilon.minosoft.data.container.stack -import de.bixilon.kutil.concurrent.lock.simple.ParentLock -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.locks.ParentLock +import de.bixilon.kutil.concurrent.lock.locks.reentrant.ReentrantRWLock import de.bixilon.kutil.json.JsonObject import de.bixilon.kutil.json.MutableJsonObject import de.bixilon.kutil.observer.DataObserver.Companion.observed @@ -28,7 +28,7 @@ import de.bixilon.minosoft.protocol.network.session.play.PlaySession import java.util.* class ItemStack { - val lock = ParentLock(lock = ThreadLock()) + val lock = ParentLock(lock = ReentrantRWLock()) val item: ItemProperty var holder: HolderProperty? = null diff --git a/src/main/java/de/bixilon/minosoft/data/entities/data/EntityData.kt b/src/main/java/de/bixilon/minosoft/data/entities/data/EntityData.kt index a631eeaf3..0e7d1d3a9 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/data/EntityData.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/data/EntityData.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +16,7 @@ package de.bixilon.minosoft.data.entities.data import de.bixilon.kutil.bit.BitByte.isBitMask import de.bixilon.kutil.cast.CastUtil.cast import de.bixilon.kutil.cast.CastUtil.unsafeCast -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.protocol.network.session.play.PlaySession import de.bixilon.minosoft.util.logging.Log @@ -28,10 +28,10 @@ class EntityData( val session: PlaySession, data: Int2ObjectOpenHashMap? = null, ) { - private val lock = SimpleLock() + private val lock = RWLock.rwlock() private val data: Int2ObjectOpenHashMap = Int2ObjectOpenHashMap() private val observers: Int2ObjectOpenHashMap Unit>> = Int2ObjectOpenHashMap() - private val observersLock = SimpleLock() + private val observersLock = RWLock.rwlock() init { data?.let { merge(it) } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/SignatureKeyManagement.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/SignatureKeyManagement.kt index 4c917f8f9..135a21ce8 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/SignatureKeyManagement.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/local/SignatureKeyManagement.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.data.entities.entities.player.local import de.bixilon.kutil.cast.CastUtil.nullCast -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.concurrent.schedule.TaskScheduler.runLater import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.kutil.time.TimeUtil.millis @@ -36,7 +36,7 @@ class SignatureKeyManagement( val session: PlaySession, val account: Account, ) { - private val lock = SimpleLock() + private val lock = RWLock.rwlock() var key: PlayerPrivateKey? = null private set diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt index 8929dc722..7d96e6035 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/World.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,9 @@ package de.bixilon.minosoft.data.world import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec3.Vec3i -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker import de.bixilon.kutil.observer.DataObserver.Companion.observed -import de.bixilon.kutil.random.RandomUtil.nextInt import de.bixilon.minosoft.data.entities.block.BlockEntity import de.bixilon.minosoft.data.entities.entities.Entity import de.bixilon.minosoft.data.registries.blocks.state.BlockState @@ -55,7 +54,7 @@ import java.util.* class World( val session: PlaySession, ) : WorldAudioPlayer { - val lock = SimpleLock() + val lock = RWLock.rwlock() val random = Random() val biomes = WorldBiomes(this) val chunks = ChunkManager(this, 1000, 100) diff --git a/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/Chunk.kt b/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/Chunk.kt index 4e9d875f7..1d0f8999f 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/Chunk.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/chunk/chunk/Chunk.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.data.world.chunk.chunk import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec3.Vec3i -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.math.simple.IntMath.clamp import de.bixilon.minosoft.data.direction.Directions import de.bixilon.minosoft.data.entities.block.BlockEntity @@ -45,7 +45,7 @@ class Chunk( val chunkPosition: ChunkPosition, var biomeSource: BiomeSource, ) : Iterable, BiomeAccessor { - val lock = ThreadLock() + val lock = RWLock.rwlock() val world = session.world val light = ChunkLight(this) val minSection = world.dimension.minSection diff --git a/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt b/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt index 4d39dd576..697c56b95 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/entities/WorldEntities.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.data.world.entities import de.bixilon.kotlinglm.vec3.Vec3d -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.observer.set.SetObserver.Companion.observedSet import de.bixilon.minosoft.data.abilities.Gamemodes import de.bixilon.minosoft.data.entities.entities.Entity @@ -34,7 +34,7 @@ class WorldEntities : Iterable { val entities: MutableSet by observedSet(mutableSetOf()) private val ticker = EntityTicker(this) - val lock = SimpleLock() + val lock = RWLock.rwlock() val size: Int get() = entities.size diff --git a/src/main/java/de/bixilon/minosoft/gui/eros/util/StageList.kt b/src/main/java/de/bixilon/minosoft/gui/eros/util/StageList.kt index e4f848fe4..ccf65e86e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/eros/util/StageList.kt +++ b/src/main/java/de/bixilon/minosoft/gui/eros/util/StageList.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,13 +13,13 @@ package de.bixilon.minosoft.gui.eros.util -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import javafx.stage.Stage import java.lang.ref.WeakReference class StageList : Iterable { private val stages: MutableList> = mutableListOf() - val lock = SimpleLock() + val lock = Lock.lock() private fun MutableList>.cleanup() { val iterator = this.iterator() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt index 252f3054b..0797fe398 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderConstants.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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 import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture +import kotlin.time.Duration.Companion.milliseconds object RenderConstants { val TEXT_BACKGROUND_COLOR = RGBColor(0, 0, 0, 80) @@ -25,7 +26,7 @@ object RenderConstants { const val OCCLUSION_CULLING_ENABLED = true const val SHOW_FPS_IN_WINDOW_TITLE = true - const val MAXIMUM_QUEUE_TIME_PER_FRAME = 20L + val MAXIMUM_QUEUE_TIME_PER_FRAME = 20.milliseconds val DEBUG_TEXTURE_RESOURCE_LOCATION = minosoft("debug").texture() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/MatrixHandler.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/MatrixHandler.kt index 504c53086..79f52da63 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/MatrixHandler.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/MatrixHandler.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -19,7 +19,7 @@ import de.bixilon.kotlinglm.func.rad import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.kutil.avg.FloatAverage +import de.bixilon.kutil.avg._float.FloatAverage import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.camera.CameraDefinition.CAMERA_UP_VEC3 import de.bixilon.minosoft.gui.rendering.camera.CameraDefinition.NEAR_PLANE @@ -36,6 +36,7 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.chunkPosition import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.sectionHeight import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition +import kotlin.time.Duration.Companion.milliseconds class MatrixHandler( private val context: RenderContext, @@ -68,7 +69,7 @@ class MatrixHandler( var viewProjectionMatrix = projectionMatrix * viewMatrix private set - private var dynamicFOV = FloatAverage(3 * ProtocolDefinition.TICK_TIME * 1_000_000L, 1.0f) + private var dynamicFOV = FloatAverage((3 * ProtocolDefinition.TICK_TIME).milliseconds, 1.0f) private fun calculateFOV(): Float { var fov = profile.fov diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/shaking/CameraShaking.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/shaking/CameraShaking.kt index 490f84fe2..73aad8b79 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/shaking/CameraShaking.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/shaking/CameraShaking.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.camera.shaking import de.bixilon.kotlinglm.mat4x4.Mat4 import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.swizzle.xz -import de.bixilon.kutil.avg.FloatAverage +import de.bixilon.kutil.avg._float.FloatAverage import de.bixilon.kutil.math.Trigonometry.sin import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.minosoft.config.profile.profiles.rendering.camera.shaking.ShakingC @@ -24,14 +24,15 @@ import de.bixilon.minosoft.gui.rendering.camera.Camera import de.bixilon.minosoft.gui.rendering.renderer.drawable.Drawable import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.Z import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition +import kotlin.time.Duration.Companion.milliseconds class CameraShaking( private val camera: Camera, private val profile: ShakingC, ) : Drawable { private var rotation = 0.0f - private var strength = FloatAverage(5 * ProtocolDefinition.TICK_TIME * 1_000_000L, 1.0f) - private val speed = FloatAverage(5 * ProtocolDefinition.TICK_TIME * 1_000_000L, 0.0f) + private var strength = FloatAverage((5 * ProtocolDefinition.TICK_TIME).milliseconds, 1.0f) + private val speed = FloatAverage((5 * ProtocolDefinition.TICK_TIME).milliseconds, 0.0f) val isEmpty: Boolean get() = rotation == 0.0f diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/ChunkRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/ChunkRenderer.kt index 5638f9f74..1dd3abbc5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/ChunkRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/ChunkRenderer.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -15,7 +15,7 @@ package de.bixilon.minosoft.gui.rendering.chunk import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.latch.AbstractLatch import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.minosoft.config.key.KeyActions @@ -63,7 +63,7 @@ class ChunkRenderer( val visibilityGraph = context.camera.visibilityGraph private val shader = renderSystem.createShader(minosoft("chunk")) { ChunkShader(it) } private val textShader = renderSystem.createShader(minosoft("chunk")) { ChunkShader(it) } - val lock = SimpleLock() + val lock = RWLock.rwlock() val world: World = session.world val loaded = LoadedMeshes(this) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/LoadedMeshes.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/LoadedMeshes.kt index 06b2eb0c3..422a6912e 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/LoadedMeshes.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/LoadedMeshes.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.gui.rendering.chunk import de.bixilon.kotlinglm.vec2.Vec2i -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.minosoft.data.world.positions.ChunkPosition import de.bixilon.minosoft.gui.rendering.chunk.mesh.ChunkMeshes import de.bixilon.minosoft.gui.rendering.chunk.mesh.VisibleMeshes @@ -24,7 +24,7 @@ class LoadedMeshes( private val renderer: ChunkRenderer, ) { val meshes: MutableMap> = hashMapOf() // all prepared (and up to date) meshes - private val lock = SimpleLock() + private val lock = RWLock.rwlock() val size: Int get() = meshes.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/CulledQueue.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/CulledQueue.kt index 7a4f66aa0..8b76646ed 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/CulledQueue.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/CulledQueue.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.queue import de.bixilon.kotlinglm.vec2.Vec2i -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.minosoft.data.world.chunk.chunk.Chunk import de.bixilon.minosoft.data.world.positions.ChunkPosition import de.bixilon.minosoft.data.world.positions.SectionHeight @@ -25,7 +25,7 @@ class CulledQueue( private val renderer: ChunkRenderer, ) { private val queue: MutableMap = mutableMapOf() // Chunk sections that can be prepared or have changed, but are not required to get rendered yet (i.e. culled chunks) - private val lock = SimpleLock() + private val lock = RWLock.rwlock() val size: Int get() = queue.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshLoadingQueue.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshLoadingQueue.kt index 615bb6e70..824a11d35 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshLoadingQueue.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshLoadingQueue.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.queue.loading import de.bixilon.kutil.cast.CastUtil.unsafeNull -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.time.TimeUtil import de.bixilon.minosoft.data.world.positions.ChunkPosition import de.bixilon.minosoft.gui.rendering.chunk.ChunkRenderer @@ -28,7 +28,7 @@ class MeshLoadingQueue( ) { private val meshes: MutableList = mutableListOf() // prepared meshes, that can be loaded in the (next) frame private val positions: MutableSet = HashSet() - private val lock = SimpleLock() + private val lock = Lock.lock() val size: Int get() = meshes.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshUnloadingQueue.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshUnloadingQueue.kt index ac60c4916..d45c5f333 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshUnloadingQueue.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/loading/MeshUnloadingQueue.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.chunk.queue.loading -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.time.TimeUtil import de.bixilon.minosoft.gui.rendering.chunk.ChunkRenderer import de.bixilon.minosoft.gui.rendering.chunk.mesh.ChunkMeshes @@ -25,7 +25,7 @@ class MeshUnloadingQueue( ) { private val meshes: MutableList = mutableListOf() // prepared meshes, that can be loaded in the (next) frame private val positions: MutableSet = mutableSetOf() - private val lock = SimpleLock() + private val lock = Lock.lock() private fun forceWork() { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/ChunkMeshingQueue.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/ChunkMeshingQueue.kt index 3c4a70bae..fb2d74144 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/ChunkMeshingQueue.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/ChunkMeshingQueue.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.queue.meshing import de.bixilon.kutil.cast.CastUtil.unsafeCast -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.concurrent.pool.ThreadPool import de.bixilon.kutil.concurrent.pool.runnable.HeavyPoolRunnable import de.bixilon.minosoft.data.world.positions.ChunkPosition @@ -37,7 +37,7 @@ class ChunkMeshingQueue( private val queue: MutableList = ArrayList() private val set: MutableSet = HashSet() - private val lock = SimpleLock() + private val lock = Lock.lock() val size: Int get() = queue.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/tasks/MeshPrepareTaskManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/tasks/MeshPrepareTaskManager.kt index 17c7462f8..5e50a9bd2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/tasks/MeshPrepareTaskManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/queue/meshing/tasks/MeshPrepareTaskManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.chunk.queue.meshing.tasks -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.minosoft.data.world.positions.ChunkPosition import de.bixilon.minosoft.data.world.positions.SectionHeight @@ -24,7 +24,7 @@ class MeshPrepareTaskManager( val max: Int = maxOf(minOf(Runtime.getRuntime().availableProcessors() - 1, DefaultThreadPool.threadCount - 1), 1) ) { private val tasks: MutableSet = mutableSetOf() // current running section preparing tasks - private val lock = SimpleLock() + private val lock = RWLock.rwlock() val size: Int get() = tasks.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityRendererManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityRendererManager.kt index 24b456018..319180256 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityRendererManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/EntityRendererManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +16,7 @@ package de.bixilon.minosoft.gui.rendering.entities import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.kutil.collections.map.LockMap import de.bixilon.kutil.collections.spliterator.async.ConcurrentSpliterator -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.concurrent.pool.ThreadPool import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll import de.bixilon.kutil.observer.set.SetObserver.Companion.observeSet @@ -30,7 +30,7 @@ import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class EntityRendererManager(val renderer: EntitiesRenderer) : Iterable> { - val lock = SimpleLock() + val lock = RWLock.rwlock() private val renderers: LockMap> = LockMap(HashMap(), lock) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/visibility/VisibilityManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/visibility/VisibilityManager.kt index e456397ce..455a7708d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/visibility/VisibilityManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/visibility/VisibilityManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.entities.visibility -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.minosoft.data.world.view.ViewDistanceChangeEvent import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer @@ -36,7 +36,7 @@ class VisibilityManager(val renderer: EntitiesRenderer) { val opaque: ArrayList = ArrayList(1000) val translucent: ArrayList = ArrayList(1000) - private val lock = SimpleLock() + private val lock = Lock.lock() private val graph = renderer.context.camera.visibilityGraph private val frustum = renderer.context.camera.matrixHandler.frustum private var renderDistance = 0 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/simple/PowderSnowOverlay.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/simple/PowderSnowOverlay.kt index 4da7a8eb5..632ce73db 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/simple/PowderSnowOverlay.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/framebuffer/world/overlay/overlays/simple/PowderSnowOverlay.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,18 +13,19 @@ package de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.overlays.simple -import de.bixilon.kutil.avg.FloatAverage +import de.bixilon.kutil.avg._float.FloatAverage import de.bixilon.minosoft.data.text.formatting.color.RGBColor import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.framebuffer.world.overlay.OverlayFactory import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture import de.bixilon.minosoft.util.KUtil.toResourceLocation +import kotlin.time.Duration.Companion.seconds class PowderSnowOverlay(context: RenderContext) : SimpleOverlay(context) { private val config = context.session.profiles.rendering.overlay override val texture: Texture = context.textures.static.create(OVERLAY_TEXTURE) - private val strength = FloatAverage(1L * 1000000000L, 0.0f) + private val strength = FloatAverage(1.seconds, 0.0f) override var render: Boolean = false get() = config.powderSnow && field diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt index 0977ebe73..2f02b8f23 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -15,7 +15,7 @@ package de.bixilon.minosoft.gui.rendering.gui.gui import de.bixilon.kotlinglm.vec2.Vec2 import de.bixilon.kutil.cast.CastUtil.unsafeCast -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.locks.reentrant.ReentrantRWLock import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.latch.SimpleLatch import de.bixilon.kutil.time.TimeUtil.millis @@ -49,7 +49,7 @@ class GUIManager( private val guiRenderer: GUIRenderer, ) : Initializable, InputHandler, DraggableHandler, Drawable, AsyncDrawable { private val elementCache: MutableMap, GUIElement> = mutableMapOf() - private var orderLock = SimpleLock() + private var orderLock = ReentrantRWLock() var elementOrder: MutableList = mutableListOf() private val context = guiRenderer.context private var lastTickTime: Long = -1L diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleList.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleList.kt index a7bdd8279..1c4a4c131 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleList.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleList.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,12 +13,12 @@ package de.bixilon.minosoft.gui.rendering.particle -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.minosoft.gui.rendering.particle.types.Particle class ParticleList(maxAmount: Int) { val particles: MutableList = ArrayList(maxAmount) - val lock = SimpleLock() + val lock = Lock.lock() val size get() = particles.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleQueue.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleQueue.kt index 4af561e3d..3c39a7827 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleQueue.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleQueue.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.particle -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.minosoft.gui.rendering.particle.types.Particle class ParticleQueue(val renderer: ParticleRenderer) { - private val lock = SimpleLock() + private val lock = Lock.lock() private val queue: MutableList = ArrayList(QUEUE_CAPACITY) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/AnimationManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/AnimationManager.kt index 297c1362a..66012166b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/AnimationManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/skeletal/instance/AnimationManager.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,14 +13,14 @@ package de.bixilon.minosoft.gui.rendering.skeletal.instance -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.minosoft.gui.rendering.skeletal.baked.animation.AbstractAnimation import de.bixilon.minosoft.gui.rendering.skeletal.baked.animation.keyframe.instance.KeyframeInstance.Companion.OVER class AnimationManager(val instance: SkeletalInstance) { private val playing: MutableMap = mutableMapOf() - private val lock = SimpleLock() + private val lock = Lock.lock() private var lastDraw = -1L diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt index 22f7de31e..85b2ae27b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -40,6 +40,7 @@ import org.lwjgl.openal.EXTThreadLocalContext.alcSetThreadContext import org.lwjgl.system.MemoryUtil import java.nio.ByteBuffer import java.nio.IntBuffer +import kotlin.time.Duration.Companion.milliseconds class AudioPlayer( @@ -234,7 +235,7 @@ class AudioPlayer( if (session.established || session.error != null) { break } - queue.workBlocking(500L) + queue.workBlocking(500.milliseconds) calculateAvailableSources() while (!enabled) { Thread.sleep(1L) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/stats/AbstractRenderStats.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/stats/AbstractRenderStats.kt index 57e92f58d..672f32c30 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/stats/AbstractRenderStats.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/stats/AbstractRenderStats.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.stats -import de.bixilon.kutil.avg.Average +import de.bixilon.kutil.avg._long.LongAverage interface AbstractRenderStats { - val avgDrawTime: Average - val avgFrameTime: Average + val avgDrawTime: LongAverage + val avgFrameTime: LongAverage val avgFPS: Double val smoothAvgFPS: Double diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/stats/ExperimentalRenderStats.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/stats/ExperimentalRenderStats.kt index e84ede80a..3987be2b3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/stats/ExperimentalRenderStats.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/stats/ExperimentalRenderStats.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,12 +14,10 @@ package de.bixilon.minosoft.gui.rendering.stats import de.bixilon.kotlinglm.func.common.clamp -import de.bixilon.kutil.avg.Average -import de.bixilon.kutil.avg.LongAverage -import de.bixilon.kutil.random.RandomUtil.nextFloat -import de.bixilon.kutil.random.RandomUtil.nextInt +import de.bixilon.kutil.avg._long.LongAverage import de.bixilon.kutil.time.TimeUtil.millis import java.util.* +import kotlin.time.Duration.Companion.seconds class ExperimentalRenderStats : AbstractRenderStats { private val renderStats = RenderStats() @@ -28,8 +26,8 @@ class ExperimentalRenderStats : AbstractRenderStats { private val baseMultiplier = random.nextFloat(1.0f, 1.5f) private val baseJitter = random.nextInt(0, 20) - override val avgFrameTime: Average = LongAverage(Long.MAX_VALUE) - override val avgDrawTime: Average = LongAverage(Long.MAX_VALUE) + override val avgFrameTime = LongAverage(3.seconds) + override val avgDrawTime = LongAverage(3.seconds) private var lastSmoothFPSCalculationTime = 0L override var smoothAvgFPS: Double = 0.0 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/stats/RenderStats.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/stats/RenderStats.kt index f610deb15..0f028b3b9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/stats/RenderStats.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/stats/RenderStats.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,12 +13,13 @@ package de.bixilon.minosoft.gui.rendering.stats -import de.bixilon.kutil.avg.LongAverage +import de.bixilon.kutil.avg._long.LongAverage import de.bixilon.kutil.time.TimeUtil.millis +import kotlin.time.Duration.Companion.seconds class RenderStats : AbstractRenderStats { - override val avgDrawTime: LongAverage = LongAverage(1L * 1000000000L, Long.MAX_VALUE) // 1 second * SECOND_SCALE - override val avgFrameTime: LongAverage = LongAverage(1L * 1000000000L, Long.MAX_VALUE) // 1 second * SECOND_SCALE + override val avgDrawTime = LongAverage(3.seconds, Long.MAX_VALUE) + override val avgFrameTime = LongAverage(3.seconds, Long.MAX_VALUE) override var totalFrames: Long = 0L private set diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/StaticTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/StaticTextureArray.kt index 216df5ff5..42e032fa4 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/StaticTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/StaticTextureArray.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.gui.rendering.system.base.texture.array import de.bixilon.kotlinglm.vec2.Vec2i -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.concurrent.pool.ThreadPool import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable @@ -35,7 +35,7 @@ abstract class StaticTextureArray( ) : TextureArray { protected val named: MutableMap = mutableMapOf() protected val other: MutableSet = mutableSetOf() - private val lock = SimpleLock() + private val lock = RWLock.rwlock() val animator = SpriteAnimator(context) var state: TextureArrayStates = TextureArrayStates.DECLARED diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontTextureArray.kt index b75457a69..8a3978c43 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/array/font/FontTextureArray.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.system.base.texture.array.font -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.concurrent.pool.ThreadPool.Priorities.HIGH import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable @@ -29,7 +29,7 @@ abstract class FontTextureArray( val compression: FontCompressions, ) : TextureArray { protected val textures: MutableSet = mutableSetOf() - private val lock = SimpleLock() + private val lock = Lock.lock() var state: TextureArrayStates = TextureArrayStates.DECLARED protected set diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTexture.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTexture.kt index 64c86845a..1b71bcfa9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTexture.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTexture.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.gui.rendering.system.base.texture.dynamic import de.bixilon.kotlinglm.vec2.Vec2 -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll import de.bixilon.minosoft.gui.rendering.system.base.texture.data.MipmapTextureData import de.bixilon.minosoft.gui.rendering.system.base.texture.shader.ShaderTexture @@ -23,7 +23,7 @@ abstract class DynamicTexture( val identifier: Any, ) : ShaderTexture { private val callbacks: MutableSet = mutableSetOf() - private val lock = SimpleLock() + private val lock = RWLock.rwlock() var data: MipmapTextureData? = null var state: DynamicTextureState = DynamicTextureState.WAITING diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt index cc201708b..81da206e3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/base/texture/dynamic/DynamicTextureArray.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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.gui.rendering.system.base.texture.dynamic -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.locks.reentrant.ReentrantRWLock import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.concurrent.pool.runnable.ForcePooledRunnable import de.bixilon.kutil.latch.AbstractLatch @@ -37,7 +37,7 @@ abstract class DynamicTextureArray( ) : TextureArray { protected var textures: Array?> = arrayOfNulls(initialSize) protected val shaders: MutableSet = mutableSetOf() - private val lock = ThreadLock() + private val lock = ReentrantRWLock() private var reload = false val capacity get() = textures.size diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt index 4fd5b4e7c..d174ca342 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/system/opengl/OpenGLRenderSystem.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,6 @@ package de.bixilon.minosoft.gui.rendering.system.opengl import de.bixilon.kotlinglm.vec2.Vec2i -import de.bixilon.kutil.concurrent.lock.thread.ThreadMissmatchException 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 @@ -307,7 +306,7 @@ class OpenGLRenderSystem( val thread = thread ?: throw IllegalStateException("Not yet initialized!") val current = Thread.currentThread() if (thread !== current) { - throw ThreadMissmatchException(thread, current) + throw Exception("Thread mismatch: thread=$thread, current=$current") } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/master/EventMaster.kt b/src/main/java/de/bixilon/minosoft/modding/event/master/EventMaster.kt index 8e06d99a8..501820a09 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/master/EventMaster.kt +++ b/src/main/java/de/bixilon/minosoft/modding/event/master/EventMaster.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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,7 +14,7 @@ package de.bixilon.minosoft.modding.event.master import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedList -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker import de.bixilon.minosoft.modding.event.events.AsyncEvent import de.bixilon.minosoft.modding.event.events.CancelableEvent @@ -26,9 +26,9 @@ import java.util.* open class EventMaster(vararg parents: AbstractEventMaster) : AbstractEventMaster { private val parents: MutableSet = mutableSetOf(*parents) - private val parentLock = SimpleLock() + private val parentLock = RWLock.rwlock() private val eventListeners: PriorityQueue = PriorityQueue() - private val eventInvokerLock = SimpleLock() + private val eventInvokerLock = RWLock.rwlock() override val size: Int get() { diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/NetworkConnection.kt b/src/main/java/de/bixilon/minosoft/protocol/network/NetworkConnection.kt index 086a572d5..894680f36 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/NetworkConnection.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/NetworkConnection.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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 -import de.bixilon.kutil.concurrent.lock.thread.ThreadLock +import de.bixilon.kutil.concurrent.lock.RWLock import de.bixilon.kutil.observer.DataObserver import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.observer.DataObserver.Companion.observed @@ -37,7 +37,7 @@ class NetworkConnection( override val identifier = address.toString() override var active by observed(false) private set - var state: ProtocolStates? by DataObserver(null, ThreadLock()) + var state: ProtocolStates? by DataObserver(null, RWLock.rwlock()) init { this::state.observe(this) { active = it != null } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/compression/PacketInflater.kt b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/compression/PacketInflater.kt index 33f291dcc..3c0db9115 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/compression/PacketInflater.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/compression/PacketInflater.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -29,7 +29,7 @@ class PacketInflater( val buffer = InByteBuffer(data) val uncompressedLength = buffer.readVarInt() - val rest = buffer.readRest() + val rest = buffer.readRemaining() if (uncompressedLength == 0) { out += rest return diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/encoding/PacketDecoder.kt b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/encoding/PacketDecoder.kt index f947f75a5..0c59bf55a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/encoding/PacketDecoder.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/network/client/netty/pipeline/encoding/PacketDecoder.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -36,7 +36,7 @@ class PacketDecoder( override fun decode(context: ChannelHandlerContext, array: ByteArray, out: MutableList) { val buffer = InByteBuffer(array) val packetId = buffer.readVarInt() - val data = buffer.readRest() + val data = buffer.readRemaining() val state = client.connection.state ?: throw IllegalStateException("Not connected!") diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/session/play/tick/SessionTicker.kt b/src/main/java/de/bixilon/minosoft/protocol/network/session/play/tick/SessionTicker.kt index 2fa7cad1e..648e05fa5 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/session/play/tick/SessionTicker.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/network/session/play/tick/SessionTicker.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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.session.play.tick -import de.bixilon.kutil.concurrent.lock.simple.SimpleLock +import de.bixilon.kutil.concurrent.lock.Lock import de.bixilon.kutil.concurrent.schedule.RepeatedTask import de.bixilon.kutil.concurrent.schedule.TaskScheduler import de.bixilon.kutil.concurrent.schedule.TaskScheduler.runLater @@ -27,7 +27,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition class SessionTicker(private val session: PlaySession) { private val tasks: MutableSet = mutableSetOf() - private val lock = SimpleLock() + private val lock = Lock.lock() private var registered = false diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/common/ChannelS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/common/ChannelS2CP.kt index 79e2fec0f..dfd055e3b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/common/ChannelS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/common/ChannelS2CP.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -33,7 +33,7 @@ class ChannelS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { } } - val data = buffer.readRest() + val data = buffer.readRemaining() override fun handle(session: PlaySession) { session.channels.play.handle(channel, data) diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/login/ChannelS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/login/ChannelS2CP.kt index daac44e72..33c543815 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/login/ChannelS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/login/ChannelS2CP.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -22,7 +22,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType class ChannelS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { val messageId = buffer.readVarInt() val channel = buffer.readResourceLocation() - val data: ByteArray = buffer.readRest() + val data: ByteArray = buffer.readRemaining() override fun handle(session: PlaySession) { session.channels.login.handle(messageId, channel, data) diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/map/legacy/DataLegacyMapS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/map/legacy/DataLegacyMapS2CP.kt index ee290233c..1c999451a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/map/legacy/DataLegacyMapS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/map/legacy/DataLegacyMapS2CP.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -24,7 +24,7 @@ class DataLegacyMapS2CP( buffer: PlayInByteBuffer, ) : LegacyMapS2CP { val start = Vec2i(buffer.readUnsignedByte(), buffer.readUnsignedByte()) - val colors = buffer.readRest() + val colors = buffer.readRemaining() override fun log(reducedLog: Boolean) { if (reducedLog) { diff --git a/src/main/java/de/bixilon/minosoft/util/KUtil.kt b/src/main/java/de/bixilon/minosoft/util/KUtil.kt index 6a05e36f9..4b8845345 100644 --- a/src/main/java/de/bixilon/minosoft/util/KUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/KUtil.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2024 Moritz Zwerger + * Copyright (C) 2020-2025 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. * @@ -340,7 +340,7 @@ object KUtil { fun PlayInByteBuffer.dump(name: String) { val pointer = pointer this.pointer = 0 - val data = readRest() + val data = readRemaining() this.pointer = pointer val path = "/home/moritz/${name}_${Versions.getById(this.versionId)?.name?.replace(".", "_")}.bin"