mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
multithreaded initial spawn chunkgen
This commit is contained in:
@@ -215,6 +215,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
IngameRenderer.setRenderedWorld(demoWorld)
|
||||
WeatherMixer.internalReset(this)
|
||||
WeatherMixer.titleScreenInitWeather(demoWorld.weatherbox)
|
||||
WeatherMixer.forceTimeAt = 23456
|
||||
|
||||
|
||||
// load a half-gradient texture that would be used throughout the titlescreen and its sub UIs
|
||||
|
||||
@@ -55,7 +55,7 @@ class Biomegen(world: GameWorld, isFinal: Boolean, seed: Long, params: Any, val
|
||||
|
||||
companion object {
|
||||
private const val slices = 5
|
||||
private val nearbyArr = arrayOf(
|
||||
private val nearbyArr8 = arrayOf(
|
||||
(-1 to -1), // tileTL
|
||||
(+1 to -1), // tileTR
|
||||
(-1 to +1), // tileBL
|
||||
@@ -65,14 +65,25 @@ class Biomegen(world: GameWorld, isFinal: Boolean, seed: Long, params: Any, val
|
||||
(-1 to 0), // tileL
|
||||
(+1 to 0) // tileR
|
||||
)
|
||||
private const val TL = 0
|
||||
private const val TR = 1
|
||||
private const val BL = 2
|
||||
private const val BR = 3
|
||||
private const val TP = 4
|
||||
private const val BT = 5
|
||||
private const val LF = 6
|
||||
private const val RH = 7
|
||||
private val nearbyArr4 = arrayOf(
|
||||
(0 to -1), // tileT
|
||||
(0 to +1), // tileB
|
||||
(-1 to 0), // tileL
|
||||
(+1 to 0) // tileR
|
||||
)
|
||||
private const val TL8 = 0
|
||||
private const val TR8 = 1
|
||||
private const val BL8 = 2
|
||||
private const val BR8 = 3
|
||||
private const val TP8 = 4
|
||||
private const val BT8 = 5
|
||||
private const val LF8 = 6
|
||||
private const val RH8 = 7
|
||||
|
||||
private const val TP4 = 0
|
||||
private const val BT4 = 1
|
||||
private const val LF4 = 2
|
||||
private const val RH4 = 3
|
||||
|
||||
/* Biome key format:
|
||||
|
||||
@@ -109,10 +120,10 @@ class Biomegen(world: GameWorld, isFinal: Boolean, seed: Long, params: Any, val
|
||||
if (y > 0) {
|
||||
val tileThis = world.getTileFromTerrain(x, y)
|
||||
val wallThis = world.getTileFromWall(x, y)
|
||||
val nearbyTerr = nearbyArr.map { world.getTileFromTerrain(x + it.first, y + it.second) }
|
||||
val nearbyWall = nearbyArr.map { world.getTileFromWall(x + it.first, y + it.second) }
|
||||
val nearbyTerr = nearbyArr8.map { world.getTileFromTerrain(x + it.first, y + it.second) }
|
||||
val nearbyWall = nearbyArr8.map { world.getTileFromWall(x + it.first, y + it.second) }
|
||||
val exposedToAir = nearbyTerr.any { it == Block.AIR } && nearbyWall.any { it == Block.AIR }
|
||||
val hasNoFloor = (nearbyTerr[BT] == Block.AIR)
|
||||
val hasNoFloor = (nearbyTerr[BT8] == Block.AIR)
|
||||
|
||||
val grassRock = when (control1) {
|
||||
0 -> { // woodlands
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.realestate.LandUtil
|
||||
import net.torvald.terrarum.realestate.LandUtil.CHUNK_H
|
||||
import net.torvald.terrarum.realestate.LandUtil.CHUNK_W
|
||||
import java.util.concurrent.Callable
|
||||
import kotlin.experimental.and
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.roundToLong
|
||||
@@ -119,7 +120,8 @@ object Worldgen {
|
||||
val pcx = spawnX / CHUNK_W
|
||||
val pcy = spawnY / CHUNK_H
|
||||
App.getLoadScreen().addMessage(Lang["MENU_IO_WORLDGEN_CLEANING_UP"])
|
||||
listOf(
|
||||
|
||||
val chunkgenJobs = listOf(
|
||||
Point2iMod(pcx - 1, pcy - 2), Point2iMod(pcx, pcy - 2), Point2iMod(pcx + 1, pcy - 2),
|
||||
Point2iMod(pcx - 2, pcy - 1), Point2iMod(pcx - 1, pcy - 1), Point2iMod(pcx, pcy - 1), Point2iMod(pcx + 1, pcy - 1), Point2iMod(pcx + 2, pcy - 1),
|
||||
Point2iMod(pcx - 2, pcy), Point2iMod(pcx - 1, pcy), Point2iMod(pcx + 1, pcy), Point2iMod(pcx + 2, pcy),
|
||||
@@ -128,10 +130,14 @@ object Worldgen {
|
||||
).filter { it.y in 0 until world.height }.filter { (cx, cy) ->
|
||||
if (cy !in 0 until world.height / CHUNK_H) false
|
||||
else (world.chunkFlags[cy][cx].and(0x7F) == 0.toByte())
|
||||
}.forEach { (cx, cy) ->
|
||||
Worldgen.generateChunkIngame(cx, cy, true) { cx, cy -> }
|
||||
}.map { (cx, cy) ->
|
||||
Callable { generateChunkIngame(cx, cy, true) { cx, cy -> } }
|
||||
}
|
||||
|
||||
Worldgen.threadExecutor.renew()
|
||||
threadExecutor.submitAll(chunkgenJobs)
|
||||
Worldgen.threadExecutor.join()
|
||||
|
||||
|
||||
val tDiff = System.nanoTime() - t1
|
||||
printdbg(this, "Generation job finished; time took: ${tDiff / 1000000000.0} seconds, bogoflops: ${App.bogoflops}")
|
||||
|
||||
Reference in New Issue
Block a user