From da8d62076636d039354290c03042d2fa82ae32c8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 22 Aug 2023 02:55:31 +0900 Subject: [PATCH] clouds with just right depths --- assets/mods/basegame/commands.csv | 3 +- .../basegame/weathers/WeatherGeneric.json | 11 +++--- .../mods/basegame/weathers/cloud_normal.kra | 4 +-- .../mods/basegame/weathers/cloud_normal.png | 4 +-- src/net/torvald/terrarum/App.java | 4 +-- .../terrarum/modulebasegame/console/Uuid.kt | 22 ++++++++++++ .../terrarum/weather/BaseModularWeather.kt | 1 + .../torvald/terrarum/weather/WeatherMixer.kt | 34 +++++++++++++------ .../terrarum/weather/WeatherObjectCloud.kt | 2 +- 9 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/console/Uuid.kt diff --git a/assets/mods/basegame/commands.csv b/assets/mods/basegame/commands.csv index ec0392585..80b92454a 100644 --- a/assets/mods/basegame/commands.csv +++ b/assets/mods/basegame/commands.csv @@ -32,4 +32,5 @@ Teleport ToggleNoClip Zoom DynToStatic -DebugFillInventory \ No newline at end of file +DebugFillInventory +Uuid \ No newline at end of file diff --git a/assets/mods/basegame/weathers/WeatherGeneric.json b/assets/mods/basegame/weathers/WeatherGeneric.json index bd3b50e92..267e35124 100644 --- a/assets/mods/basegame/weathers/WeatherGeneric.json +++ b/assets/mods/basegame/weathers/WeatherGeneric.json @@ -2,17 +2,18 @@ "skyboxGradColourMap": "generic_skybox.tga", "daylightClut": "clut_daylight.tga", "classification": "generic", - "cloudChance": 10, - "cloudGamma": [0.59, 2.0], - "cloudDriftSpeed": 10.4, + "cloudChance": 20, + "cloudGamma": [0.48, 1.8], + "cloudGammaVariance": [0.1, 0.1], + "cloudDriftSpeed": 0.3, "clouds": { "large": { "filename": "cloud_large.png", - "tw": 2048, "th": 1024, "probability": 0.2, "baseScale": 0.45, "scaleVariance": 0.7 + "tw": 2048, "th": 1024, "probability": 0.2, "baseScale": 0.666, "scaleVariance": 0.7 }, "normal": { "filename": "cloud_normal.png", - "tw": 1024, "th": 512, "probability": 1.0, "baseScale": 0.5, "scaleVariance": 0.8 + "tw": 1024, "th": 512, "probability": 1.0, "baseScale": 0.75, "scaleVariance": 0.8 } } } \ No newline at end of file diff --git a/assets/mods/basegame/weathers/cloud_normal.kra b/assets/mods/basegame/weathers/cloud_normal.kra index 644b366f8..392cd4d50 100644 --- a/assets/mods/basegame/weathers/cloud_normal.kra +++ b/assets/mods/basegame/weathers/cloud_normal.kra @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a993447e75e5d9430b8e187befdf04eef1cb01ccd209785a8c2e25bc745a3f78 -size 2115503 +oid sha256:60b86bec9d98df8a6e3f89ce8f53f467b3bcc75a9ad06d71919f5eeaec4576fc +size 2106213 diff --git a/assets/mods/basegame/weathers/cloud_normal.png b/assets/mods/basegame/weathers/cloud_normal.png index 1f547d6b6..16ddbabd6 100644 --- a/assets/mods/basegame/weathers/cloud_normal.png +++ b/assets/mods/basegame/weathers/cloud_normal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:884594d5fbb8893edcba938ab82e33792c37e366dd2e8dad518b25ad0a65d580 -size 360226 +oid sha256:2704f4d5e1fdf54e9afcf3a1f4e6f396201c3f686c5f002f3f89e9ccf08c9f6e +size 358636 diff --git a/src/net/torvald/terrarum/App.java b/src/net/torvald/terrarum/App.java index e6e50a5aa..6a02ce4f8 100644 --- a/src/net/torvald/terrarum/App.java +++ b/src/net/torvald/terrarum/App.java @@ -269,8 +269,8 @@ public class App implements ApplicationListener { Gdx.gl20.glViewport(0, 0, width, height); } - public static final int TICKS = 64; - public static final float UPDATE_RATE = 1f / TICKS; // apparent framerate will be limited by update rate + public static final int TICK_SPEED = 64; + public static final float UPDATE_RATE = 1f / TICK_SPEED; // apparent framerate will be limited by update rate private static float loadTimer = 0f; private static final float showupTime = 100f / 1000f; diff --git a/src/net/torvald/terrarum/modulebasegame/console/Uuid.kt b/src/net/torvald/terrarum/modulebasegame/console/Uuid.kt new file mode 100644 index 000000000..cc3868cc1 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/console/Uuid.kt @@ -0,0 +1,22 @@ +package net.torvald.terrarum.modulebasegame.console + +import net.torvald.terrarum.INGAME +import net.torvald.terrarum.ccG +import net.torvald.terrarum.ccY +import net.torvald.terrarum.console.ConsoleCommand +import net.torvald.terrarum.console.Echo + +/** + * Created by minjaesong on 2023-08-22. + */ +object Uuid : ConsoleCommand { + override fun execute(args: Array) { + val worldUUID = INGAME.world.worldIndex + val playerUUID = INGAME.actorGamer.uuid + Echo("${ccY}World UUID: ${ccG}$worldUUID") + Echo("${ccY}Player UUID: ${ccG}$playerUUID") + } + + override fun printUsage() { + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/weather/BaseModularWeather.kt b/src/net/torvald/terrarum/weather/BaseModularWeather.kt index 5bc58acb7..226ec3b87 100644 --- a/src/net/torvald/terrarum/weather/BaseModularWeather.kt +++ b/src/net/torvald/terrarum/weather/BaseModularWeather.kt @@ -20,6 +20,7 @@ data class BaseModularWeather( val cloudChance: Float, val cloudDriftSpeed: Float, val cloudGamma: Vector2, + val cloudGammaVariance: Vector2, var clouds: List, // sorted by CloudProps.probability val mixFrom: String? = null, diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index d0176a4c1..9a0634f55 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -86,7 +86,7 @@ internal object WeatherMixer : RNGConsumer { private var astrumOffX = 0f private var astrumOffY = 0f - private val clouds = Array(256) { null } + private val clouds = Array(4096) { null } private var cloudsSpawned = 0 private var cloudDriftVector = Vector3(-1f, 0f, 1f) // this is a direction vector @@ -94,6 +94,7 @@ internal object WeatherMixer : RNGConsumer { override fun loadFromSave(s0: Long, s1: Long) { super.loadFromSave(s0, s1) internalReset(s0, s1) + initClouds() } fun internalReset() = internalReset(RNG.state0, RNG.state1) @@ -155,6 +156,7 @@ internal object WeatherMixer : RNGConsumer { 0f, 0f, Vector2(1f, 1f), + Vector2(0f, 0f), listOf() ) @@ -221,14 +223,14 @@ internal object WeatherMixer : RNGConsumer { private fun randomPosWithin(range: ClosedFloatingPointRange, random: Float) = ((range.start + range.endInclusive) / 2f) + random * (range.endInclusive - range.start) / 2f - private fun tryToSpawnCloud(currentWeather: BaseModularWeather) { + private fun tryToSpawnCloud(currentWeather: BaseModularWeather, initX: Float? = null) { printdbg(this, "Trying to spawn a cloud... (${cloudsSpawned} / ${clouds.size})") if (cloudsSpawned < clouds.size) { val flip = Math.random() < 0.5 val rC = Math.random().toFloat() - val rZ = (Math.random() * 3.0 + 1.0).toFloat() // 1..4 - val r0 = (Math.random() * 2.0 - 1.0).toFloat() // -1..1 + val rZ = (Math.random() * 9 + 1.0).toFloat() // 1..10 uniformly + val rY = ((Math.random() + Math.random()) - 1.0).toFloat() // -1..1 val r1 = (Math.random() * 2.0 - 1.0).toFloat() // -1..1 val r2 = (Math.random() * 2.0 - 1.0).toFloat() // -1..1 val rT1 = ((Math.random() + Math.random()) - 1.0).toFloat() // -1..1 @@ -249,11 +251,11 @@ internal object WeatherMixer : RNGConsumer { cloudsToSpawn?.let { cloud -> val scaleVariance = 1f + rT1.absoluteValue * cloud.scaleVariance val cloudScale = cloud.baseScale * (if (rT1 < 0) 1f / scaleVariance else scaleVariance) - val hCloudSize = (cloud.spriteSheet.tileW * cloudScale) + 1f - val posX = if (cloudDriftVector.x < 0) (App.scr.width + hCloudSize) * rZ else -hCloudSize * rZ + val hCloudSize = (cloud.spriteSheet.tileW * cloudScale) / 2f + 1f + val posX = if (initX != null) initX * rZ else if (cloudDriftVector.x < 0) (App.scr.width + hCloudSize) * rZ else -hCloudSize * rZ val posY = when (cloud.category) { - "large" -> randomPosWithin(-10f..120f, r0) * scrHscaler - else -> randomPosWithin(-50f..150f, r0) * scrHscaler // -50..150 + "large" -> randomPosWithin(-120f..120f, rY) * scrHscaler * (rZ * 0.5f) + else -> randomPosWithin(-150f..150f, rY) * scrHscaler * (rZ * 0.5f) } val sheetX = rA % cloud.spriteSheet.horizontalCount val sheetY = rB % cloud.spriteSheet.verticalCount @@ -262,8 +264,12 @@ internal object WeatherMixer : RNGConsumer { it.darkness.set(currentWeather.cloudGamma) it.darkness.x *= it.scale - it.darkness.x *= 1f + r1 * 0.1f - it.darkness.y *= 1f + r2 * 0.1f + + val varX = 1f + r1.absoluteValue * currentWeather.cloudGammaVariance.x + val varY = 1f + r2.absoluteValue * currentWeather.cloudGammaVariance.y + + it.darkness.x *= if (r1 < 0) 1f / varX else varX + it.darkness.y *= if (r2 < 0) 1f / varY else varY it.posX = posX it.posY = posY @@ -280,6 +286,13 @@ internal object WeatherMixer : RNGConsumer { } } + private fun initClouds() { + repeat((currentWeather.cloudChance * 6.8f).ceilToInt()) { // multiplier is an empirical value that depends on the 'rZ' + tryToSpawnCloud(currentWeather, ((Math.random() * 2.0 - 1.0) * App.scr.wf).toFloat()) + } + + } + private fun Array.addAtFreeSpot(obj: T) { var c = 0 while (true) { @@ -566,6 +579,7 @@ internal object WeatherMixer : RNGConsumer { cloudChance = JSON.getFloat("cloudChance"), cloudDriftSpeed = JSON.getFloat("cloudDriftSpeed"), cloudGamma = JSON["cloudGamma"].asFloatArray().let { Vector2(it[0], it[1]) }, + cloudGammaVariance = JSON["cloudGammaVariance"].asFloatArray().let { Vector2(it[0], it[1]) }, clouds = cloudsMap, ) } diff --git a/src/net/torvald/terrarum/weather/WeatherObjectCloud.kt b/src/net/torvald/terrarum/weather/WeatherObjectCloud.kt index 1d9259144..832f92953 100644 --- a/src/net/torvald/terrarum/weather/WeatherObjectCloud.kt +++ b/src/net/torvald/terrarum/weather/WeatherObjectCloud.kt @@ -47,7 +47,7 @@ class WeatherObjectCloud(private val texture: TextureRegion, private val flipW: val y = posY + offsetY - texture.regionHeight * scale val z = posZ // must be at least 1.0 val w = App.scr.halfwf - val h = App.scr.halfhf // 50% to the screen height, or 35%? + val h = App.scr.hf * 0.35f val drawX = (x + w * (z-1)) / z val drawY = (y + h * (z-1)) / z