From d3dd879dd523db03ff8c398e85329df88eae6632 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Tue, 20 Dec 2016 21:01:22 +0900 Subject: [PATCH] seamlessly looped terrain generation WIP (resolving issue #4) Former-commit-id: cb2110fc1574ddfbff9ea6bd21596945c5895e13 Former-commit-id: 4f17d4d0bb1b1ed1ee61872651abfeb046de8b9c --- src/net/torvald/terrarum/Terrarum.kt | 4 ++-- .../terrarum/mapgenerator/WorldGenerator.kt | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index 651008b1f..e40af8051 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -234,11 +234,11 @@ constructor(gamename: String) : StateBasedGame(gamename) { * 0xAA_BB_XXXX * AA: Major version * BB: Minor version - * XXXX: Revision + * XXXX: Revision (Repository commits) * * e.g. 0x02010034 can be translated as 2.1.52 */ - const val VERSION_RAW = 0x0002006D + const val VERSION_RAW = 0x000200E1 const val VERSION_STRING: String = "${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}" const val NAME = "Terrarum" diff --git a/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt b/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt index 60930fb34..967a3db85 100644 --- a/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt +++ b/src/net/torvald/terrarum/mapgenerator/WorldGenerator.kt @@ -256,6 +256,8 @@ object WorldGenerator { return noiseArrayLocal } + private val TWO_PI = Math.PI * 2.0 + /** * http://accidentalnoise.sourceforge.net/minecraftworlds.html * @@ -405,11 +407,23 @@ object WorldGenerator { println("[mapgenerator] Raising and eroding terrain...") for (y in 0..(TERRAIN_UNDULATION - 1)) { for (x in 0..WIDTH) { - val map: Boolean = ( + // straight-line sampling + /*val map: Boolean = ( joise.get( x / SCALE_X, y / SCALE_Y - ) == 1.0) + ) == 1.0)*/ + // circular sampling + // Mapping function: + // World(x, y) -> Joise(sin x, y, cos x) + val sampleTheta = (x.toDouble() / WIDTH) * TWO_PI + val sampleOffset = (WIDTH / SCALE_X) / 4.0 + val sampleX = Math.sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only + val sampleZ = Math.cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled + val sampleY = y / SCALE_Y + val map: Boolean = ( + joise.get(sampleX, sampleY, sampleZ) == 1.0 + ) noiseMap[y + TERRAIN_AVERAGE_HEIGHT - (TERRAIN_UNDULATION / 2)].set(x, map) } }