mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 16:46:07 +09:00
seamlessly looped terrain generation WIP (resolving issue #4)
Former-commit-id: cb2110fc1574ddfbff9ea6bd21596945c5895e13 Former-commit-id: 4f17d4d0bb1b1ed1ee61872651abfeb046de8b9c
This commit is contained in:
@@ -234,11 +234,11 @@ constructor(gamename: String) : StateBasedGame(gamename) {
|
|||||||
* 0xAA_BB_XXXX
|
* 0xAA_BB_XXXX
|
||||||
* AA: Major version
|
* AA: Major version
|
||||||
* BB: Minor version
|
* BB: Minor version
|
||||||
* XXXX: Revision
|
* XXXX: Revision (Repository commits)
|
||||||
*
|
*
|
||||||
* e.g. 0x02010034 can be translated as 2.1.52
|
* 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 =
|
const val VERSION_STRING: String =
|
||||||
"${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}"
|
"${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}"
|
||||||
const val NAME = "Terrarum"
|
const val NAME = "Terrarum"
|
||||||
|
|||||||
@@ -256,6 +256,8 @@ object WorldGenerator {
|
|||||||
return noiseArrayLocal
|
return noiseArrayLocal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val TWO_PI = Math.PI * 2.0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http://accidentalnoise.sourceforge.net/minecraftworlds.html
|
* http://accidentalnoise.sourceforge.net/minecraftworlds.html
|
||||||
*
|
*
|
||||||
@@ -405,11 +407,23 @@ object WorldGenerator {
|
|||||||
println("[mapgenerator] Raising and eroding terrain...")
|
println("[mapgenerator] Raising and eroding terrain...")
|
||||||
for (y in 0..(TERRAIN_UNDULATION - 1)) {
|
for (y in 0..(TERRAIN_UNDULATION - 1)) {
|
||||||
for (x in 0..WIDTH) {
|
for (x in 0..WIDTH) {
|
||||||
val map: Boolean = (
|
// straight-line sampling
|
||||||
|
/*val map: Boolean = (
|
||||||
joise.get(
|
joise.get(
|
||||||
x / SCALE_X,
|
x / SCALE_X,
|
||||||
y / SCALE_Y
|
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)
|
noiseMap[y + TERRAIN_AVERAGE_HEIGHT - (TERRAIN_UNDULATION / 2)].set(x, map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user