TilePropCodex is now object, torch flicker (WIP as all the torches are in unison)

Former-commit-id: df9c0e3a9ace2ba976da5e81f1f2d2217db541a0
Former-commit-id: 81a25a938023f318937e1f4ded15e6047fdf8864
This commit is contained in:
Song Minjae
2016-06-17 01:39:55 +09:00
parent 9f42ae9639
commit c4ad69525b
20 changed files with 347 additions and 206 deletions

View File

@@ -7,15 +7,17 @@ import java.util.*
* Created by minjaesong on 16-05-25.
*/
object ThreadPool {
private val pool = Array<Thread>(Terrarum.CORES, { Thread() })
val POOL_SIZE = Terrarum.CORES
val POOL_SIZE = Terrarum.CORES + 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, vararg runnables: Runnable) {
if (runnables.size != Terrarum.CORES)
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)
@@ -23,6 +25,7 @@ object ThreadPool {
}
/**
* Map Runnable object to certain index of the thread pool.
* @param index of the runnable
* @param runnable
* @param prefix Will name each thread like "Foo-1", "Foo-2", etc.
@@ -31,7 +34,18 @@ object ThreadPool {
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() }
pool.forEach { it?.start() }
}
}