From 20dd60820257af9aef8ff3eeab1c03736252e284 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 25 Nov 2010 03:02:26 +0100 Subject: Relax GLAnimatorControl, ie remove fail fast for start()/stop(), return (boolean)success instead. --- src/jogl/classes/com/jogamp/opengl/util/Animator.java | 11 +++++++---- src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl') diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java index 31abe099d..311b4141f 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -253,9 +253,9 @@ public class Animator extends AnimatorBase { } } - public synchronized void start() { + public synchronized boolean start() { if ( isStartedImpl() ) { - throw new GLException("Start: Already running (started "+isStartedImpl()+" (false))"); + return false; } if (runnable == null) { runnable = new MainLoop(); @@ -271,7 +271,9 @@ public class Animator extends AnimatorBase { thread.setDaemon(true); // don't stop JVM from shutdown .. thread.start(); finishLifecycleAction(waitForStartedCondition); + return true; } + private class WaitForStartedCondition implements Condition { public boolean result() { return !isStartedImpl() || (!drawablesEmpty && !isAnimating) ; @@ -279,13 +281,14 @@ public class Animator extends AnimatorBase { } Condition waitForStartedCondition = new WaitForStartedCondition(); - public synchronized void stop() { + public synchronized boolean stop() { if ( !isStartedImpl() ) { - throw new GLException("Stop: Not running (started "+isStartedImpl()+" (true))"); + return false; } stopIssued = true; notifyAll(); finishLifecycleAction(waitForStoppedCondition); + return true; } private class WaitForStoppedCondition implements Condition { public boolean result() { diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java index 6bac1646b..741d4461b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java @@ -137,9 +137,9 @@ public class FPSAnimator extends AnimatorBase { } } - public synchronized void start() { + public synchronized boolean start() { if (timer != null) { - throw new GLException("Already started"); + return false; } stateSync.lock(); try { @@ -148,14 +148,15 @@ public class FPSAnimator extends AnimatorBase { } finally { stateSync.unlock(); } + return true; } /** Stops this FPSAnimator. Due to the implementation of the FPSAnimator it is not guaranteed that the FPSAnimator will be completely stopped by the time this method returns. */ - public synchronized void stop() { + public synchronized boolean stop() { if (timer == null) { - throw new GLException("Already stopped"); + return false; } stateSync.lock(); try { @@ -168,6 +169,7 @@ public class FPSAnimator extends AnimatorBase { } finally { stateSync.unlock(); } + return true; } public synchronized boolean pause() { -- cgit v1.2.3