Synchronize item registry loading using universe thread
This commit is contained in:
parent
a2cc4ba6c3
commit
b41d45b3e9
@ -23,6 +23,7 @@ import ru.dbotthepony.kstarbound.defs.`object`.ObjectDefinition
|
|||||||
import ru.dbotthepony.kstarbound.fromJson
|
import ru.dbotthepony.kstarbound.fromJson
|
||||||
import ru.dbotthepony.kstarbound.json.JsonPatch
|
import ru.dbotthepony.kstarbound.json.JsonPatch
|
||||||
import ru.dbotthepony.kstarbound.json.builder.JsonFactory
|
import ru.dbotthepony.kstarbound.json.builder.JsonFactory
|
||||||
|
import ru.dbotthepony.kstarbound.json.fromJsonTreeFast
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
@ -50,7 +51,6 @@ object ItemRegistry {
|
|||||||
|
|
||||||
private val LOGGER = LogManager.getLogger()
|
private val LOGGER = LogManager.getLogger()
|
||||||
private val entries = HashMap<String, Entry>()
|
private val entries = HashMap<String, Entry>()
|
||||||
private val tasks = ConcurrentLinkedQueue<Runnable>()
|
|
||||||
|
|
||||||
val AIR = Entry("", ItemType.GENERIC, JsonObject(), true, "air", ImmutableSet.of(), ImmutableSet.of(), null)
|
val AIR = Entry("", ItemType.GENERIC, JsonObject(), true, "air", ImmutableSet.of(), ImmutableSet.of(), null)
|
||||||
|
|
||||||
@ -134,9 +134,6 @@ object ItemRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun finishLoad() {
|
fun finishLoad() {
|
||||||
tasks.forEach { it.run() }
|
|
||||||
tasks.clear()
|
|
||||||
|
|
||||||
for (obj in Registries.worldObjects.keys.values) {
|
for (obj in Registries.worldObjects.keys.values) {
|
||||||
if (obj.value.hasObjectItem) {
|
if (obj.value.hasObjectItem) {
|
||||||
addObjectItem(obj)
|
addObjectItem(obj)
|
||||||
@ -154,10 +151,10 @@ object ItemRegistry {
|
|||||||
for (file in files) {
|
for (file in files) {
|
||||||
futures.add(Starbound.GLOBAL_SCOPE.launch {
|
futures.add(Starbound.GLOBAL_SCOPE.launch {
|
||||||
try {
|
try {
|
||||||
val read = JsonPatch.applyAsync(Starbound.ELEMENTS_ADAPTER.read(file.asyncJsonReader().await()), patches[file.computeFullPath()]).asJsonObject
|
val read = JsonPatch.applyAsync(file.asyncJsonReader(), patches[file.computeFullPath()]).asJsonObject
|
||||||
val readData = data.fromJsonTree(read)
|
val readData = data.fromJsonTreeFast(read)
|
||||||
|
|
||||||
tasks.add {
|
Starbound.submit {
|
||||||
if (readData.itemName in entries) {
|
if (readData.itemName in entries) {
|
||||||
LOGGER.warn("Overwriting item definition at ${readData.itemName} (old def originate from ${entries[readData.itemName]!!.file}; new from $file)")
|
LOGGER.warn("Overwriting item definition at ${readData.itemName} (old def originate from ${entries[readData.itemName]!!.file}; new from $file)")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user