mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 05:54:05 +09:00
now the sunstone and the daylight capacitor are also managed by TilePropUtil, added field "dlfn" in tileprop.csv
Former-commit-id: 7dfec6896031f89eb1f0de062303485bee8ee5f4 Former-commit-id: 0fae44e4b200248997ab873e415e9d7bce8de2e4
This commit is contained in:
@@ -3,6 +3,7 @@ package net.torvald.terrarum.tileproperties
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gamemap.WorldTime
|
||||
import net.torvald.terrarum.mapdrawer.LightmapRenderer
|
||||
|
||||
/**
|
||||
@@ -12,19 +13,18 @@ object TilePropUtil {
|
||||
var flickerFuncX = 0 // in milliseconds; saves current status of func
|
||||
val flickerFuncDomain = 100 // time between two noise sample, in milliseconds
|
||||
val flickerFuncRange = 0.012f // intensity [0, 1]
|
||||
//val torchIntensityOffset = -0.04f
|
||||
|
||||
val random = HQRNG();
|
||||
var funcY = 0f
|
||||
|
||||
var patternThis = getNewPattern()
|
||||
var patternNext = getNewPattern()
|
||||
var patternThis = getNewRandom()
|
||||
var patternNext = getNewRandom()
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
fun getTorchFlicker(baseLum: Int): Int {
|
||||
private fun getTorchFlicker(baseLum: Int): Int {
|
||||
funcY = linearInterpolation1D(patternThis, patternNext,
|
||||
flickerFuncX.toFloat() / flickerFuncDomain
|
||||
)
|
||||
@@ -32,7 +32,15 @@ object TilePropUtil {
|
||||
return LightmapRenderer.brightenUniform(baseLum, funcY)
|
||||
}
|
||||
|
||||
fun torchFlickerTickClock() {
|
||||
private fun getSlowBreath(baseLum: Int): Int {
|
||||
return baseLum
|
||||
}
|
||||
|
||||
private fun getPulsate(baseLum: Int): Int {
|
||||
return baseLum
|
||||
}
|
||||
|
||||
internal fun dynamicLumFuncTickClock() {
|
||||
if (Terrarum.appgc.fps > 0)
|
||||
flickerFuncX += 1000 / Terrarum.appgc.fps
|
||||
|
||||
@@ -40,19 +48,22 @@ object TilePropUtil {
|
||||
flickerFuncX -= flickerFuncDomain
|
||||
|
||||
patternThis = patternNext
|
||||
patternNext = getNewPattern()
|
||||
patternNext = getNewRandom()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNewPattern(): Float = random.nextFloat().times(2).minus(1f) * flickerFuncRange
|
||||
private fun getNewRandom() = random.nextFloat().times(2).minus(1f) * flickerFuncRange
|
||||
|
||||
private fun cosineInterpolation1D(a: Float, b: Float, x: Float): Float{
|
||||
val ft: Float = x * FastMath.PI;
|
||||
val f: Float = (1 - FastMath.cos(ft)) * 0.5f;
|
||||
private fun linearInterpolation1D(a: Float, b: Float, x: Float) = a * (1 - x) + b * x;
|
||||
|
||||
return a * (1 - f) + b * f;
|
||||
fun getDynamicLumFunc(baseLum: Int, type: Int): Int {
|
||||
return when (type) {
|
||||
1 -> getTorchFlicker(baseLum)
|
||||
2 -> Terrarum.game.map.globalLight // current global light
|
||||
3 -> Terrarum.game.globalLightByTime(WorldTime.DAY_LENGTH / 2) // daylight at noon
|
||||
4 -> getSlowBreath(baseLum)
|
||||
5 -> getPulsate(baseLum)
|
||||
else -> baseLum
|
||||
}
|
||||
}
|
||||
|
||||
private fun linearInterpolation1D(a: Float, b: Float, x: Float) =
|
||||
a * (1 - x) + b * x;
|
||||
}
|
||||
Reference in New Issue
Block a user