public abstract class AnimatorBase extends Object implements GLAnimatorControl
The change synchronization is done via synchronized blocks on the AnimatorBase instance.
Status get / set activity is synced with a RecursiveLock, used as a memory barrier.
This is suitable, since all change requests are allowed to be expensive
as they are not expected to be called at every frame.
Modifier and Type | Class and Description |
---|---|
static interface |
AnimatorBase.AnimatorImpl |
static class |
AnimatorBase.UncaughtAnimatorException |
GLAnimatorControl.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
static int |
MODE_EXPECT_AWT_RENDERING_THREAD
If present in
modeBits field and
AWT is available ,
implementation is aware of the AWT EDT, otherwise not. |
DEFAULT_FRAMES_PER_INTERVAL
Constructor and Description |
---|
AnimatorBase()
Creates a new, empty Animator instance
while expecting an AWT rendering thread if AWT is available.
|
Modifier and Type | Method and Description |
---|---|
void |
add(GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
|
Thread |
getExclusiveContextThread()
Returns the exclusive context thread if
isExclusiveContextEnabled() and isStarted() , otherwise null . |
long |
getFPSStartTime()
Returns the time of the first display call in milliseconds after enabling this feature via
FPSCounter.setUpdateFPSFrames(int, PrintStream) .This value is reset via FPSCounter.resetFPSCounter() . |
float |
getLastFPS() |
long |
getLastFPSPeriod() |
long |
getLastFPSUpdateTime()
Returns the time of the last update interval in milliseconds, if this feature is enabled via
FPSCounter.setUpdateFPSFrames(int, PrintStream) .This value is reset via FPSCounter.resetFPSCounter() . |
int |
getModeBits() |
Thread |
getThread() |
float |
getTotalFPS() |
long |
getTotalFPSDuration() |
int |
getTotalFPSFrames() |
GLAnimatorControl.UncaughtExceptionHandler |
getUncaughtExceptionHandler()
Returns the
GLAnimatorControl.UncaughtExceptionHandler invoked when this animator abruptly stops
due to an uncaught exception from one of its GLAutoDrawable s. |
int |
getUpdateFPSFrames() |
boolean |
isExclusiveContextEnabled()
Returns
true , if the exclusive context thread is enabled, otherwise false . |
boolean |
isStarted()
Indicates whether this animator has been
started . |
void |
remove(GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
|
void |
resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
|
boolean |
setExclusiveContext(boolean enable)
Dedicate all
GLAutoDrawable 's context to this animator thread. |
Thread |
setExclusiveContext(Thread t)
Dedicate all
GLAutoDrawable 's context to the given exclusive context thread. |
void |
setIgnoreExceptions(boolean ignoreExceptions)
Sets a flag causing this Animator to ignore exceptions produced
while redrawing the drawables.
|
void |
setModeBits(boolean enable,
int bitValues)
Enables or disables the given
bitValues
in this Animators modeBits . |
void |
setPrintExceptions(boolean printExceptions)
Sets a flag indicating that when exceptions are being ignored by
this Animator (see
setIgnoreExceptions(boolean) ), to print the
exceptions' stack traces for diagnostic information. |
void |
setUncaughtExceptionHandler(GLAnimatorControl.UncaughtExceptionHandler handler)
Set the handler invoked when this
animator abruptly stops
due to an uncaught exception from one of its GLAutoDrawable s. |
void |
setUpdateFPSFrames(int frames,
PrintStream out) |
String |
toString() |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
isAnimating, isPaused, pause, resume, start, stop
public static final int MODE_EXPECT_AWT_RENDERING_THREAD
modeBits
field and
AWT is available
,
implementation is aware of the AWT EDT, otherwise not.
This is the default.
public AnimatorBase()
GLProfile.isAWTAvailable()
public final void setModeBits(boolean enable, int bitValues) throws GLException
bitValues
in this Animators modeBits
.enable
- bitValues
- GLException
- if Animator is isStarted()
and MODE_EXPECT_AWT_RENDERING_THREAD
about to changeMODE_EXPECT_AWT_RENDERING_THREAD
public int getModeBits()
public final void add(GLAutoDrawable drawable)
GLAnimatorControl
This allows the animator thread to become animating
,
in case the first drawable is added and the animator is started
.
add
in interface GLAnimatorControl
drawable
- the drawable to be addedpublic final void remove(GLAutoDrawable drawable)
GLAnimatorControl
This method should get called in case a drawable becomes invalid, and will not be recovered.
This allows the animator thread to become not animating
,
in case the last drawable has been removed.
remove
in interface GLAnimatorControl
drawable
- the drawable to be removedpublic final Thread setExclusiveContext(Thread t)
GLAutoDrawable
's context to the given exclusive context thread.
The given thread will be exclusive to all GLAutoDrawable
's context while GLAnimatorControl.isAnimating()
.
If already started and disabling, method waits
until change is propagated to all GLAutoDrawable
if not
called from the animator thread or exclusive context thread
.
Note: Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas.
enable
- setExclusiveContext(boolean)
,
getExclusiveContextThread()
,
isExclusiveContextEnabled()
public final boolean setExclusiveContext(boolean enable)
GLAutoDrawable
's context to this animator thread.
The given thread will be exclusive to all GLAutoDrawable
's context while GLAnimatorControl.isAnimating()
.
If already started and disabling, method waits
until change is propagated to all GLAutoDrawable
if not
called from the animator thread or exclusive context thread
.
Note: Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas.
enable
- setExclusiveContext(Thread)
,
getExclusiveContextThread()
,
isExclusiveContextEnabled()
public final boolean isExclusiveContextEnabled()
true
, if the exclusive context thread is enabled, otherwise false
.public final Thread getExclusiveContextThread()
isExclusiveContextEnabled()
and isStarted()
, otherwise null
.
If exclusive context is enabled via setExclusiveContext(boolean)
the animator thread
is returned if above conditions are met.
If exclusive context is enabled via setExclusiveContext(Thread)
the user passed thread is returned if above conditions are met.
public final Thread getThread()
getThread
in interface GLAnimatorControl
GLAnimatorControl.start()
,
GLAnimatorControl.stop()
public final void setUpdateFPSFrames(int frames, PrintStream out)
setUpdateFPSFrames
in interface FPSCounter
frames
- Update interval in frames.FPSCounter.DEFAULT_FRAMES_PER_INTERVAL
.out
- optional print stream where the fps values gets printed if not null at every frames intervalpublic final void resetFPSCounter()
FPSCounter
resetFPSCounter
in interface FPSCounter
public final int getUpdateFPSFrames()
getUpdateFPSFrames
in interface FPSCounter
FPSCounter.setUpdateFPSFrames(int, PrintStream)
public final long getFPSStartTime()
FPSCounter
FPSCounter.setUpdateFPSFrames(int, PrintStream)
.FPSCounter.resetFPSCounter()
.getFPSStartTime
in interface FPSCounter
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final long getLastFPSUpdateTime()
FPSCounter
FPSCounter.setUpdateFPSFrames(int, PrintStream)
.FPSCounter.resetFPSCounter()
.getLastFPSUpdateTime
in interface FPSCounter
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final long getLastFPSPeriod()
getLastFPSPeriod
in interface FPSCounter
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final float getLastFPS()
getLastFPS
in interface FPSCounter
FPSCounter.getUpdateFPSFrames()
/ FPSCounter.getLastFPSPeriod()
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final int getTotalFPSFrames()
getTotalFPSFrames
in interface FPSCounter
FPSCounter.getFPSStartTime()
up to FPSCounter.getLastFPSUpdateTime()
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final long getTotalFPSDuration()
getTotalFPSDuration
in interface FPSCounter
FPSCounter.getLastFPSUpdateTime()
- FPSCounter.getFPSStartTime()
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final float getTotalFPS()
getTotalFPS
in interface FPSCounter
FPSCounter.getTotalFPSFrames()
/ FPSCounter.getTotalFPSDuration()
FPSCounter.setUpdateFPSFrames(int, PrintStream)
,
FPSCounter.resetFPSCounter()
public final void setIgnoreExceptions(boolean ignoreExceptions)
public final void setPrintExceptions(boolean printExceptions)
setIgnoreExceptions(boolean)
), to print the
exceptions' stack traces for diagnostic information. Defaults to
false.public final GLAnimatorControl.UncaughtExceptionHandler getUncaughtExceptionHandler()
GLAnimatorControl
GLAnimatorControl.UncaughtExceptionHandler
invoked when this animator
abruptly stops
due to an uncaught exception from one of its GLAutoDrawable
s.
Default is null
.
getUncaughtExceptionHandler
in interface GLAnimatorControl
public final void setUncaughtExceptionHandler(GLAnimatorControl.UncaughtExceptionHandler handler)
GLAnimatorControl
animator
abruptly stops
due to an uncaught exception from one of its GLAutoDrawable
s.setUncaughtExceptionHandler
in interface GLAnimatorControl
handler
- the GLAnimatorControl.UncaughtExceptionHandler
to use as this animator
's uncaught exception
handler. Pass null
to unset the handler.GLAnimatorControl.UncaughtExceptionHandler.uncaughtException(GLAnimatorControl, GLAutoDrawable, Throwable)
public boolean isStarted()
GLAnimatorControl
started
.isStarted
in interface GLAnimatorControl
GLAnimatorControl.start()
,
GLAnimatorControl.stop()
,
GLAnimatorControl.isPaused()
,
GLAnimatorControl.pause()
,
GLAnimatorControl.resume()
Copyright 2010 JogAmp Community.