|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.hdcookbook.grin.animator.AnimationEngine com.hdcookbook.grin.animator.ClockBasedEngine
public abstract class ClockBasedEngine
Abstract base class for a clock-based animation engine. A clock-based engine uses System.currentTimeMillis and Object.wait() to pace the animation to real time.
Field Summary |
---|
Fields inherited from class com.hdcookbook.grin.animator.AnimationEngine |
---|
modelTimeSkipped, renderContext, repaintBounds, targetsCanOverlap, transparent |
Constructor Summary | |
---|---|
protected |
ClockBasedEngine()
Create a new ClockBasedEngine |
Method Summary | |
---|---|
int |
getFps()
Get the current framerate, in 1001ths of a second. |
void |
pause()
Pause the currently running animations. |
protected void |
runAnimationLoop()
The inner loop for the animation thread. |
void |
setFps(int fps)
Set the frame rate of the animation, in 1001sts of a second. |
void |
skipFrames(int num)
Skip ahead the given number of frames. |
void |
start()
Start the current animations. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected ClockBasedEngine()
Method Detail |
---|
public void start()
By default, the manager will assume that the contents of the framebuffer wasn't changed while the manager was paused. If it might have been, it's advisable to call paintNextFrameFully().
The animation manager starts in the paused state, so this method will normally need to be called at least once.
start
in class AnimationEngine
AnimationEngine.paintNextFrameFully()
public void pause()
This method will return immediately, even if the animation hasn't reached the paused state yet.
When the animation framework is paused, no effort is made to output one last frame with the current state of the model.
pause
in class AnimationEngine
public void setFps(int fps)
Desired framerate fps value ================= ========= 23.976 24,000 24.000 24,024 29.970 30,000 30.000 30,030 59.940 60,000 60.000 60,060If you find yourself asking "why 1001," read the HD Handbook starting from page 2-2 (ISBN 978-0-07-149585-1). Long story short: NTSC video's frame rate is 30*1000/1001 frames/second, due to issues around the transition from B&W to color. Fun fact: 1001 isn't prime, it's 7*11*13
The frame rate must be greater than 0 fps. To stop the animation, call pause().
If the animation is paused when this method is called, it will stay paused.
java.lang.IllegalArgumentException
- if fps < 0.skipFrames(int)
public int getFps()
setFps(int)
,
skipFrames(int)
public void skipFrames(int num) throws java.lang.InterruptedException
This method is probably only useful for debugging.
num
- The number of frames to skip
java.lang.InterruptedException
protected void runAnimationLoop() throws java.lang.InterruptedException
This method must call checkNewClients() outside of any synchronized block at least once per frame. This should be done at the beginning of the frame before any model updates or animation work is done.
This method must check destroyRequested() at least once per frame, and if it's true, bail out of the loop. To advance the model by one frame, it should call advanceModel(). When it wants to show a frame (and not skip it), it should call showFrame(), which will cause callPaintTargets() to be called.
Of course, the animation loop should also check Thread.interrupted() regularly.
runAnimationLoop
in class AnimationEngine
java.lang.InterruptedException
AnimationEngine.destroyRequested()
,
AnimationEngine.advanceModel()
,
AnimationEngine.showFrame()
,
AnimationEngine.callPaintTargets()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |