From a9e6aab94cc33695de83fb8cac67692575c62047 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 6 Sep 2024 23:59:46 +0900 Subject: [PATCH] new worldgen test wip --- .../terrarum/modulebasegame/TerrarumIngame.kt | 6 +- .../modulebasegame/worldgenerator/Terragen.kt | 6 +- .../terrarum/tests/WorldgenNoiseSandbox.kt | 57 ++++++++++--------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt index 681ab83b1..b1ed081fb 100644 --- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt +++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt @@ -169,9 +169,9 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) { (this.hitbox.endX >= WorldCamera.x && this.hitbox.startX <= WorldCamera.xEnd)) val SIZE_SMALL = Point2i(CHUNK_W*66, CHUNK_H*60) - val SIZE_NORMAL = Point2i(CHUNK_W*100, CHUNK_H*64) - val SIZE_LARGE = Point2i(CHUNK_W*150, CHUNK_H*66) - val SIZE_HUGE = Point2i(CHUNK_W*250, CHUNK_H*70) + val SIZE_NORMAL = Point2i(CHUNK_W*100, CHUNK_H*60) + val SIZE_LARGE = Point2i(CHUNK_W*150, CHUNK_H*60) + val SIZE_HUGE = Point2i(CHUNK_W*250, CHUNK_H*60) val NEW_WORLD_SIZE = arrayOf(SIZE_SMALL, SIZE_NORMAL, SIZE_LARGE, SIZE_HUGE) val WORLDPORTAL_NEW_WORLD_SIZE = arrayOf(SIZE_SMALL, SIZE_NORMAL, SIZE_LARGE, SIZE_HUGE) diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt index 2eb621872..cd296c03b 100644 --- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt +++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Terragen.kt @@ -259,7 +259,7 @@ interface TerragenParams { } data class TerragenParamsAlpha1( - override val terragenTiers: List = listOf(.0, .5, 1.0, 2.5), + override val terragenTiers: List = listOf(.0, .5, 1.0, 2.5, 11.0), override val featureSize: Double = 333.0, override val lowlandScaleOffset: Double = -0.65, // linearly alters the height @@ -277,12 +277,10 @@ data class TerragenParamsAlpha1( override val caveBlockageSelectThre: Double = 1.40, // adjust cave closing-up strength. Lower = more closing override val rockBandCutoffFreq: Double = 4.0, - - ) : TerragenParams data class TerragenParamsAlpha2( - override val terragenTiers: List = listOf(.0, .5, 1.5, 3.75), + override val terragenTiers: List = listOf(.0, .5, 1.5, 3.75, 11.0), override val featureSize: Double = 333.0, override val lowlandScaleOffset: Double = -0.65, // linearly alters the height diff --git a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt index bf8127016..9332ff380 100644 --- a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt +++ b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt @@ -21,9 +21,7 @@ import com.sudoplay.joise.module.* import net.torvald.random.HQRNG import net.torvald.terrarum.* import net.torvald.terrarum.blockproperties.Block -import net.torvald.terrarum.concurrent.RunnableFun import net.torvald.terrarum.concurrent.ThreadExecutor -import net.torvald.terrarum.concurrent.sliceEvenly import net.torvald.terrarum.modulebasegame.worldgenerator.* import net.torvald.terrarum.worlddrawer.toRGBA import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap @@ -34,11 +32,14 @@ import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen.YHEIGHT_DIVIS import net.torvald.terrarum.modulebasegame.worldgenerator.Worldgen.YHEIGHT_MAGIC import java.io.PrintStream import java.util.Calendar +import java.util.concurrent.Callable -const val NOISEBOX_WIDTH = 1600 -const val NOISEBOX_HEIGHT = 2400 +const val NOISEBOX_WIDTH = 90 * 18 +const val NOISEBOX_HEIGHT = 90 * 26 const val TWO_PI = Math.PI * 2 +const val WORLDGEN_YOFF = 5400 - NOISEBOX_HEIGHT + /** * Created by minjaesong on 2019-07-23. */ @@ -204,28 +205,29 @@ class WorldgenNoiseSandbox : ApplicationAdapter() { worldgenDone = false Thread { - val runnables: List = (0 until testTex.width).sliceEvenly(genSlices).map { range -> - { - val localJoise = noiseMaker.getGenerator(seed, 0) - for (x in range) { - for (y in 0 until NOISEBOX_HEIGHT) { - val sampleTheta = (x.toDouble() / NOISEBOX_WIDTH) * TWO_PI - val sampleX = - sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only - val sampleZ = - cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled - val sampleY = getSY(y) //+ 10000 + val callables = ArrayList>() - noiseMaker.draw(x, y, localJoise.mapIndexed { index, it -> - it.get(sampleX, sampleY, sampleZ) - }, testTex) - } + for (cy in 0 until NOISEBOX_HEIGHT / 90) { for (cx in 0 until NOISEBOX_WIDTH / 90) { + val localJoise = noiseMaker.getGenerator(seed, 0) + callables.add(Callable { for (x in cx * 90 until (cx + 1) * 90) { + for (y in cy * 90 until (cy + 1) * 90) { + val sampleTheta = (x.toDouble() / NOISEBOX_WIDTH) * TWO_PI + val sampleX = + sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only + val sampleZ = + cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled + val sampleY = getSY(y) + WORLDGEN_YOFF + + noiseMaker.draw(x, y, localJoise.mapIndexed { index, joise -> + joise.get(sampleX, sampleY, sampleZ) + }, testTex) } - } - } + } }) + } } + threadExecutor.renew() - runnables.forEach { + callables.forEach { threadExecutor.submit(it) } @@ -350,9 +352,12 @@ internal class TerragenTest(val params: TerragenParams) : NoiseMaker { Color(0.97f, 0.6f, 0.56f, 1f) ) - private val groundDepthBlock = listOf( - Block.AIR, Block.DIRT, Block.STONE, Block.STONE_SLATE + private val groundDepthBlockWall = listOf( + Block.AIR, Block.DIRT, Block.STONE, Block.STONE_SLATE, Block.STONE_SLATE ) + private val groundDepthBlockTERR = ArrayList(groundDepthBlockWall).also { + it[it.lastIndex] = Block.AIR + } private fun Double.tiered(tiers: List): Int { tiers.reversed().forEachIndexed { index, it -> @@ -398,8 +403,8 @@ internal class TerragenTest(val params: TerragenParams) : NoiseMaker { val isMarble = false // noiseValue[13] > 0.5 - val wallBlock = if (isMarble) Block.STONE_MARBLE else groundDepthBlock[terr] - val terrBlock = if (cave == 0) Block.AIR else if (isMarble) Block.STONE_MARBLE else wallBlock + val wallBlock = if (isMarble) Block.STONE_MARBLE else groundDepthBlockWall[terr] + val terrBlock = if (cave == 0) Block.AIR else if (isMarble) Block.STONE_MARBLE else groundDepthBlockTERR[terr] outTex.drawPixel(x, y,