This commit is contained in:
DBotThePony 2023-09-29 22:14:01 +07:00
parent ccf696a156
commit b3f7cee963
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 20 additions and 18 deletions

View File

@ -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"
})

View File

@ -155,24 +155,28 @@ class ObjectRegistry<T : Any>(val clazz: KClass<T>, val name: String, val key: (
return add(RegistryObject(value, json, file), key)
}
private val lock = Any()
private fun add(value: RegistryObject<T>, 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 {

View File

@ -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,
)
/**