From 1e64e40088e079087d455489de6bcb8463307592 Mon Sep 17 00:00:00 2001 From: obigu Date: Fri, 16 Oct 2020 09:30:42 +0200 Subject: [PATCH] Fix #6228 --- .../gdx/backends/android/AndroidGraphics.java | 12 ++++-------- .../android/AndroidGraphicsLiveWallpaper.java | 6 ++---- gdx/src/com/badlogic/gdx/Graphics.java | 6 ++++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java index 6858e35709c..aca9fff5f92 100644 --- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java +++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java @@ -76,7 +76,6 @@ public class AndroidGraphics implements Graphics, Renderer { protected long frameId = -1; protected int frames = 0; protected int fps; - protected WindowedMean mean = new WindowedMean(5); volatile boolean created = false; volatile boolean running = false; @@ -304,7 +303,6 @@ public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLCo Display display = app.getWindowManager().getDefaultDisplay(); this.width = display.getWidth(); this.height = display.getHeight(); - this.mean = new WindowedMean(5); this.lastFrameTime = System.nanoTime(); gl.glViewport(0, 0, this.width, this.height); @@ -406,15 +404,14 @@ void destroy () { @Override public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) { long time = System.nanoTime(); - deltaTime = (time - lastFrameTime) / 1000000000.0f; - lastFrameTime = time; - // After pause deltaTime can have somewhat huge value that destabilizes the mean, so let's cut it off if (!resume) { - mean.addValue(deltaTime); + deltaTime = (time - lastFrameTime) / 1000000000.0f; } else { deltaTime = 0; } + lastFrameTime = time; + boolean lrunning = false; boolean lpause = false; @@ -514,7 +511,7 @@ public long getFrameId () { /** {@inheritDoc} */ @Override public float getDeltaTime () { - return mean.getMean() == 0 ? deltaTime : mean.getMean(); + return deltaTime; } @Override @@ -720,7 +717,6 @@ public void setContinuousRendering (boolean isContinuous) { this.isContinuous = enforceContinuousRendering || isContinuous; int renderMode = this.isContinuous ? GLSurfaceView.RENDERMODE_CONTINUOUSLY : GLSurfaceView.RENDERMODE_WHEN_DIRTY; view.setRenderMode(renderMode); - mean.clear(); } } diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphicsLiveWallpaper.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphicsLiveWallpaper.java index fcf9d11b13b..8b33caa4772 100644 --- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphicsLiveWallpaper.java +++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphicsLiveWallpaper.java @@ -111,15 +111,13 @@ void resume () { @Override public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) { long time = System.nanoTime(); - deltaTime = (time - lastFrameTime) / 1000000000.0f; - lastFrameTime = time; - // After pause deltaTime can have somewhat huge value that destabilizes the mean, so let's cut it off if (!resume) { - mean.addValue(deltaTime); + deltaTime = (time - lastFrameTime) / 1000000000.0f; } else { deltaTime = 0; } + lastFrameTime = time; boolean lrunning = false; boolean lpause = false; diff --git a/gdx/src/com/badlogic/gdx/Graphics.java b/gdx/src/com/badlogic/gdx/Graphics.java index db24753d24d..89925ab626a 100644 --- a/gdx/src/com/badlogic/gdx/Graphics.java +++ b/gdx/src/com/badlogic/gdx/Graphics.java @@ -180,10 +180,12 @@ public String toString () { * @return the id of the current frame */ public long getFrameId (); - /** @return the time span between the current frame and the last frame in seconds. Might be smoothed over n frames. */ + /** @return the time span between the current frame and the last frame in seconds. */ public float getDeltaTime (); - /** @return the time span between the current frame and the last frame in seconds, without smoothing **/ + /** @return the time span between the current frame and the last frame in seconds, without smoothing + * @deprecated use {@link #getDeltaTime()} instead. */ + @Deprecated public float getRawDeltaTime (); /** @return the average number of frames per second */