mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
cavegen candidate 0
This commit is contained in:
@@ -10,7 +10,7 @@ typealias ThreadableFun = (Int) -> Unit
|
||||
* Created by minjaesong on 2016-05-25.
|
||||
*/
|
||||
object ThreadParallel {
|
||||
val threadCount = Runtime.getRuntime().availableProcessors() + 1 // modify this to your taste
|
||||
val threadCount = Runtime.getRuntime().availableProcessors() // not using (logicalCores + 1) method; it's often better idea to reserve one extra thread for other jobs in the app
|
||||
|
||||
private val pool: Array<Thread?> = Array(threadCount) { null }
|
||||
|
||||
@@ -206,5 +206,14 @@ fun IntProgression.sliceEvenly(slices: Int): List<IntProgression> {
|
||||
}
|
||||
}
|
||||
|
||||
fun IntProgression.mapToThreadPoolDirectly(prefix: String, worker: (IntProgression) -> Unit) {
|
||||
this.sliceEvenly(ThreadParallel.threadCount).forEachIndexed { index, intProgression ->
|
||||
val workerFun: ThreadableFun = {
|
||||
worker(intProgression)
|
||||
}
|
||||
ThreadParallel.map(index, prefix, workerFun)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private inline fun Float.roundInt(): Int = Math.round(this)
|
||||
Reference in New Issue
Block a user