fang
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 fang.GameWindow
                          extended by fang.FrameAdvancer
All Implemented Interfaces:
AlarmScheduler, ActionListener, WindowStateListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer
Direct Known Subclasses:
GameLoop

public abstract class FrameAdvancer
extends GameWindow
implements AlarmScheduler

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
JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  AnimationCanvas canvas
          the canvas which displays the Sprites
 double timeInterval
          time since the last call to updateInterval
 
Fields inherited from class fang.GameWindow
cards, connectButton, container, createOwnFrame, displayControlButtons, frame, fullScreen, help, helpPlay, loadingMessage, mute, pause, players, playersSelectable, playersSpinner, quit, serverField, serverLabel, serverSelectable, sessionComboBox, sessionLabel, sessionSelectable, 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(Dimension gameDimensions)
          initializes the canvas to size and no alarms set
FrameAdvancer(Dimension gameDimensions, Color backgroundColor)
           
 
Method Summary
 void advanceFrame(double timePassed)
          called repeatedly between every model update
 void cancel(TimedAction action)
           
 void cancelAlarm(Alarm alarm)
          removes all pending alarms on this object.
 void cancelAllAlarms()
          removes all pending alarms.
 void cancelAllTimedActions()
           
 Alarm[] getAlarms()
          gets the list of alarms scheduled to go off in the future.
 TimedAction[] getAllTimedActions()
           
 AnimationCanvas getCanvas()
          returns the canvas
 double getScreenRefreshRate()
          returns the screen refresh rate
 double getTime()
          returns the current time in seconds since the beginning of this game.
abstract  void postAdvanceFrame(double timePassed)
          called after advanceFrame
 void refreshScreen()
          updates the AnimationCanvas, should only be called from the AWTEvent Thread.
 void removeCursor()
          removes the cursor from the game canvas
 void resetTime()
          makes the current time zero
 void restoreCursor()
          adds the default cursor back to the screen
 void schedule(TimedAction action, double delay)
           
 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 setBackground(Color backgroundColor)
          Set the bacground color of this game.
 void setCanvas(AnimationCanvas canvas)
          set canvas to a new canvas
 void setCursor(URL url)
          sets the cursor for the game engine
 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 fang.GameWindow
actionPerformed, begin, disconnect, getDefaultSize, getGameName, getHash, getHelpStyleSheet, getHostname, getServerName, getSessionName, init, isCreatingOwnFrame, pauseToggle, runAsApplication, setCreateOwnFrame, setDefaultHelp, setGameName, setHelp, setHelpText, setLoadMessage, setNumberOfPlayers, setServerName, setSessionName, setTitle, 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, 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

canvas

protected AnimationCanvas canvas
the canvas which displays the Sprites


timeInterval

public double timeInterval
time since the last call to updateInterval

Constructor Detail

FrameAdvancer

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


FrameAdvancer

public FrameAdvancer(Dimension gameDimensions)
initializes the canvas to size and no alarms set


FrameAdvancer

public FrameAdvancer(Dimension gameDimensions,
                     Color backgroundColor)
Method Detail

setBackground

public void setBackground(Color backgroundColor)
Set the bacground color of this game. This sets the background color of both the FrameAdvancer and the contained AnimationCanvas.

Overrides:
setBackground in class Component
Parameters:
backgroundColor - color to use for the background of the game field

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(double timePassed)
called repeatedly between every model update


getTime

public double getTime()
returns the current time in seconds since the beginning of this game. When the game starts over, so does the time.

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.

Specified by:
scheduleRelative in interface AlarmScheduler
Parameters:
alarm - the class to call the alarm method on
relative - the time from now in seconds to call the alarm method

schedule

public void schedule(TimedAction action,
                     double delay)

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.

Specified by:
scheduleAbsolute in interface AlarmScheduler
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.

Specified by:
cancelAlarm in interface AlarmScheduler
Parameters:
alarm - the object that is the target of a pending alarm

cancel

public void cancel(TimedAction action)

cancelAllAlarms

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

Specified by:
cancelAllAlarms in interface AlarmScheduler

cancelAllTimedActions

public void cancelAllTimedActions()

getAllTimedActions

public TimedAction[] getAllTimedActions()

getAlarms

public Alarm[] getAlarms()
gets the list of alarms scheduled to go off in the future.

Returns:
the array of alarms in the order which they would go off

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.

Parameters:
time - the current absolute time

setCursor

public void setCursor(URL url)
sets the cursor for the game engine

Parameters:
filename - the image to display as the cursor

removeCursor

public void removeCursor()
removes the cursor from the game canvas


restoreCursor

public void restoreCursor()
adds the default cursor back to the screen


postAdvanceFrame

public abstract void postAdvanceFrame(double timePassed)
called after advanceFrame

Parameters:
timePassed - the duration since the last frame

refreshScreen

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


resetTime

public void resetTime()
makes the current time zero