tipgame
Class FrameAdvancer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by tipgame.GameWindow
                          extended by tipgame.FrameAdvancer
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowStateListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer
Direct Known Subclasses:
GameLoop

public abstract class FrameAdvancer
extends GameWindow

used to advance the frame in an animation using the AnimationCanvas. There are two basic parametes to the FrameAdvancer: the model frame rate and the screen frame rate. The model frame rate describes the number of frames per second which must be computed to have a consistent model. This in effect determines the maximum time for computations between displays. The screen frame rate is how often the screen is refreshed with the current Sprites. The screen rate is never higher than the model rate.

Author:
Jam Jenkins
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.util.TreeMap<java.lang.Double,java.util.LinkedList<Alarm>> alarms
          all pending alarms
protected  AnimationCanvas canvas
          the canvas which displays the Sprites
private  double currentTime
          the current time, used in updateInterval method
private  double maxModelTimeInterval
          the highest allowable time between calls to update
private  java.util.LinkedList<java.lang.Double> refreshTimes
          keeps track of the screen refresh rate
 double timeInterval
          time since the last call to updateInterval
 
Fields inherited from class tipgame.GameWindow
frame, gameLoop, hasFrame, help, helpPlay, mute, pause, quit, title
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FrameAdvancer()
          initializes the canvas to empty and no alarms set
FrameAdvancer(java.awt.Dimension size)
          initializes the canvas to size and no alarms set
 
Method Summary
 void advanceFrame()
          called repeatedly between every model update
 void cancelAlarm(Alarm alarm)
          removes all pending alarms on this object.
 void clearAllAlarms()
          removes all pending alarms.
 AnimationCanvas getCanvas()
          returns the canvas
 double getScreenRefreshRate()
          returns the screen refresh rate
 double getTime()
          returns the current time in seconds
abstract  void postAdvanceFrame()
           
 void refreshScreen()
          updates the AnimationCanvas, should only be called from the AWTEvent Thread.
 void scheduleAbsolute(Alarm alarm, double absolute)
          sets and alarm to go off at a time relative to the beginning of time (zero).
 void scheduleRelative(Alarm alarm, double relative)
          sets and alarm to go off relative to the current time.
 void setCanvas(AnimationCanvas canvas)
          set canvas to a new canvas
 void setMinimumModelFrameRate(int framesPerSecond)
          sets the minimum number of frames which must be computed per second.
 void updateModel(double time)
          updates the model between displays.
 
Methods inherited from class tipgame.GameWindow
actionPerformed, disconnect, getDefaultSize, getHelpURL, init, pauseToggle, runAsApplication, setGameName, setNumberOfPlayers, setServerName, setSessionName, setTitle, setUseFrame, startGame, stop, toggleAudible, windowStateChanged
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, remove, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

refreshTimes

private java.util.LinkedList<java.lang.Double> refreshTimes
keeps track of the screen refresh rate


canvas

protected AnimationCanvas canvas
the canvas which displays the Sprites


currentTime

private double currentTime
the current time, used in updateInterval method


timeInterval

public double timeInterval
time since the last call to updateInterval


maxModelTimeInterval

private double maxModelTimeInterval
the highest allowable time between calls to update


alarms

private java.util.TreeMap<java.lang.Double,java.util.LinkedList<Alarm>> alarms
all pending alarms

Constructor Detail

FrameAdvancer

public FrameAdvancer()
initializes the canvas to empty and no alarms set


FrameAdvancer

public FrameAdvancer(java.awt.Dimension size)
initializes the canvas to size and no alarms set

Method Detail

setCanvas

public void setCanvas(AnimationCanvas canvas)
set canvas to a new canvas

Parameters:
canvas -

getCanvas

public AnimationCanvas getCanvas()
returns the canvas

Specified by:
getCanvas in class GameWindow
Returns:
canvas

advanceFrame

public void advanceFrame()
called repeatedly between every model update


getTime

public double getTime()
returns the current time in seconds

Returns:
the current time in seconds

getScreenRefreshRate

public double getScreenRefreshRate()
returns the screen refresh rate

Returns:
ScreenRefreshRate

setMinimumModelFrameRate

public void setMinimumModelFrameRate(int framesPerSecond)
sets the minimum number of frames which must be computed per second. This is separate from the screen frame rate in that more frames can be computed than displayed, but it can be affected by (and affect) the screen rate. Too high of a model frame rate can cause computation to slow down the display rate, and too low of a model frame rate can cause important events to be missed (typically the intersection of Sprites). Too high a model frame rate can slow down the advancing of time to slower than physical time. Frame rates higher than 200 Hz are not allowed.

Parameters:
framesPerSecond - the number of frames computed per second

scheduleRelative

public void scheduleRelative(Alarm alarm,
                             double relative)
sets and alarm to go off relative to the current time. For example, this method can be used to set off an alarm in 5 seconds from the current time.

Parameters:
alarm - the class to call the alarm method on
relative - the time from now in seconds to call the alarm method

scheduleAbsolute

public void scheduleAbsolute(Alarm alarm,
                             double absolute)
sets and alarm to go off at a time relative to the beginning of time (zero). For example, this method can be used to set off an alarm 30 seconds from the beginning time.

Parameters:
alarm - the class to call the alarm method on
absolute - the time in seconds to call the alarm method

cancelAlarm

public void cancelAlarm(Alarm alarm)
removes all pending alarms on this object. If there are no alarms with this object as the target, the method call is ignored.

Parameters:
alarm - the object that is the target of a pending alarm

clearAllAlarms

public void clearAllAlarms()
removes all pending alarms. If there are no pending alarms, the method call is ignored.


updateModel

public void updateModel(double time)
updates the model between displays. This method can split the time passed if more time has passed since the last display than the maximum time interval allowable for the model frame rate.


postAdvanceFrame

public abstract void postAdvanceFrame()

refreshScreen

public void refreshScreen()
updates the AnimationCanvas, should only be called from the AWTEvent Thread.