seamlessly looped terrain generation WIP (resolving issue #4)

Former-commit-id: cb2110fc1574ddfbff9ea6bd21596945c5895e13
Former-commit-id: 4f17d4d0bb1b1ed1ee61872651abfeb046de8b9c
This commit is contained in:
Song Minjae
2016-12-20 21:01:22 +09:00
parent 7c84566623
commit d3dd879dd5
2 changed files with 18 additions and 4 deletions

View File

@@ -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"

View File

@@ -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)
}
}