From 040261dbfea66d4d8190e8c31dfe1f8620be2e93 Mon Sep 17 00:00:00 2001 From: Krisztian Gergely Date: Mon, 4 Jan 2016 17:03:11 +0100 Subject: [PATCH 1/2] noFPSReduction parameter for G3MWidget_Android --- .../glob3/mobile/specific/ES2Renderer.java | 41 +++++++++---------- .../mobile/specific/G3MBuilder_Android.java | 7 +--- .../mobile/specific/G3MWidget_Android.java | 19 +++++++-- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java index 01aa480640..04d779a47f 100644 --- a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java +++ b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java @@ -62,29 +62,28 @@ public void onDrawFrame(final GL10 glUnused) { final G3MWidget widget = _widgetAndroid.getG3MWidget(); widget.render(_width, _height); - // experimental FPS reduction - DGD - final long now = System.currentTimeMillis(); - final long timeElapsedInRender = now - _startTime; - final long timeLeftInMS = GOAL_MS_PER_FRAME - timeElapsedInRender; - if (timeLeftInMS > 0) { - // System.gc(); - // - // timeElapsedInRender = System.currentTimeMillis() - _startTime; - // timeLeftInMS = GOAL_MS_PER_FRAME - timeElapsedInRender; - // if (timeLeftInMS > 0) { - try { - //ILogger.instance().logInfo("**** sleeping OpenGL thread for " + timeLeftInMS + "ms"); - Thread.sleep(timeLeftInMS); + if (!_widgetAndroid.getNoFPSReduction()) { + // experimental FPS reduction - DGD + final long now = System.currentTimeMillis(); + final long timeElapsedInRender = now - _startTime; + final long timeLeftInMS = GOAL_MS_PER_FRAME - timeElapsedInRender; + if (timeLeftInMS > 0) { + // System.gc(); + // + // timeElapsedInRender = System.currentTimeMillis() - _startTime; + // timeLeftInMS = GOAL_MS_PER_FRAME - timeElapsedInRender; + // if (timeLeftInMS > 0) { + try { + //ILogger.instance().logInfo("**** sleeping OpenGL thread for " + timeLeftInMS + "ms"); + Thread.sleep(timeLeftInMS); + } catch (final InterruptedException e) { + } + // } + _startTime = System.currentTimeMillis(); + } else { + _startTime = now; } - catch (final InterruptedException e) { - } - // } - _startTime = System.currentTimeMillis(); - } - else { - _startTime = now; } - } diff --git a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java index 0b37e865a0..d2e3d8a883 100644 --- a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java +++ b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java @@ -19,11 +19,10 @@ public class G3MBuilder_Android private final G3MWidget_Android _nativeWidget; - - public G3MBuilder_Android(final Context context) { + public G3MBuilder_Android(final Context context, final boolean noFPSReduction) { super(); - _nativeWidget = new G3MWidget_Android(context); + _nativeWidget = new G3MWidget_Android(context, noFPSReduction); } @@ -91,6 +90,4 @@ protected IDownloader createDefaultDownloader() { getStorage(), // saveInBackground); } - - } diff --git a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java index 2adfed7374..2f20b36831 100644 --- a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java +++ b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java @@ -61,7 +61,7 @@ public final class G3MWidget_Android private final OnDoubleTapListener _doubleTapListener; private final GestureDetector _gestureDetector; private Thread _openGLThread = null; - + private final boolean _noFPSReduction; public G3MWidget_Android(final android.content.Context context) { this(context, null); @@ -83,11 +83,22 @@ public final void checkOpenGLThread() { } } + public G3MWidget_Android(final android.content.Context context, + final boolean noFPSReduction) { + this(context, null, noFPSReduction); + } // Needed to create widget from XML layout public G3MWidget_Android(final android.content.Context context, - final AttributeSet attrs) { + final AttributeSet attrs) { + this(context, attrs, false); + } + + public G3MWidget_Android(final android.content.Context context, + final AttributeSet attrs, + final boolean noFPSReduction) { super(context, attrs); + _noFPSReduction = noFPSReduction; initSingletons(); @@ -453,5 +464,7 @@ public G3MContext getG3MContext() { return getG3MWidget().getG3MContext(); } - + public boolean getNoFPSReduction() { + return _noFPSReduction; + } } From 05f7050e143063de8b62e5e8fa7f5ded60924c70 Mon Sep 17 00:00:00 2001 From: Krisztian Gergely Date: Wed, 25 May 2016 13:33:14 +0200 Subject: [PATCH 2/2] tweakable fps reduction in builder_android --- .../glob3/mobile/specific/ES2Renderer.java | 2 +- .../mobile/specific/G3MBuilder_Android.java | 14 ++++++++-- .../mobile/specific/G3MWidget_Android.java | 26 +++++++------------ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java index 04d779a47f..3a30eb8f54 100644 --- a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java +++ b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/ES2Renderer.java @@ -62,7 +62,7 @@ public void onDrawFrame(final GL10 glUnused) { final G3MWidget widget = _widgetAndroid.getG3MWidget(); widget.render(_width, _height); - if (!_widgetAndroid.getNoFPSReduction()) { + if (_widgetAndroid.getFPSReduction()) { // experimental FPS reduction - DGD final long now = System.currentTimeMillis(); final long timeElapsedInRender = now - _startTime; diff --git a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java index d2e3d8a883..abbadc819e 100644 --- a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java +++ b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MBuilder_Android.java @@ -19,10 +19,10 @@ public class G3MBuilder_Android private final G3MWidget_Android _nativeWidget; - public G3MBuilder_Android(final Context context, final boolean noFPSReduction) { + public G3MBuilder_Android(final Context context) { super(); - _nativeWidget = new G3MWidget_Android(context, noFPSReduction); + _nativeWidget = new G3MWidget_Android(context); } @@ -90,4 +90,14 @@ protected IDownloader createDefaultDownloader() { getStorage(), // saveInBackground); } + + /** + * Sets the _FPSReduction + * + * @param FPSReduction + */ + public final void setFPSReduction(boolean FPSReduction) + { + _nativeWidget.setFPSReduction(FPSReduction); + } } diff --git a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java index 2f20b36831..2bec7f3446 100644 --- a/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java +++ b/Android/G3MAndroidSDK/src/org/glob3/mobile/specific/G3MWidget_Android.java @@ -61,7 +61,7 @@ public final class G3MWidget_Android private final OnDoubleTapListener _doubleTapListener; private final GestureDetector _gestureDetector; private Thread _openGLThread = null; - private final boolean _noFPSReduction; + private boolean _FPSReduction; public G3MWidget_Android(final android.content.Context context) { this(context, null); @@ -83,22 +83,12 @@ public final void checkOpenGLThread() { } } - public G3MWidget_Android(final android.content.Context context, - final boolean noFPSReduction) { - this(context, null, noFPSReduction); - } - // Needed to create widget from XML layout public G3MWidget_Android(final android.content.Context context, - final AttributeSet attrs) { - this(context, attrs, false); - } - - public G3MWidget_Android(final android.content.Context context, - final AttributeSet attrs, - final boolean noFPSReduction) { + final AttributeSet attrs) { super(context, attrs); - _noFPSReduction = noFPSReduction; + + _FPSReduction = true; initSingletons(); @@ -464,7 +454,11 @@ public G3MContext getG3MContext() { return getG3MWidget().getG3MContext(); } - public boolean getNoFPSReduction() { - return _noFPSReduction; + public void setFPSReduction(boolean FPSReduction) { + _FPSReduction = FPSReduction; + } + + public boolean getFPSReduction() { + return _FPSReduction; } }