Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e32fdad2 authored by Michel Comin Escude's avatar Michel Comin Escude
Browse files

Remove unnecessary time constants

Flag: EXEMPT MP apk not in build yet
Bug: 355683834
Test: visual
Change-Id: Ia826b5852750cba24b0a87d250e9c2ba8fb11d14
parent 4bc12a07
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.SizeF
import com.google.android.wallpaper.weathereffects.graphics.WeatherEffect
import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.ImageCrop
import java.util.concurrent.TimeUnit
import kotlin.math.sin
import kotlin.random.Random

@@ -47,9 +48,9 @@ class FogEffect(
    override fun resize(newSurfaceSize: SizeF) = adjustCropping(newSurfaceSize)

    override fun update(deltaMillis: Long, frameTimeNanos: Long) {
        val deltaTime = deltaMillis * MILLIS_TO_SECONDS
        val deltaTime = TimeUnit.MILLISECONDS.toSeconds(deltaMillis)

        val time = frameTimeNanos.toFloat() * NANOS_TO_SECONDS
        val time = TimeUnit.NANOSECONDS.toSeconds(frameTimeNanos)
        // Variation range [0.4, 1]. We don't want the variation to be 0.
        val variation = sin(0.06f * time + sin(0.18f * time)) * 0.3f + 0.7f
        elapsedTime += variation * deltaTime
@@ -180,10 +181,4 @@ class FogEffect(
        }
        fogConfig.colorGradingShader.setFloatUniform("intensity", fogConfig.colorGradingIntensity)
    }

    private companion object {

        private const val MILLIS_TO_SECONDS = 1 / 1000f
        private const val NANOS_TO_SECONDS = 1 / 1_000_000_000f
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.ImageCrop
import com.google.android.wallpaper.weathereffects.graphics.utils.SolidColorShader
import java.util.concurrent.Executor
import java.util.concurrent.TimeUnit
import kotlin.random.Random

/** Defines and generates the rain weather effect animation. */
@@ -61,7 +62,7 @@ class RainEffect(
    override fun resize(newSurfaceSize: SizeF) = adjustCropping(newSurfaceSize)

    override fun update(deltaMillis: Long, frameTimeNanos: Long) {
        elapsedTime += deltaMillis * MILLIS_TO_SECONDS
        elapsedTime += TimeUnit.MILLISECONDS.toSeconds(deltaMillis)

        rainConfig.rainShowerShader.setFloatUniform("time", elapsedTime)
        rainConfig.glassRainShader.setFloatUniform("time", elapsedTime)
@@ -189,8 +190,4 @@ class RainEffect(
            )
        }
    }

    private companion object {
        private const val MILLIS_TO_SECONDS = 1 / 1000f
    }
}
+2 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.ImageCrop
import com.google.android.wallpaper.weathereffects.graphics.utils.MathUtils
import java.util.concurrent.Executor
import java.util.concurrent.TimeUnit
import kotlin.random.Random

/** Defines and generates the rain weather effect animation. */
@@ -65,7 +66,7 @@ class SnowEffect(
    }

    override fun update(deltaMillis: Long, frameTimeNanos: Long) {
        elapsedTime += snowSpeed * deltaMillis * MILLIS_TO_SECONDS
        elapsedTime += snowSpeed * TimeUnit.MILLISECONDS.toSeconds(deltaMillis)

        snowConfig.shader.setFloatUniform("time", elapsedTime)
        snowConfig.colorGradingShader.setInputShader("texture", snowConfig.shader)
@@ -201,8 +202,4 @@ class SnowEffect(
        val gridSize = GraphicsUtils.computeDefaultGridSize(surfaceSize, snowConfig.pixelDensity)
        snowConfig.shader.setFloatUniform("gridSize", 7 * gridSize, 2f * gridSize)
    }

    private companion object {
        private const val MILLIS_TO_SECONDS = 1 / 1000f
    }
}