Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
obigu committed Oct 16, 2020
1 parent 939088c commit 1e64e40
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -514,7 +511,7 @@ public long getFrameId () {
/** {@inheritDoc} */
@Override
public float getDeltaTime () {
return mean.getMean() == 0 ? deltaTime : mean.getMean();
return deltaTime;
}

@Override
Expand Down Expand Up @@ -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();
}
}

Expand Down
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions gdx/src/com/badlogic/gdx/Graphics.java
Expand Up @@ -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 */
Expand Down

0 comments on commit 1e64e40

Please sign in to comment.