|
@@ -75,7 +75,8 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
|
|
protected SystemListener listener;
|
|
protected SystemListener listener;
|
|
protected boolean autoFlush = true;
|
|
protected boolean autoFlush = true;
|
|
protected AndroidInputHandler androidInput;
|
|
protected AndroidInputHandler androidInput;
|
|
- protected int minFrameDuration = 0; // No FPS cap
|
|
|
|
|
|
+ protected long minFrameDuration = 0; // No FPS cap
|
|
|
|
+ protected long lastUpdateTime = 0;
|
|
protected JoyInput androidSensorJoyInput = null;
|
|
protected JoyInput androidSensorJoyInput = null;
|
|
|
|
|
|
public OGLESContext() {
|
|
public OGLESContext() {
|
|
@@ -225,6 +226,12 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
|
|
androidInput.loadSettings(settings);
|
|
androidInput.loadSettings(settings);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (settings.getFrameRate() > 0) {
|
|
|
|
+ minFrameDuration = (long)(1000d / (double)settings.getFrameRate()); // ms
|
|
|
|
+ logger.log(Level.FINE, "Setting min tpf: {0}ms", minFrameDuration);
|
|
|
|
+ } else {
|
|
|
|
+ minFrameDuration = 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -320,23 +327,25 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
|
|
throw new IllegalStateException("onDrawFrame without create");
|
|
throw new IllegalStateException("onDrawFrame without create");
|
|
}
|
|
}
|
|
|
|
|
|
- long milliStart = System.currentTimeMillis();
|
|
|
|
-
|
|
|
|
listener.update();
|
|
listener.update();
|
|
if (autoFlush) {
|
|
if (autoFlush) {
|
|
renderer.onFrame();
|
|
renderer.onFrame();
|
|
}
|
|
}
|
|
|
|
|
|
- long milliDelta = System.currentTimeMillis() - milliStart;
|
|
|
|
|
|
+ long updateDelta = System.currentTimeMillis() - lastUpdateTime;
|
|
|
|
|
|
// Enforce a FPS cap
|
|
// Enforce a FPS cap
|
|
- if (milliDelta < minFrameDuration) {
|
|
|
|
- //logger.log(Level.FINE, "Time per frame {0}", milliDelta);
|
|
|
|
|
|
+ if (updateDelta < minFrameDuration) {
|
|
|
|
+// logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
|
|
|
|
+// new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
|
|
try {
|
|
try {
|
|
- Thread.sleep(minFrameDuration - milliDelta);
|
|
|
|
|
|
+ Thread.sleep(minFrameDuration - updateDelta);
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ lastUpdateTime = System.currentTimeMillis();
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|