Fix fps issue when certain animation intervals are set, such as (1 / 30). (#2162)

This commit is contained in:
RH 2024-09-19 01:10:29 +10:00 committed by GitHub
parent 1de06414cc
commit ef5204385b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 12 deletions

View File

@ -38,6 +38,7 @@ public class AxmolRenderer implements GLSurfaceView.Renderer {
// The final animation interval which is used in 'onDrawFrame'
private static long sAnimationInterval = (long) (1.0f / 60f * AxmolRenderer.NANOSECONDSPERSECOND);
private static float FPS_CONTROL_THRESHOLD = 1.0f / 1200.0f * AxmolRenderer.NANOSECONDSPERSECOND;
// ===========================================================
// Fields
@ -91,19 +92,15 @@ public class AxmolRenderer implements GLSurfaceView.Renderer {
@Override
public void onDrawFrame(final GL10 gl) {
/*
* Fix 60fps limiting doesn't work when high-end device is working in 120fps mode.
* Render time MUST be counted in, or the FPS will slower than appointed.
*/
if (AxmolRenderer.sAnimationInterval <= 1.0f / 1200.0f * AxmolRenderer.NANOSECONDSPERSECOND) {
AxmolRenderer.nativeRender();
} else {
final long now = System.nanoTime();
final long interval = now - this.mLastTickInNanoSeconds;
/*
* Render time MUST be counted in, or the FPS will slower than appointed.
*/
this.mLastTickInNanoSeconds = now;
AxmolRenderer.nativeRender();
AxmolRenderer.nativeRender();
/*
* No need to use algorithm in default(60,90,120... FPS) situation,
* since onDrawFrame() was called by system 60 times per second by default.
*/
if (AxmolRenderer.sAnimationInterval > AxmolRenderer.FPS_CONTROL_THRESHOLD) {
final long interval = System.nanoTime() - this.mLastTickInNanoSeconds;
if (interval < AxmolRenderer.sAnimationInterval) {
try {
@ -111,6 +108,8 @@ public class AxmolRenderer implements GLSurfaceView.Renderer {
} catch (final Exception e) {
}
}
this.mLastTickInNanoSeconds = System.nanoTime();
}
}