diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt index 06ca1a97..0d867990 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/GlobalDefaults.kt @@ -3,16 +3,18 @@ package ru.dbotthepony.kstarbound import org.apache.logging.log4j.LogManager import ru.dbotthepony.kstarbound.defs.ClientConfigParameters import ru.dbotthepony.kstarbound.defs.MovementParameters -import ru.dbotthepony.kstarbound.defs.PlayerMovementParameters +import ru.dbotthepony.kstarbound.defs.ActorMovementParameters import ru.dbotthepony.kstarbound.util.AssetPathStack +import java.util.concurrent.ExecutorService import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinTask +import java.util.concurrent.Future import kotlin.reflect.KMutableProperty0 object GlobalDefaults { private val LOGGER = LogManager.getLogger() - var playerMovementParameters = PlayerMovementParameters() + var actorMovementParameters = ActorMovementParameters() private set var movementParameters = MovementParameters() @@ -34,7 +36,7 @@ object GlobalDefaults { } } - private inline fun load(path: String, accept: KMutableProperty0, executor: ForkJoinPool): ForkJoinTask<*> { + private inline fun load(path: String, accept: KMutableProperty0, executor: ExecutorService): Future<*> { val file = Starbound.locate(path) if (!file.exists) { @@ -52,10 +54,10 @@ object GlobalDefaults { } } - fun load(executor: ForkJoinPool): List> { - val tasks = ArrayList>() + fun load(executor: ExecutorService): List> { + val tasks = ArrayList>() - tasks.add(load("/default_actor_movement.config", ::playerMovementParameters, executor)) + tasks.add(load("/default_actor_movement.config", ::actorMovementParameters, executor)) tasks.add(load("/default_movement.config", ::movementParameters, executor)) tasks.add(load("/client.config", ::clientParameters, executor)) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/RecipeRegistry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/RecipeRegistry.kt index 26c1fe2f..114f3e14 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/RecipeRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/RecipeRegistry.kt @@ -10,8 +10,10 @@ import ru.dbotthepony.kstarbound.util.KOptional import ru.dbotthepony.kstarbound.util.ParallelPerform import java.util.* import java.util.concurrent.ConcurrentLinkedQueue +import java.util.concurrent.ExecutorService import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinTask +import java.util.concurrent.Future import java.util.concurrent.locks.ReentrantLock import kotlin.collections.ArrayList import kotlin.concurrent.withLock @@ -72,7 +74,7 @@ object RecipeRegistry { } } - fun load(fileTree: Map>, executor: ForkJoinPool): List> { + fun load(fileTree: Map>, executor: ExecutorService): List> { val files = fileTree["recipe"] ?: return emptyList() val elements = Starbound.gson.getAdapter(JsonElement::class.java) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt index f9d3f28a..e1254b76 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Registries.kt @@ -35,8 +35,10 @@ import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier import ru.dbotthepony.kstarbound.defs.tile.TileDefinition import ru.dbotthepony.kstarbound.util.AssetPathStack +import java.util.concurrent.ExecutorService import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinTask +import java.util.concurrent.Future object Registries { private val LOGGER = LogManager.getLogger() @@ -96,11 +98,11 @@ object Registries { } private inline fun loadRegistry( - executor: ForkJoinPool, + executor: ExecutorService, registry: Registry, files: List, noinline keyProvider: (T) -> Pair - ): List> { + ): List> { val adapter by lazy { Starbound.gson.getAdapter(T::class.java) } val elementAdapter by lazy { Starbound.gson.getAdapter(JsonElement::class.java) } @@ -130,8 +132,8 @@ object Registries { registries.forEach { it.finishLoad() } } - fun load(fileTree: Map>, executor: ForkJoinPool): List> { - val tasks = ArrayList>() + fun load(fileTree: Map>, executor: ExecutorService): List> { + val tasks = ArrayList>() tasks.addAll(loadItemDefinitions(fileTree, executor)) @@ -155,7 +157,7 @@ object Registries { return tasks } - private fun loadItemDefinitions(files: Map>, executor: ForkJoinPool): List> { + private fun loadItemDefinitions(files: Map>, executor: ExecutorService): List> { val fileMap = mapOf( "item" to ItemDefinition::class.java, "currency" to CurrencyItemDefinition::class.java, @@ -169,7 +171,7 @@ object Registries { "back" to BackArmorItemDefinition::class.java, ) - val tasks = ArrayList>() + val tasks = ArrayList>() val objects = Starbound.gson.getAdapter(JsonObject::class.java) for ((ext, clazz) in fileMap) { @@ -195,7 +197,7 @@ object Registries { return tasks } - private fun loadJsonFunctions(files: Collection, executor: ForkJoinPool): List> { + private fun loadJsonFunctions(files: Collection, executor: ExecutorService): List> { return files.map { listedFile -> executor.submit { try { @@ -216,7 +218,7 @@ object Registries { } } - private fun loadJson2Functions(files: Collection, executor: ForkJoinPool): List> { + private fun loadJson2Functions(files: Collection, executor: ExecutorService): List> { return files.map { listedFile -> executor.submit { try { @@ -237,7 +239,7 @@ object Registries { } } - private fun loadTreasurePools(files: Collection, executor: ForkJoinPool): List> { + private fun loadTreasurePools(files: Collection, executor: ExecutorService): List> { return files.map { listedFile -> executor.submit { try { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 30b9cd56..2c8d83d3 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -63,8 +63,10 @@ import java.io.* import java.lang.ref.Cleaner import java.text.DateFormat import java.util.concurrent.CompletableFuture +import java.util.concurrent.Executors import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinTask +import java.util.concurrent.Future import java.util.concurrent.locks.LockSupport import java.util.function.BiConsumer import java.util.function.BinaryOperator @@ -442,8 +444,8 @@ object Starbound : ISBFileLocator { checkMailbox() - val tasks = ArrayList>() - val pool = if (parallel) ForkJoinPool.commonPool() else ForkJoinPool(1) + val tasks = ArrayList>() + val pool = if (parallel) ForkJoinPool.commonPool() else Executors.newFixedThreadPool(1) tasks.addAll(Registries.load(ext2files, pool)) tasks.addAll(RecipeRegistry.load(ext2files, pool))