new thread pooling strategy and test program WIP

This commit is contained in:
Minjae Song
2018-12-14 22:53:25 +09:00
parent 6f49dcff4b
commit 513c5a17eb
8 changed files with 231 additions and 32 deletions

View File

@@ -869,7 +869,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
private fun insertionSortLastElemAV(arr: ArrayList<ActorWithBody>) { // out-projection doesn't work, duh
lock(ReentrantLock()) {
ReentrantLock().lock {
var j = arr.lastIndex - 1
val x = arr.last()
while (j >= 0 && arr[j] > x) {

View File

@@ -9,6 +9,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_DYNAMIC
import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
import net.torvald.terrarum.itemproperties.ItemID
import net.torvald.terrarum.lock
import net.torvald.terrarum.modulebasegame.Ingame
import java.util.*
import java.util.concurrent.locks.Lock
@@ -253,7 +254,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
return itemList[index]
}
private fun insertionSortLastElem(arr: ArrayList<InventoryPair>) {
lock(ReentrantLock()) {
ReentrantLock().lock {
var j = arr.lastIndex - 1
val x = arr.last()
while (j >= 0 && arr[j].item > x.item) {
@@ -284,15 +285,6 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
}
return -(low + 1) // key not found
}
inline fun lock(lock: Lock, body: () -> Unit) {
lock.lock()
try {
body()
}
finally {
lock.unlock()
}
}
}
data class InventoryPair(val item: GameItem, var amount: Int)

View File

@@ -76,8 +76,8 @@ object WorldSimulator {
fun moveFluids(delta: Float) {
makeFluidMapFromWorld()
//simCompression()
for (y in 1 until fluidMap.size - 1) {
simCompression()
/*for (y in 1 until fluidMap.size - 1) {
for (x in 1 until fluidMap[0].size - 1) {
val worldX = x + updateXFrom
val worldY = y + updateYFrom
@@ -98,7 +98,7 @@ object WorldSimulator {
fluidNewMap[y + 1][x] += remainingMass
}
}
}
}*/
fluidmapToWorld()
}