Don't directly depend on forkjoinpool
This commit is contained in:
parent
f4cb791125
commit
bfc39a6cb6
@ -3,16 +3,18 @@ package ru.dbotthepony.kstarbound
|
|||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.kstarbound.defs.ClientConfigParameters
|
import ru.dbotthepony.kstarbound.defs.ClientConfigParameters
|
||||||
import ru.dbotthepony.kstarbound.defs.MovementParameters
|
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 ru.dbotthepony.kstarbound.util.AssetPathStack
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.ForkJoinPool
|
import java.util.concurrent.ForkJoinPool
|
||||||
import java.util.concurrent.ForkJoinTask
|
import java.util.concurrent.ForkJoinTask
|
||||||
|
import java.util.concurrent.Future
|
||||||
import kotlin.reflect.KMutableProperty0
|
import kotlin.reflect.KMutableProperty0
|
||||||
|
|
||||||
object GlobalDefaults {
|
object GlobalDefaults {
|
||||||
private val LOGGER = LogManager.getLogger()
|
private val LOGGER = LogManager.getLogger()
|
||||||
|
|
||||||
var playerMovementParameters = PlayerMovementParameters()
|
var actorMovementParameters = ActorMovementParameters()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var movementParameters = MovementParameters()
|
var movementParameters = MovementParameters()
|
||||||
@ -34,7 +36,7 @@ object GlobalDefaults {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T> load(path: String, accept: KMutableProperty0<T>, executor: ForkJoinPool): ForkJoinTask<*> {
|
private inline fun <reified T> load(path: String, accept: KMutableProperty0<T>, executor: ExecutorService): Future<*> {
|
||||||
val file = Starbound.locate(path)
|
val file = Starbound.locate(path)
|
||||||
|
|
||||||
if (!file.exists) {
|
if (!file.exists) {
|
||||||
@ -52,10 +54,10 @@ object GlobalDefaults {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun load(executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
fun load(executor: ExecutorService): List<Future<*>> {
|
||||||
val tasks = ArrayList<ForkJoinTask<*>>()
|
val tasks = ArrayList<Future<*>>()
|
||||||
|
|
||||||
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("/default_movement.config", ::movementParameters, executor))
|
||||||
tasks.add(load("/client.config", ::clientParameters, executor))
|
tasks.add(load("/client.config", ::clientParameters, executor))
|
||||||
|
|
||||||
|
@ -10,8 +10,10 @@ import ru.dbotthepony.kstarbound.util.KOptional
|
|||||||
import ru.dbotthepony.kstarbound.util.ParallelPerform
|
import ru.dbotthepony.kstarbound.util.ParallelPerform
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.ForkJoinPool
|
import java.util.concurrent.ForkJoinPool
|
||||||
import java.util.concurrent.ForkJoinTask
|
import java.util.concurrent.ForkJoinTask
|
||||||
|
import java.util.concurrent.Future
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
import java.util.concurrent.locks.ReentrantLock
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.concurrent.withLock
|
import kotlin.concurrent.withLock
|
||||||
@ -72,7 +74,7 @@ object RecipeRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun load(fileTree: Map<String, List<IStarboundFile>>, executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
fun load(fileTree: Map<String, List<IStarboundFile>>, executor: ExecutorService): List<Future<*>> {
|
||||||
val files = fileTree["recipe"] ?: return emptyList()
|
val files = fileTree["recipe"] ?: return emptyList()
|
||||||
|
|
||||||
val elements = Starbound.gson.getAdapter(JsonElement::class.java)
|
val elements = Starbound.gson.getAdapter(JsonElement::class.java)
|
||||||
|
@ -35,8 +35,10 @@ import ru.dbotthepony.kstarbound.defs.tile.LiquidDefinition
|
|||||||
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
|
import ru.dbotthepony.kstarbound.defs.tile.MaterialModifier
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
|
||||||
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
import ru.dbotthepony.kstarbound.util.AssetPathStack
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.ForkJoinPool
|
import java.util.concurrent.ForkJoinPool
|
||||||
import java.util.concurrent.ForkJoinTask
|
import java.util.concurrent.ForkJoinTask
|
||||||
|
import java.util.concurrent.Future
|
||||||
|
|
||||||
object Registries {
|
object Registries {
|
||||||
private val LOGGER = LogManager.getLogger()
|
private val LOGGER = LogManager.getLogger()
|
||||||
@ -96,11 +98,11 @@ object Registries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <reified T : Any> loadRegistry(
|
private inline fun <reified T : Any> loadRegistry(
|
||||||
executor: ForkJoinPool,
|
executor: ExecutorService,
|
||||||
registry: Registry<T>,
|
registry: Registry<T>,
|
||||||
files: List<IStarboundFile>,
|
files: List<IStarboundFile>,
|
||||||
noinline keyProvider: (T) -> Pair<String, Int?>
|
noinline keyProvider: (T) -> Pair<String, Int?>
|
||||||
): List<ForkJoinTask<*>> {
|
): List<Future<*>> {
|
||||||
val adapter by lazy { Starbound.gson.getAdapter(T::class.java) }
|
val adapter by lazy { Starbound.gson.getAdapter(T::class.java) }
|
||||||
val elementAdapter by lazy { Starbound.gson.getAdapter(JsonElement::class.java) }
|
val elementAdapter by lazy { Starbound.gson.getAdapter(JsonElement::class.java) }
|
||||||
|
|
||||||
@ -130,8 +132,8 @@ object Registries {
|
|||||||
registries.forEach { it.finishLoad() }
|
registries.forEach { it.finishLoad() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun load(fileTree: Map<String, List<IStarboundFile>>, executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
fun load(fileTree: Map<String, List<IStarboundFile>>, executor: ExecutorService): List<Future<*>> {
|
||||||
val tasks = ArrayList<ForkJoinTask<*>>()
|
val tasks = ArrayList<Future<*>>()
|
||||||
|
|
||||||
tasks.addAll(loadItemDefinitions(fileTree, executor))
|
tasks.addAll(loadItemDefinitions(fileTree, executor))
|
||||||
|
|
||||||
@ -155,7 +157,7 @@ object Registries {
|
|||||||
return tasks
|
return tasks
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadItemDefinitions(files: Map<String, Collection<IStarboundFile>>, executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
private fun loadItemDefinitions(files: Map<String, Collection<IStarboundFile>>, executor: ExecutorService): List<Future<*>> {
|
||||||
val fileMap = mapOf(
|
val fileMap = mapOf(
|
||||||
"item" to ItemDefinition::class.java,
|
"item" to ItemDefinition::class.java,
|
||||||
"currency" to CurrencyItemDefinition::class.java,
|
"currency" to CurrencyItemDefinition::class.java,
|
||||||
@ -169,7 +171,7 @@ object Registries {
|
|||||||
"back" to BackArmorItemDefinition::class.java,
|
"back" to BackArmorItemDefinition::class.java,
|
||||||
)
|
)
|
||||||
|
|
||||||
val tasks = ArrayList<ForkJoinTask<*>>()
|
val tasks = ArrayList<Future<*>>()
|
||||||
val objects = Starbound.gson.getAdapter(JsonObject::class.java)
|
val objects = Starbound.gson.getAdapter(JsonObject::class.java)
|
||||||
|
|
||||||
for ((ext, clazz) in fileMap) {
|
for ((ext, clazz) in fileMap) {
|
||||||
@ -195,7 +197,7 @@ object Registries {
|
|||||||
return tasks
|
return tasks
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadJsonFunctions(files: Collection<IStarboundFile>, executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
private fun loadJsonFunctions(files: Collection<IStarboundFile>, executor: ExecutorService): List<Future<*>> {
|
||||||
return files.map { listedFile ->
|
return files.map { listedFile ->
|
||||||
executor.submit {
|
executor.submit {
|
||||||
try {
|
try {
|
||||||
@ -216,7 +218,7 @@ object Registries {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadJson2Functions(files: Collection<IStarboundFile>, executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
private fun loadJson2Functions(files: Collection<IStarboundFile>, executor: ExecutorService): List<Future<*>> {
|
||||||
return files.map { listedFile ->
|
return files.map { listedFile ->
|
||||||
executor.submit {
|
executor.submit {
|
||||||
try {
|
try {
|
||||||
@ -237,7 +239,7 @@ object Registries {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadTreasurePools(files: Collection<IStarboundFile>, executor: ForkJoinPool): List<ForkJoinTask<*>> {
|
private fun loadTreasurePools(files: Collection<IStarboundFile>, executor: ExecutorService): List<Future<*>> {
|
||||||
return files.map { listedFile ->
|
return files.map { listedFile ->
|
||||||
executor.submit {
|
executor.submit {
|
||||||
try {
|
try {
|
||||||
|
@ -63,8 +63,10 @@ import java.io.*
|
|||||||
import java.lang.ref.Cleaner
|
import java.lang.ref.Cleaner
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.concurrent.CompletableFuture
|
import java.util.concurrent.CompletableFuture
|
||||||
|
import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.ForkJoinPool
|
import java.util.concurrent.ForkJoinPool
|
||||||
import java.util.concurrent.ForkJoinTask
|
import java.util.concurrent.ForkJoinTask
|
||||||
|
import java.util.concurrent.Future
|
||||||
import java.util.concurrent.locks.LockSupport
|
import java.util.concurrent.locks.LockSupport
|
||||||
import java.util.function.BiConsumer
|
import java.util.function.BiConsumer
|
||||||
import java.util.function.BinaryOperator
|
import java.util.function.BinaryOperator
|
||||||
@ -442,8 +444,8 @@ object Starbound : ISBFileLocator {
|
|||||||
|
|
||||||
checkMailbox()
|
checkMailbox()
|
||||||
|
|
||||||
val tasks = ArrayList<ForkJoinTask<*>>()
|
val tasks = ArrayList<Future<*>>()
|
||||||
val pool = if (parallel) ForkJoinPool.commonPool() else ForkJoinPool(1)
|
val pool = if (parallel) ForkJoinPool.commonPool() else Executors.newFixedThreadPool(1)
|
||||||
|
|
||||||
tasks.addAll(Registries.load(ext2files, pool))
|
tasks.addAll(Registries.load(ext2files, pool))
|
||||||
tasks.addAll(RecipeRegistry.load(ext2files, pool))
|
tasks.addAll(RecipeRegistry.load(ext2files, pool))
|
||||||
|
Loading…
Reference in New Issue
Block a user