From b0cd74f86140937ce73b740602b0bf79dbfd8f11 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Tue, 21 Feb 2006 10:04:34 +0000 Subject: Fixed Issue 205: FPSAnimator flag for fixed-rate scheduling Added new constructors taking fixed-rate scheduling flag. Defaults to false. Seems to help FPSAnimator reach higher framerate targets. Unclear whether the flag will cause excessive CPU consumption. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@630 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/classes/com/sun/opengl/util/FPSAnimator.java | 32 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/classes') diff --git a/src/classes/com/sun/opengl/util/FPSAnimator.java b/src/classes/com/sun/opengl/util/FPSAnimator.java index fae0ce0ae..290de89d6 100755 --- a/src/classes/com/sun/opengl/util/FPSAnimator.java +++ b/src/classes/com/sun/opengl/util/FPSAnimator.java @@ -49,19 +49,38 @@ import javax.media.opengl.*; public class FPSAnimator extends Animator { private Timer timer; private int fps; + private boolean scheduleAtFixedRate; - /** Creates an FPSAnimator with a given target frames-per-second value. */ + /** Creates an FPSAnimator with a given target frames-per-second + value. Equivalent to FPSAnimator(null, fps). */ public FPSAnimator(int fps) { this(null, fps); } /** Creates an FPSAnimator with a given target frames-per-second - value and an initial drawable to animate. */ + value and a flag indicating whether to use fixed-rate + scheduling. Equivalent to FPSAnimator(null, fps, + scheduleAtFixedRate). */ + public FPSAnimator(int fps, boolean scheduleAtFixedRate) { + this(null, fps, scheduleAtFixedRate); + } + + /** Creates an FPSAnimator with a given target frames-per-second + value and an initial drawable to animate. Equivalent to + FPSAnimator(null, fps, false). */ public FPSAnimator(GLAutoDrawable drawable, int fps) { + this(drawable, fps, false); + } + + /** Creates an FPSAnimator with a given target frames-per-second + value, an initial drawable to animate, and a flag indicating + whether to use fixed-rate scheduling. */ + public FPSAnimator(GLAutoDrawable drawable, int fps, boolean scheduleAtFixedRate) { this.fps = fps; if (drawable != null) { add(drawable); } + this.scheduleAtFixedRate = scheduleAtFixedRate; } /** Starts this FPSAnimator. */ @@ -71,11 +90,16 @@ public class FPSAnimator extends Animator { } timer = new Timer(); long delay = (long) (1000.0f / (float) fps); - timer.schedule(new TimerTask() { + TimerTask task = new TimerTask() { public void run() { display(); } - }, 0, delay); + }; + if (scheduleAtFixedRate) { + timer.scheduleAtFixedRate(task, 0, delay); + } else { + timer.schedule(task, 0, delay); + } } /** Indicates whether this FPSAnimator is currently running. This -- cgit v1.2.3