aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
index 01c2ea664..a6ba74665 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java
@@ -30,7 +30,12 @@ package com.jogamp.opengl.util;
import com.jogamp.common.util.locks.RecursiveLock;
import jogamp.opengl.Debug;
+import jogamp.opengl.FPSCounterImpl;
+
+import java.io.PrintStream;
import java.util.ArrayList;
+
+import javax.media.opengl.FPSCounter;
import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLProfile;
@@ -61,9 +66,7 @@ public abstract class AnimatorBase implements GLAnimatorControl {
protected Thread animThread;
protected boolean ignoreExceptions;
protected boolean printExceptions;
- protected long startTime;
- protected long curTime;
- protected int totalFrames;
+ protected FPSCounterImpl fpsCounter = new FPSCounterImpl();
protected RecursiveLock stateSync = new RecursiveLock();
/** Creates a new, empty Animator. */
@@ -83,7 +86,6 @@ public abstract class AnimatorBase implements GLAnimatorControl {
baseName = baseName.concat("-"+animatorCount);
drawablesEmpty = true;
}
- resetCounter();
}
protected abstract String getBaseName(String prefix);
@@ -138,25 +140,48 @@ public abstract class AnimatorBase implements GLAnimatorControl {
lightweight widgets are continually being redrawn. */
protected void display() {
impl.display(drawables, ignoreExceptions, printExceptions);
- curTime = System.currentTimeMillis();
- totalFrames++;
+ fpsCounter.tickFPS();
+ }
+
+ public final void setUpdateFPSFrames(int frames, PrintStream out) {
+ fpsCounter.setUpdateFPSFrames(frames, out);
+ }
+
+ public final void resetFPSCounter() {
+ fpsCounter.resetFPSCounter();
}
- public long getCurrentTime() {
- return curTime;
+ public final int getUpdateFPSFrames() {
+ return fpsCounter.getUpdateFPSFrames();
+ }
+
+ public final long getFPSStartTime() {
+ return fpsCounter.getFPSStartTime();
}
- public long getDuration() {
- return curTime - startTime;
+ public final long getLastFPSUpdateTime() {
+ return fpsCounter.getLastFPSUpdateTime();
}
- public long getStartTime() {
- return startTime;
+ public final long getLastFPSPeriod() {
+ return fpsCounter.getLastFPSPeriod();
+ }
+
+ public final float getLastFPS() {
+ return fpsCounter.getLastFPS();
+ }
+
+ public final int getTotalFPSFrames() {
+ return fpsCounter.getTotalFPSFrames();
}
- public int getTotalFrames() {
- return totalFrames;
+ public final long getTotalFPSDuration() {
+ return fpsCounter.getTotalFPSDuration();
}
+
+ public final float getTotalFPS() {
+ return fpsCounter.getTotalFPS();
+ }
public final Thread getThread() {
stateSync.lock();
@@ -167,12 +192,6 @@ public abstract class AnimatorBase implements GLAnimatorControl {
}
}
- public synchronized void resetCounter() {
- startTime = System.currentTimeMillis(); // overwrite startTime to real init one
- curTime = startTime;
- totalFrames = 0;
- }
-
/** Sets a flag causing this Animator to ignore exceptions produced
while redrawing the drawables. By default this flag is set to
false, causing any exception thrown to halt the Animator. */
@@ -189,6 +208,6 @@ public abstract class AnimatorBase implements GLAnimatorControl {
}
public String toString() {
- return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", frames "+getTotalFrames()+", drawable "+drawables.size()+"]";
+ return getClass().getName()+"[started "+isStarted()+", animating "+isAnimating()+", paused "+isPaused()+", drawable "+drawables.size()+"]";
}
}