aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-11-25 03:02:26 +0100
committerSven Gothel <[email protected]>2010-11-25 03:02:26 +0100
commit20dd60820257af9aef8ff3eeab1c03736252e284 (patch)
treead0cdd1e234ceb3dc7a8800d315326de5b9fcdb7 /src
parentc62a07ceeafec94c4327b8db2d2dc359043b2f2b (diff)
Relax GLAnimatorControl, ie remove fail fast for start()/stop(), return (boolean)success instead.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/Animator.java11
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java10
-rw-r--r--src/jogl/classes/javax/media/opengl/GLAnimatorControl.java16
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java16
4 files changed, 29 insertions, 24 deletions
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() {
diff --git a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java
index 0282b3ad0..2c8c7cca3 100644
--- a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java
+++ b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java
@@ -31,10 +31,6 @@ package javax.media.opengl;
/**
* An animator control interface,
* which implementation may drive a {@link javax.media.opengl.GLAutoDrawable} animation.
- * <P>
- * Note that the methods {@link #start()} and {@link #stop()}
- * shall be implemented fail-fast, ie {@link #start()} fails if not started, etc.
- * This way an implementation can find implementation errors faster.
*/
public interface GLAnimatorControl {
@@ -127,12 +123,14 @@ public interface GLAnimatorControl {
* <P>
* If started, all counters (time, frames, ..) are reset to zero.
*
+ * @return true is started due to this call,
+ * otherwise false, ie started already or unable to start.
+ *
* @see #stop()
* @see #isAnimating()
* @see #getThread()
- * @throws GLException if started already
*/
- void start();
+ boolean start();
/**
* Stops this animator.
@@ -142,12 +140,14 @@ public interface GLAnimatorControl {
* or in some cases from an implementation-internal thread like the
* AWT event queue thread.
*
+ * @return true is stopped due to this call,
+ * otherwise false, ie not started or unable to stop.
+ *
* @see #start()
* @see #isAnimating()
* @see #getThread()
- * @throws GLException if not started
*/
- void stop();
+ boolean stop();
/**
* Pauses this animator.
diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java
index 34e4f6430..e73181604 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java
@@ -118,13 +118,13 @@ public class TestGLWindows02NEWTAnimated extends UITestCase {
Assert.assertNotNull(caps);
GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */);
Animator animator = new Animator(window);
- animator.start();
+ Assert.assertTrue(animator.start());
while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
Thread.sleep(100);
}
destroyWindow(window);
Assert.assertEquals(true, animator.isAnimating());
- animator.stop();
+ Assert.assertTrue(animator.stop());
}
@Test
@@ -133,14 +133,14 @@ public class TestGLWindows02NEWTAnimated extends UITestCase {
Assert.assertNotNull(caps);
GLWindow window = createWindow(null, caps, width, height, true /* onscreen */, false /* undecorated */);
Animator animator = new Animator(window);
- animator.start();
+ Assert.assertTrue(animator.start());
while(animator.isAnimating() && animator.getDuration()<durationPerTest) {
Thread.sleep(100);
}
destroyWindow(window);
destroyWindow(window);
Assert.assertEquals(true, animator.isAnimating());
- animator.stop();
+ Assert.assertTrue(animator.stop());
}
@Test
@@ -166,7 +166,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase {
Assert.assertEquals(false, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());
- animator.start();
+ Assert.assertTrue(animator.start());
Assert.assertEquals(true, animator.isStarted());
Assert.assertEquals(false, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());
@@ -196,7 +196,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase {
Assert.assertEquals(true, animator.isStarted());
Assert.assertEquals(false, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());
- animator.stop();
+ Assert.assertTrue(animator.stop());
}
@Test
@@ -227,7 +227,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase {
Assert.assertEquals(false, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());
- animator.start();
+ Assert.assertTrue(animator.start());
Assert.assertEquals(true, animator.isStarted());
Assert.assertEquals(false, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());
@@ -268,7 +268,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase {
Assert.assertEquals(true, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());
- animator.stop();
+ Assert.assertTrue(animator.stop());
Assert.assertEquals(false, animator.isStarted());
Assert.assertEquals(false, animator.isAnimating());
Assert.assertEquals(false, animator.isPaused());