not-generated marker works as intended, reducing number of chunks for initial worldgen

This commit is contained in:
minjaesong
2024-07-11 16:17:38 +09:00
parent 7b6d7f2b93
commit 24e43edafb

View File

@@ -146,7 +146,7 @@ object Worldgen {
val start = (0.00342f * world.height - 3.22f).floorToInt().coerceAtLeast(1) val start = (0.00342f * world.height - 3.22f).floorToInt().coerceAtLeast(1)
// this value has to extend up, otherwise the player may spawn into the chopped-off mountaintop // this value has to extend up, otherwise the player may spawn into the chopped-off mountaintop
// this value has to extend down into the rock layer, otherwise, if the bottom of the bottom chunk is dirt, they will turn into grasses // this value has to extend down into the rock layer, otherwise, if the bottom of the bottom chunk is dirt, they will turn into grasses
return start - 1 to start + 7 return start to start + 5
} }
private val rockScoreMin = 40 private val rockScoreMin = 40
@@ -157,31 +157,38 @@ object Worldgen {
val tallies = ArrayList<Pair<Point2i, Vector3f>>() // xypos, score (0..1+) val tallies = ArrayList<Pair<Point2i, Vector3f>>() // xypos, score (0..1+)
var tries = 0 var tries = 0
var found = false var found = false
val ySearchRadius = 30
while (tries < 99) { while (tries < 99) {
val posX = (Math.random() * world.width).toInt() val posX = (Math.random() * world.width).toInt()
var posY = yInit * CHUNK_H var posY = yInit * CHUNK_H
// go up? // go up?
if (BlockCodex[world.getTileFromTerrain(posX, posY)].isSolid) { if (BlockCodex[world.getTileFromTerrain(posX, posY)].isSolid) {
// go up! // go up!
while (BlockCodex[world.getTileFromTerrain(posX, posY)].isSolid) { while (posY > ySearchRadius && BlockCodex[world.getTileFromTerrain(posX, posY)].isSolid) {
posY -= 1 posY -= 1
} }
} }
else { else {
// go down! // go down!
while (!BlockCodex[world.getTileFromTerrain(posX, posY)].isSolid) { while (posY < world.height - ySearchRadius && !BlockCodex[world.getTileFromTerrain(posX, posY)].isSolid) {
posY += 1 posY += 1
} }
} }
printdbg(this, "Trying spawn point #${tries + 1} at ($posX, $posY)") printdbg(this, "Trying spawn point #${tries + 1} at ($posX, $posY)")
if (posY !in ySearchRadius+1 until world.height - ySearchRadius) {
printdbg(this, "...Survey says: X=$posX has no floor")
tries += 1
continue
}
var rocks = 0 var rocks = 0
var trees = 0 var trees = 0
var flatness = 0 var flatness = 0
// make survey // make survey
for (sx in -80..80) { for (sx in -80..80) {
for (sy in -30..30) { for (sy in -ySearchRadius..ySearchRadius) {
val x = posX + sx val x = posX + sx
val y = posY + sy val y = posY + sy
val tile = BlockCodex[world.getTileFromTerrain(x, y)] val tile = BlockCodex[world.getTileFromTerrain(x, y)]