From b41d45b3e917673c9009e57836e47e751f347642 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 22 May 2024 19:01:05 +0700 Subject: [PATCH] Synchronize item registry loading using universe thread --- .../ru/dbotthepony/kstarbound/item/ItemRegistry.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/item/ItemRegistry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/item/ItemRegistry.kt index 5ddbf4ba..6e44a180 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/item/ItemRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/item/ItemRegistry.kt @@ -23,6 +23,7 @@ import ru.dbotthepony.kstarbound.defs.`object`.ObjectDefinition import ru.dbotthepony.kstarbound.fromJson import ru.dbotthepony.kstarbound.json.JsonPatch import ru.dbotthepony.kstarbound.json.builder.JsonFactory +import ru.dbotthepony.kstarbound.json.fromJsonTreeFast import java.util.Collections import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.Future @@ -50,7 +51,6 @@ object ItemRegistry { private val LOGGER = LogManager.getLogger() private val entries = HashMap() - private val tasks = ConcurrentLinkedQueue() val AIR = Entry("", ItemType.GENERIC, JsonObject(), true, "air", ImmutableSet.of(), ImmutableSet.of(), null) @@ -134,9 +134,6 @@ object ItemRegistry { } fun finishLoad() { - tasks.forEach { it.run() } - tasks.clear() - for (obj in Registries.worldObjects.keys.values) { if (obj.value.hasObjectItem) { addObjectItem(obj) @@ -154,10 +151,10 @@ object ItemRegistry { for (file in files) { futures.add(Starbound.GLOBAL_SCOPE.launch { try { - val read = JsonPatch.applyAsync(Starbound.ELEMENTS_ADAPTER.read(file.asyncJsonReader().await()), patches[file.computeFullPath()]).asJsonObject - val readData = data.fromJsonTree(read) + val read = JsonPatch.applyAsync(file.asyncJsonReader(), patches[file.computeFullPath()]).asJsonObject + val readData = data.fromJsonTreeFast(read) - tasks.add { + Starbound.submit { if (readData.itemName in entries) { LOGGER.warn("Overwriting item definition at ${readData.itemName} (old def originate from ${entries[readData.itemName]!!.file}; new from $file)") }