diff options
author | Sven Gothel <[email protected]> | 2012-11-04 07:11:41 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-11-04 07:11:41 +0100 |
commit | 9cf42434eb58160e25c79613efca51f2fd4d6086 (patch) | |
tree | 2c99d91800cee6bb528afa08c28b8bc8b58559f0 /src/jogl/classes/com | |
parent | c002e04f848116922a1ed7bd96ead54961649bbd (diff) |
FPSAnimator: Wait '2 x period' or 20ms, whichever is greater in case of pause/stop - taking execution frequency into account
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java index f7fc58160..73cc3a5f2 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java @@ -119,7 +119,7 @@ public class FPSAnimator extends AnimatorBase { if(null != task) { return; } - long delay = (long) (1000.0f / (float) fps); + final long period = (long) (1000.0f / (float) fps); task = new TimerTask() { public void run() { if(FPSAnimator.this.shouldRun) { @@ -134,9 +134,9 @@ public class FPSAnimator extends AnimatorBase { shouldRun = true; if (scheduleAtFixedRate) { - timer.scheduleAtFixedRate(task, 0, delay); + timer.scheduleAtFixedRate(task, 0, period); } else { - timer.schedule(task, 0, delay); + timer.schedule(task, 0, period); } } @@ -174,7 +174,8 @@ public class FPSAnimator extends AnimatorBase { } animThread = null; try { - Thread.sleep(20); // ~ 1/60 hz wait, since we can't ctrl stopped threads + final long periodx2 = 2L * (long) (1000.0f / (float) fps); + Thread.sleep(periodx2 > 20L ? periodx2 : 20L); // max(2 x timer period, ~ 1/60), since we can't ctrl stopped threads } catch (InterruptedException e) { } } finally { stateSync.unlock(); @@ -195,7 +196,8 @@ public class FPSAnimator extends AnimatorBase { } animThread = null; try { - Thread.sleep(20); // ~ 1/60 hz wait, since we can't ctrl stopped threads + final long periodx2 = 2L * (long) (1000.0f / (float) fps); + Thread.sleep(periodx2 > 20L ? periodx2 : 20L); // max(2 x timer period, ~ 1/60), since we can't ctrl stopped threads } catch (InterruptedException e) { } } finally { stateSync.unlock(); |