sprite updates

Former-commit-id: a52e024a231e54e7e837b7c717606f4f0d187758
Former-commit-id: fcdb5a9e12802c9671bea24481c94a8876dfd418
This commit is contained in:
Song Minjae
2017-01-04 22:46:51 +09:00
parent e83ff16ebf
commit 1d160e54aa
6 changed files with 19 additions and 51 deletions

View File

@@ -1,28 +1,12 @@
package net.torvald.terrarum.concurrent
import net.torvald.terrarum.Terrarum
import java.util.*
/**
* Created by minjaesong on 16-05-25.
*/
object ThreadParallel {
val POOL_SIZE = Terrarum.THREADS + 1
private val pool: Array<Thread?> = Array(POOL_SIZE, { null })
/**
* Map array of Runnable objects to thread pool.
* @param prefix : will name each thread as "Foo-1"
* @param runnables : vararg
*/
fun mapAll(prefix: String, runnables: Array<Runnable>) {
if (runnables.size != POOL_SIZE)
throw RuntimeException("Thread pool argument size mismatch. If you have four cores, you must use four runnables.")
for (i in 0..runnables.size)
pool[i] = Thread(runnables[i], "$prefix-$i")
}
private val pool: Array<Thread?> = Array(Terrarum.THREADS, { null })
/**
* Map Runnable object to certain index of the thread pool.
@@ -34,18 +18,18 @@ object ThreadParallel {
pool[index] = Thread(runnable, "$prefix-$index")
}
/**
* Fill the thread pool with NULL value.
*/
fun purge() {
for (i in 0..POOL_SIZE)
pool[i] = null
}
/**
* Start all thread in the pool. If the thread in the pool is NULL, it will simply ignored.
*/
fun startAll() {
pool.forEach { it?.start() }
}
/**
* Primitive locking
*/
fun allFinished(): Boolean {
pool.forEach { if (it?.state != Thread.State.TERMINATED) return false }
return true
}
}