From d32d6b8d1caf0cf0772990317ad2463a69dffd33 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 30 Aug 2023 12:39:56 +0900 Subject: [PATCH] torch should flicker less erratic now --- .../terrarum/blockproperties/BlockPropUtil.kt | 6 +-- .../terrarum/modulebasegame/TitleScreen.kt | 4 +- src/net/torvald/terrarum/serialise/Common.kt | 13 +++++ .../torvald/terrarum/weather/WeatherMixer.kt | 3 ++ .../torvald/terrarum/weather/Weatherbox.kt | 47 +++++++++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/net/torvald/terrarum/weather/Weatherbox.kt diff --git a/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt b/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt index 833b8f010..33d8b0533 100644 --- a/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt +++ b/src/net/torvald/terrarum/blockproperties/BlockPropUtil.kt @@ -13,7 +13,7 @@ import net.torvald.terrarum.weather.WeatherMixer */ object BlockPropUtil { //var flickerFuncX: Second = 0f // saves current status (time) of func - val flickerFuncDomain: Second = 0.06f // time between two noise sample + val flickerFuncDomain: Second = 8f/64f // time between two noise sample val flickerFuncRange = 0.036f // intensity [0, 1] //var breathFuncX = 0f @@ -50,7 +50,7 @@ object BlockPropUtil { /** - * Using our own timer so that they flickers for same duration regardless of game's FPS + * Must be using ConsistentUpdateRate update governor */ internal fun dynamicLumFuncTickClock() { @@ -80,7 +80,7 @@ object BlockPropUtil { // FPS-time compensation if (Gdx.graphics.framesPerSecond > 0) { - prop.rngBase0 += Gdx.graphics.deltaTime + prop.rngBase0 += App.UPDATE_RATE } // reset timer diff --git a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt index 3c6bd1489..15270f8c1 100644 --- a/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt +++ b/src/net/torvald/terrarum/modulebasegame/TitleScreen.kt @@ -36,6 +36,8 @@ import net.torvald.terrarum.serialise.ReadSimpleWorld import net.torvald.terrarum.ui.Toolkit import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.weather.WeatherMixer +import net.torvald.terrarum.weather.WeatherStateBox +import net.torvald.terrarum.weather.Weatherbox import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.util.CircularArray import java.io.IOException @@ -82,7 +84,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) { val xperc: Double = (x - xwstart) / xw // return FastMath.interpolateLinear(xperc.toFloat(), cameraNodes[indexThis fmod cameraNodes.size], cameraNodes[(indexThis + 1) fmod cameraNodes.size]).toDouble() - return FastMath.interpolateCatmullRom(xperc.toFloat(), + return FastMath.interpolateCatmullRom(xperc.toFloat(), 1.0f, // somehow T=1 works really well thanks to my other smoothing technique cameraNodes[(indexThis - 1) fmod cameraNodes.size], cameraNodes[(indexThis - 0) fmod cameraNodes.size], cameraNodes[(indexThis + 1) fmod cameraNodes.size], diff --git a/src/net/torvald/terrarum/serialise/Common.kt b/src/net/torvald/terrarum/serialise/Common.kt index d48f2f126..4c1cc2b82 100644 --- a/src/net/torvald/terrarum/serialise/Common.kt +++ b/src/net/torvald/terrarum/serialise/Common.kt @@ -14,6 +14,7 @@ import net.torvald.terrarum.savegame.ByteArray64GrowableOutputStream import net.torvald.terrarum.savegame.ByteArray64InputStream import net.torvald.terrarum.savegame.ByteArray64Reader import net.torvald.terrarum.utils.* +import net.torvald.terrarum.weather.WeatherStateBox import org.apache.commons.codec.digest.DigestUtils import java.io.File import java.io.InputStream @@ -213,6 +214,18 @@ object Common { return if (jsonData.isNull) return null else strToBytes(StringReader(jsonData.asString())).toByteArray() } }) + // WeatherStateBox + jsoner.setSerializer(WeatherStateBox::class.java, object : Json.Serializer { + override fun write(json: Json, obj: WeatherStateBox, knownType: Class<*>?) { + json.writeValue("${obj.x};${obj.p0};${obj.p1};${obj.p2};${obj.p3}") + } + + override fun read(json: Json, jsonData: JsonValue, type: Class<*>?): WeatherStateBox { + return jsonData.asString().split(';').map { it.toDouble() }.let { + WeatherStateBox(it[0], it[1], it[2], it[3], it[4]) + } + } + }) } diff --git a/src/net/torvald/terrarum/weather/WeatherMixer.kt b/src/net/torvald/terrarum/weather/WeatherMixer.kt index 211b1f8c5..31b33395b 100644 --- a/src/net/torvald/terrarum/weather/WeatherMixer.kt +++ b/src/net/torvald/terrarum/weather/WeatherMixer.kt @@ -90,6 +90,9 @@ internal object WeatherMixer : RNGConsumer { private var astrumOffY = 0f private val clouds = SortedArrayList() + +// val weatherbox: Weatherbox + var cloudsSpawned = 0; private set private var windVector = Vector3(-1f, 0f, 0.1f) // this is a direction vector val cloudSpawnMax: Int diff --git a/src/net/torvald/terrarum/weather/Weatherbox.kt b/src/net/torvald/terrarum/weather/Weatherbox.kt new file mode 100644 index 000000000..67a7d3891 --- /dev/null +++ b/src/net/torvald/terrarum/weather/Weatherbox.kt @@ -0,0 +1,47 @@ +package net.torvald.terrarum.weather + +import com.jme3.math.FastMath +import net.torvald.random.HQRNG +import java.util.* + +class Weatherbox { + + val RNG: HQRNG + get() = WeatherMixer.RNG + + + +} + + +data class WeatherStateBox(var x: Double, var p0: Double, var p1: Double, var p2: Double, var p3: Double) { + + fun get() = interpolateCatmullRom(x, p0, p1, p2, p3) + + fun getAndUpdate(xdelta: Double, RNG: Random): Double { + synchronized(RNG) { + val y = get() + x += xdelta + while (x >= 1.0) { + x -= 1.0 + p0 = p1 + p1 = p2 + p2 = p3 + p3 = RNG.nextDouble() + } + return y + } + } + + companion object { + // fixed with T=0.5 + fun interpolateCatmullRom(u: Double, p0: Double, p1: Double, p2: Double, p3: Double): Double { + val c1: Double = p1 + val c2: Double = -0.5 * p0 + 0.5 * p2 + val c3: Double = p0 - 2.5 * p1 + 2.0 * p2 - 0.5 * p3 + val c4: Double = -0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3 + return (((c4 * u + c3) * u + c2) * u + c1) + } + + } +} \ No newline at end of file