more randomised treegen; mixer view only updates when it's actually visible

This commit is contained in:
minjaesong
2023-11-22 16:07:07 +09:00
parent 7b77998749
commit bcd1b5c0c1
2 changed files with 60 additions and 73 deletions

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg import net.torvald.terrarum.App.printdbg
import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.concurrent.sliceEvenly import net.torvald.terrarum.concurrent.sliceEvenly
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.BlockAddress import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame import net.torvald.terrarum.modulebasegame.TerrarumIngame
@@ -213,14 +214,7 @@ class Treegen(world: GameWorld, seed: Long, val terragenParams: TerragenParams,
growCnt += 1 growCnt += 1
} }
// bulb 1 // bulb 1
for (i in 0 until bulb1) { growCnt = drawBulb(x, y, 3, bulb1, foliage, growCnt)
for (x in x-1..x+1) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
} }
else if (size == 1) { else if (size == 1) {
val heightSum = 5+3+2+1 val heightSum = 5+3+2+1
@@ -263,33 +257,11 @@ class Treegen(world: GameWorld, seed: Long, val terragenParams: TerragenParams,
} }
growCnt += 1 growCnt += 1
// bulb 1 // bulb 1
for (i in 0 until bulb1) { growCnt = drawBulb(x, y, 7, bulb1, foliage, growCnt)
for (x in x-3..x+3) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 2 // bulb 2
for (i in 0 until bulb2) { growCnt = drawBulb(x, y, 5, bulb2, foliage, growCnt)
for (x in x-2..x+2) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 3 // bulb 3
for (i in 0 until bulb3) { growCnt = drawBulb(x, y, 3, bulb3, foliage, growCnt)
for (x in x-1..x+1) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
} }
else if (size == 2) { else if (size == 2) {
val heightSum = 12+4+3+2+1 val heightSum = 12+4+3+2+1
@@ -314,14 +286,32 @@ class Treegen(world: GameWorld, seed: Long, val terragenParams: TerragenParams,
printdbg(this, "Planting tree at $x, $y; params: $stem, $bulb1, $bulb2, $bulb3") printdbg(this, "Planting tree at $x, $y; params: $stem, $bulb1, $bulb2, $bulb3")
// soiling // soiling
for (i in 1..2) { val tl1 = world.getTileFromTerrain(x - 1, y)
val tileLeft = world.getTileFromTerrain(x, y + i) val tl2 = world.getTileFromTerrain(x + 1, y)
val wallLeft = world.getTileFromWall(x, y + i) if (BlockCodex[tl2].hasTag("INCONSEQUENTIAL")) {
val tileRight = world.getTileFromTerrain(x + 1, y + i) world.setTileTerrain(x + 1, y, Block.GRASS, true)
if (tileRight != tileLeft) { /*
world.setTileTerrain(x + 1, y + i, tileLeft, true) Case 1
world.setTileWall(x + 1, y + i, wallLeft, true) WW WW
GG. -> GGG
xGx xDx
WW WW
xG. -> xGG
xG. xDG
*/
if (tl1 == Block.GRASS) {
world.setTileTerrain(x, y + 1, Block.DIRT, true)
if (BlockCodex[world.getTileFromTerrain(x + 1, y + 1)].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x + 1, y + 1, Block.DIRT, true)
} }
/*
Case 2
WW WW
.G. -> .GG
xGx xGx
*/
} }
// trunk // trunk
for (i in 0 until stem) { for (i in 0 until stem) {
@@ -351,45 +341,41 @@ class Treegen(world: GameWorld, seed: Long, val terragenParams: TerragenParams,
} }
growCnt += 1 growCnt += 1
// bulb 1 // bulb 1
for (i in 0 until bulb1) { growCnt = drawBulb(x, y, 10, bulb1, foliage, growCnt)
for (x in x-4..x+5) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 2 // bulb 2
for (i in 0 until bulb2) { growCnt = drawBulb(x, y, 8, bulb2, foliage, growCnt)
for (x in x-3..x+4) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 3 // bulb 3
for (i in 0 until bulb3) { growCnt = drawBulb(x, y, 6, bulb3, foliage, growCnt)
for (x in x-2..x+3) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
// bulb 4 // bulb 4
for (i in 0 until bulb4) { growCnt = drawBulb(x, y, 4, bulb4, foliage, growCnt)
for (x in x-1..x+2) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
} }
else throw IllegalArgumentException("Unknown tree size: $size") else throw IllegalArgumentException("Unknown tree size: $size")
} }
private fun drawBulb(x: Int, y: Int, width: Int, height: Int, foliage: ItemID, growCnt0: Int): Int {
var growCnt = growCnt0
val xStart = x - width / 2 + (1 - (width % 2))
val xEnd = xStart + width
var xStart2 = xStart
var xEnd2 = xEnd
Math.random().let {
if (it < 0.25) xStart2 += 1
else if (it < 0.5) xEnd2 -= 1
}
val xs1 = xStart until xEnd
val xs2 = xStart2 until xEnd2
for (i in 0 until height) {
for (x in if (i == height - 1 && i > 0) xs2 else xs1) {
val tileHere = world.getTileFromTerrain(x, y - growCnt)
if (BlockCodex[tileHere].hasTag("INCONSEQUENTIAL"))
world.setTileTerrain(x, y - growCnt, foliage, true)
}
growCnt += 1
}
return growCnt
}
/** /**
* Rearranges the list such that: * Rearranges the list such that:
* `1,2,3,4,5,6,7,8,9` * `1,2,3,4,5,6,7,8,9`

View File

@@ -138,12 +138,12 @@ class BasicDebugInfoWindow : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) { override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
TerrarumIngame.setCameraPosition(batch, App.shapeRender, camera, 0f, 0f) TerrarumIngame.setCameraPosition(batch, App.shapeRender, camera, 0f, 0f)
// toggle show-something // toggle show-something
showTimers = showTimers xor (Gdx.input.isKeyJustPressed(KEY_TIMERS) && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT)) showTimers = showTimers xor (Gdx.input.isKeyJustPressed(KEY_TIMERS) && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
showWeatherInfo = showWeatherInfo xor (Gdx.input.isKeyJustPressed(KEY_WEATHERS) && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT)) showWeatherInfo = showWeatherInfo xor (Gdx.input.isKeyJustPressed(KEY_WEATHERS) && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
showAudioMixer = showAudioMixer xor (Gdx.input.isKeyJustPressed(KEY_AUDIOMIXER) && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT)) showAudioMixer = showAudioMixer xor (Gdx.input.isKeyJustPressed(KEY_AUDIOMIXER) && Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
AudioMixer.masterTrack.filters[2].bypass = !showAudioMixer
drawMain(batch) drawMain(batch)
if (showTimers) drawTimers(batch) if (showTimers) drawTimers(batch)
@@ -867,6 +867,7 @@ class BasicDebugInfoWindow : UICanvas() {
} }
override fun endClosing(delta: Float) { override fun endClosing(delta: Float) {
AudioMixer.masterTrack.filters[2].bypass = true
} }
override fun dispose() { override fun dispose() {