mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
volume randomiser for smelter and furnace
This commit is contained in:
@@ -106,6 +106,10 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
spawnTimer += delta
|
||||
|
||||
|
||||
// update sound randomiser
|
||||
volRand.update(delta)
|
||||
|
||||
|
||||
// manage audio
|
||||
getTrackByAudio(static).let {
|
||||
if (it != null && !it.isPlaying) {
|
||||
@@ -118,11 +122,12 @@ class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
|
||||
if (it.filters[filterIndex] !is Gain) // just in case...
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
|
||||
(it.filters[filterIndex] as Gain).gain = 0.4f // TODO randomsied undulation
|
||||
(it.filters[filterIndex] as Gain).gain = 0.4f * volRand.get()
|
||||
}
|
||||
}
|
||||
|
||||
@Transient private val filterIndex = 0
|
||||
@Transient private val volRand = ParamRandomiser(0.8f, 0.4f)
|
||||
|
||||
override fun dispose() {
|
||||
super.dispose()
|
||||
|
||||
@@ -248,10 +248,10 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
}
|
||||
|
||||
fun setJitter(it: TerrarumAudioMixerTrack?, mode: Int, intensity: Float) {
|
||||
it?.let {
|
||||
it.processor.jitterMode = mode
|
||||
it.processor.jitterIntensity = intensity
|
||||
}
|
||||
// it?.let {
|
||||
// it.processor.jitterMode = mode
|
||||
// it.processor.jitterIntensity = intensity
|
||||
// }
|
||||
}
|
||||
|
||||
fun unloadConvolver(actor: Actor, filterIndex: Int, music: MusicContainer?) {
|
||||
@@ -263,10 +263,10 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
}
|
||||
|
||||
fun unsetJitter(actor: Actor, music: MusicContainer?) {
|
||||
actor.musicTracks[music]?.let {
|
||||
it.processor.jitterMode = 0
|
||||
it.processor.jitterIntensity = 0f
|
||||
}
|
||||
// actor.musicTracks[music]?.let {
|
||||
// it.processor.jitterMode = 0
|
||||
// it.processor.jitterIntensity = 0f
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.spriteanimation.SheetSpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.MusicContainer
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
@@ -289,6 +289,9 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
spawnTimer = 0f
|
||||
|
||||
|
||||
// update sound randomiser
|
||||
volRand.update(delta)
|
||||
|
||||
|
||||
// manage audio
|
||||
getTrackByAudio(static).let {
|
||||
@@ -307,12 +310,13 @@ class FixtureSmelterBasic : FixtureBase, CraftingStation {
|
||||
if (it.filters[filterIndex] !is Gain) // just in case...
|
||||
it.filters[filterIndex] = Gain(0f)
|
||||
|
||||
(it.filters[filterIndex] as Gain).gain = (it.maxVolume * temperature).toFloat() // TODO randomsied undulation
|
||||
(it.filters[filterIndex] as Gain).gain = (it.maxVolume * temperature * volRand.get()).toFloat()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Transient private val filterIndex = 0
|
||||
@Transient private val volRand = ParamRandomiser(0.8f, 0.4f)
|
||||
|
||||
override fun dispose() {
|
||||
super.dispose()
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.jme3.math.FastMath
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-02-12.
|
||||
*/
|
||||
class ParamRandomiser(val base: Float, val mult: Float) {
|
||||
|
||||
@Transient private var rngBase0 = Math.random().toFloat() // initial cycle phase (xxxxFuncX)
|
||||
@Transient private var rngBase1 = getNewRandom() // flicker P0, etc
|
||||
@Transient private var rngBase2 = getNewRandom() // flicker P1, etc
|
||||
@Transient private val domain = 18f/64f
|
||||
|
||||
private fun getNewRandom() = base + Math.random().toFloat() * mult
|
||||
|
||||
fun update(delta: Float) {
|
||||
// FPS-time compensation
|
||||
if (Gdx.graphics.framesPerSecond > 0) {
|
||||
rngBase0 += delta
|
||||
}
|
||||
|
||||
// reset timer
|
||||
if (rngBase0 > domain) {
|
||||
rngBase0 -= domain
|
||||
|
||||
// flicker related
|
||||
rngBase1 = rngBase2
|
||||
rngBase2 = getNewRandom()
|
||||
}
|
||||
}
|
||||
fun get(): Float {
|
||||
val funcY = FastMath.interpolateLinear(rngBase0 / domain, rngBase1, rngBase2)
|
||||
return funcY
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user