thread pooling terraingen, WIP

Former-commit-id: 1d0687d8b34d5e8192b652904a437cdb29f27b10
Former-commit-id: 1c06ce97a59eb13455cc180a4d5f13ffbead1f84
This commit is contained in:
Song Minjae
2016-06-13 00:48:37 +09:00
parent f98cd773b1
commit 9f42ae9639
8 changed files with 180 additions and 46 deletions

View File

@@ -0,0 +1,46 @@
package net.torvald.terrarum.mapgenerator
/**
* Created by minjaesong on 16-06-13.
*/
class ThreadProcessNoiseLayers(val startIndex: Int, val endIndex: Int,
val noiseRecords: Array<MapGenerator.TaggedJoise>) : Runnable {
override fun run() {
for (record in noiseRecords) {
println("[mapgenerator] ${record.message}...")
for (y in startIndex..endIndex) {
for (x in 0..MapGenerator.WIDTH - 1) {
val noise: Float = record.noiseModule.get(
x.toDouble() / 48.0, // 48: Fixed value
y.toDouble() / 48.0
).toFloat()
val fromTerr = record.replaceFromTerrain
val fromWall = record.replaceFromWall
val to: Int = when (record.replaceTo) {
// replace to designated tile
is Int -> record.replaceTo as Int
// replace to randomly selected tile from given array of tile IDs
is IntArray -> (record.replaceTo as IntArray)[MapGenerator.random.nextInt((record.replaceTo as IntArray).size)]
else -> throw IllegalArgumentException("[mapgenerator] Unknown replaceTo tile type '${record.replaceTo.javaClass.canonicalName}': Only 'kotlin.Int' and 'kotlin.IntArray' is valid.")
}
// replace to ALL? this is bullshit
if (to == MapGenerator.TILE_MACRO_ALL) throw IllegalArgumentException("[mapgenerator] Invalid replaceTo: TILE_MACRO_ALL")
// filtered threshold
val threshold = record.filter.getGrad(y, record.filterArg1, record.filterArg2)
if (noise > threshold * record.scarcity) {
if ((MapGenerator.map.getTileFromTerrain(x, y) == fromTerr || fromTerr == MapGenerator.TILE_MACRO_ALL)
&& (MapGenerator.map.getTileFromWall(x, y) == fromWall || fromWall == MapGenerator.TILE_MACRO_ALL)) {
MapGenerator.map.setTileTerrain(x, y, to)
}
}
}
}
}
}
}