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

Commit 856bfb2d authored by Michel Comin Escude's avatar Michel Comin Escude
Browse files

Fix time constants

With the previous CL, a mistake was added
that made nothing animate. Fixing it.

Flag: EXEMPT MP apk not in build yet
Bug: 355683834
Test: visual
Change-Id: I7d8fc0a585453a1ebee565420628799464664d6d
parent e32fdad2
Loading
Loading
Loading
Loading
+3 −2
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 com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils
import java.util.concurrent.TimeUnit
import kotlin.math.sin
import kotlin.random.Random
@@ -48,9 +49,9 @@ class FogEffect(
    override fun resize(newSurfaceSize: SizeF) = adjustCropping(newSurfaceSize)

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

        val time = TimeUnit.NANOSECONDS.toSeconds(frameTimeNanos)
        val time = TimeUtils.nanosToSeconds(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
+2 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ 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 com.google.android.wallpaper.weathereffects.graphics.utils.SolidColorShader
import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils
import java.util.concurrent.Executor
import java.util.concurrent.TimeUnit
import kotlin.random.Random
@@ -62,7 +63,7 @@ class RainEffect(
    override fun resize(newSurfaceSize: SizeF) = adjustCropping(newSurfaceSize)

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

        rainConfig.rainShowerShader.setFloatUniform("time", elapsedTime)
        rainConfig.glassRainShader.setFloatUniform("time", elapsedTime)
+2 −2
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ 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 com.google.android.wallpaper.weathereffects.graphics.utils.MathUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils
import java.util.concurrent.Executor
import java.util.concurrent.TimeUnit
import kotlin.random.Random

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

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

        snowConfig.shader.setFloatUniform("time", elapsedTime)
        snowConfig.colorGradingShader.setInputShader("texture", snowConfig.shader)
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.android.wallpaper.weathereffects.graphics.utils

/** Contains functions related to time. */
object TimeUtils {
    private const val MILLIS_TO_SECONDS = 1 / 1_000f
    private const val NANOS_TO_SECONDS = 1 / 1_000_000_000f

    /** Converts milliseconds to decimal seconds. */
    fun millisToSeconds(millis: Long): Float = millis * MILLIS_TO_SECONDS

    /** Converts nanoseconds to decimal seconds. */
    fun nanosToSeconds(nanos: Long): Float = nanos * NANOS_TO_SECONDS
}