torch should flicker less erratic now

This commit is contained in:
minjaesong
2023-08-30 12:39:56 +09:00
parent 9d118aebb0
commit d32d6b8d1c
5 changed files with 69 additions and 4 deletions

View File

@@ -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

View File

@@ -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],

View File

@@ -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<WeatherStateBox> {
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])
}
}
})
}

View File

@@ -90,6 +90,9 @@ internal object WeatherMixer : RNGConsumer {
private var astrumOffY = 0f
private val clouds = SortedArrayList<WeatherObjectCloud>()
// val weatherbox: Weatherbox
var cloudsSpawned = 0; private set
private var windVector = Vector3(-1f, 0f, 0.1f) // this is a direction vector
val cloudSpawnMax: Int

View File

@@ -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)
}
}
}