From b3f7cee963883a5e212618cef4482529f492bf49 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 29 Sep 2023 22:14:01 +0700 Subject: [PATCH] fix --- .../dbotthepony/kstarbound/GlobalDefaults.kt | 2 -- .../dbotthepony/kstarbound/ObjectRegistry.kt | 34 +++++++++++-------- .../kstarbound/io/json/builder/Annotations.kt | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt index 5b3a32ae..e2944da6 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt @@ -4,7 +4,6 @@ import org.apache.logging.log4j.LogManager import ru.dbotthepony.kstarbound.defs.MovementParameters import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinTask -import java.util.concurrent.Future import kotlin.reflect.KMutableProperty0 object GlobalDefaults { @@ -50,7 +49,6 @@ object GlobalDefaults { return listOf(executor.submit { val line = log.line("Loading global defaults...") val time = System.nanoTime() - tasks.forEach { it.fork() } tasks.forEach { it.join() } line.text = "Loaded global defaults in ${((System.nanoTime() - time) / 1_000_000.0).toLong()}ms" }) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt index 4af771ac..d2bd25af 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/ObjectRegistry.kt @@ -155,24 +155,28 @@ class ObjectRegistry(val clazz: KClass, val name: String, val key: ( return add(RegistryObject(value, json, file), key) } + private val lock = Any() + private fun add(value: RegistryObject, key: String): Boolean { - val existing = objects.put(key, value) + synchronized(lock) { + val existing = objects.put(key, value) - if (existing != null) { - LOGGER.warn("Registry $name already has object with key $key! Overwriting. (old originated from ${existing.file}, new originate from ${value.file}).") + if (existing != null) { + LOGGER.warn("Registry $name already has object with key $key! Overwriting. (old originated from ${existing.file}, new originate from ${value.file}).") + } + + if (this.intKey == null) + return existing != null + + val intKey = this.intKey.invoke(value.value) + val intExisting = intObjects.put(intKey, value) + + if (intExisting != null) { + LOGGER.warn("Registry $name already has object with ID $intKey (new $key, old ${ objects.entries.firstOrNull { it.value === intExisting }?.key })! Overwriting. (old originated from ${intExisting.file}, new originate from ${value.file}).") + } + + return existing != null || intExisting != null } - - if (this.intKey == null) - return existing != null - - val intKey = this.intKey.invoke(value.value) - val intExisting = intObjects.put(intKey, value) - - if (intExisting != null) { - LOGGER.warn("Registry $name already has object with ID $intKey (new $key, old ${ objects.entries.firstOrNull { it.value === intExisting }?.key })! Overwriting. (old originated from ${intExisting.file}, new originate from ${value.file}).") - } - - return existing != null || intExisting != null } companion object { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/Annotations.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/Annotations.kt index c07f739f..6e5ec3d8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/Annotations.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/io/json/builder/Annotations.kt @@ -67,7 +67,7 @@ annotation class JsonBuilder annotation class JsonFactory( val storesJson: Boolean = false, val asList: Boolean = false, - val logMisses: Boolean = true, + val logMisses: Boolean = false, ) /**