com.jmex.awt.applet
Class StandardApplet

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 com.jmex.awt.applet.StandardApplet
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public abstract class StandardApplet
extends java.applet.Applet

LWJGL2 Applet imlpementation similar to StandardGame

See Also:
Serialized Form

Nested Class Summary
static class StandardApplet.GameType
           
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  DisplaySystem display
          The DisplaySystem for this applet
protected  java.awt.Canvas displayParent
          The awt canvas to draw to
protected  boolean finished
           
protected  java.lang.Thread gameThread
          The thread with the game logic: initialization, updating, rendering
protected  ThrowableHandler throwableHandler
          If there is an exception during the game loop this is used to handle it
 
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
StandardApplet()
           
 
Method Summary
protected  void assertDisplayCreated()
          assertDisplayCreated determines if the display system was successfully created before use.
protected  void cleanup()
           
 void delayForUpdate()
          Causes the current thread to wait for an update to occur in the OpenGL thread.
 void destroy()
           
<T> T
executeInGL(java.util.concurrent.Callable<T> callable)
          Convenience method that will make sure callable is executed in the OpenGL thread.
 void finish()
          Halts execution (cleanup methods are called afterwards)
 void gameLoop()
           
 int getAlphaBits()
           
 Camera getCamera()
          The internally used Camera for this instance of StandardApplet.
 java.awt.Canvas getCanvas()
           
 int getDepthBits()
           
 DisplaySystem getDisplay()
          The internally used DisplaySystem for this instance of StandardApplet
 int getFramerate()
           
 java.lang.String getGameName()
           
 int getSamples()
           
 int getStencilBits()
           
protected  ThrowableHandler getThrowableHandler()
          Get the exception handler if one hs been set.
 StandardApplet.GameType getType()
           
 java.lang.String getVersion()
           
 boolean getVSyncEnabled()
           
 boolean inGLThread()
          Convenience method to let you know if the thread you're in is the OpenGL thread
 void init()
          Initializes the awt canvas to later render the jme scene to via Display.setParent()
protected  void initGame()
           
protected  void initSound()
           
protected  void initSystem()
           
 boolean isStarted()
          Will return true if within the main game loop.
 void lock()
          Will wait for a lock at the beginning of the OpenGL update method.
protected  void quit()
           
protected  void render(float interpolation)
           
 void resetCamera()
           
 void setAlphaBits(int alphaBits)
           
 void setBackgroundColor(ColorRGBA backgroundColor)
           
 void setDepthBits(int depthBits)
           
 void setFramerate(int preferredFPS)
           
 void setGameName(java.lang.String gameName)
           
 void setIcons(Image[] icons)
           
 void setSamples(int samples)
           
 void setStencilBits(int stencilBits)
           
protected  void setThrowableHandler(ThrowableHandler throwableHandler)
           
 void setType(StandardApplet.GameType type)
           
 void setVSyncEnabled(boolean vSyncEnabled)
           
 void shutdown()
          Gracefully shutdown the main game loop thread.
 void start()
          Creates the game thread, which first initializes the display, then runs the game updates and renders.
 void toggleFullscreen()
           
 void unlock()
          Used in conjunction with lock() in order to release a previously assigned lock on the OpenGL thread.
protected  void update(float interpolation)
           
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, getBaseline, getBaselineResizeBehavior, 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

displayParent

protected java.awt.Canvas displayParent
The awt canvas to draw to


gameThread

protected java.lang.Thread gameThread
The thread with the game logic: initialization, updating, rendering


finished

protected boolean finished

display

protected DisplaySystem display
The DisplaySystem for this applet


throwableHandler

protected ThrowableHandler throwableHandler
If there is an exception during the game loop this is used to handle it

Constructor Detail

StandardApplet

public StandardApplet()
Method Detail

getVersion

public java.lang.String getVersion()

setGameName

public void setGameName(java.lang.String gameName)

getGameName

public java.lang.String getGameName()

setType

public void setType(StandardApplet.GameType type)

getType

public StandardApplet.GameType getType()

setFramerate

public void setFramerate(int preferredFPS)

getFramerate

public int getFramerate()

setVSyncEnabled

public void setVSyncEnabled(boolean vSyncEnabled)

getVSyncEnabled

public boolean getVSyncEnabled()

setIcons

public void setIcons(Image[] icons)

setBackgroundColor

public void setBackgroundColor(ColorRGBA backgroundColor)

getAlphaBits

public int getAlphaBits()

setAlphaBits

public void setAlphaBits(int alphaBits)

getDepthBits

public int getDepthBits()

setDepthBits

public void setDepthBits(int depthBits)

getStencilBits

public int getStencilBits()

setStencilBits

public void setStencilBits(int stencilBits)

getSamples

public int getSamples()

setSamples

public void setSamples(int samples)

toggleFullscreen

public void toggleFullscreen()

getDisplay

public DisplaySystem getDisplay()
The internally used DisplaySystem for this instance of StandardApplet

Returns:
DisplaySystem
See Also:
DisplaySystem

getCamera

public Camera getCamera()
The internally used Camera for this instance of StandardApplet.

Returns:
Camera
See Also:
Camera

getCanvas

public java.awt.Canvas getCanvas()

init

public void init()
Initializes the awt canvas to later render the jme scene to via Display.setParent()

Overrides:
init in class java.applet.Applet

start

public void start()
Creates the game thread, which first initializes the display, then runs the game updates and renders.

Overrides:
start in class java.applet.Applet

destroy

public void destroy()
Overrides:
destroy in class java.applet.Applet

gameLoop

public void gameLoop()

getThrowableHandler

protected ThrowableHandler getThrowableHandler()
Get the exception handler if one hs been set.

Returns:
the exception handler, or null if not set.

setThrowableHandler

protected void setThrowableHandler(ThrowableHandler throwableHandler)
Parameters:
throwableHandler -

assertDisplayCreated

protected void assertDisplayCreated()
                             throws JmeException
assertDisplayCreated determines if the display system was successfully created before use.

Throws:
JmeException - if the display system was not successfully created

initSystem

protected void initSystem()

initSound

protected void initSound()

resetCamera

public void resetCamera()

initGame

protected void initGame()

update

protected void update(float interpolation)
Parameters:
interpolationc - is the number of seconds since the last frame

render

protected void render(float interpolation)
Parameters:
interpolation - is the number of seconds since the last frame

cleanup

protected void cleanup()

quit

protected void quit()

finish

public void finish()
Halts execution (cleanup methods are called afterwards)


shutdown

public void shutdown()
Gracefully shutdown the main game loop thread. This is a synonym for the finish() method but just sounds better.

See Also:
finish()

isStarted

public boolean isStarted()
Will return true if within the main game loop. This is particularly useful to determine if the game has finished the initialization but will also return false if the game has been terminated.

Returns:
boolean

delayForUpdate

public void delayForUpdate()
                    throws java.lang.InterruptedException,
                           java.util.concurrent.ExecutionException
Causes the current thread to wait for an update to occur in the OpenGL thread. This can be beneficial if there is work that has to be done in the OpenGL thread that needs to be completed before continuing in another thread. You can chain invocations of this together in order to wait for multiple updates.

Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException

inGLThread

public boolean inGLThread()
Convenience method to let you know if the thread you're in is the OpenGL thread

Returns:
true if, and only if, the current thread is the OpenGL thread

executeInGL

public <T> T executeInGL(java.util.concurrent.Callable<T> callable)
              throws java.lang.Exception
Convenience method that will make sure callable is executed in the OpenGL thread. If it is already in the OpenGL thread when this method is invoked it will be executed and returned immediately. Otherwise, it will be put into the GameTaskQueue and executed in the next update. This is a blocking method and will wait for the successful return of callable before returning.

Type Parameters:
T -
Parameters:
callable -
Returns:
result of callable.get()
Throws:
java.lang.Exception

lock

public void lock()
Will wait for a lock at the beginning of the OpenGL update method. Once this method returns the OpenGL thread is blocked until the lock is released (via unlock()). If another thread currently has a lock or it is currently in the process of an update the calling thread will be blocked until the lock is successfully established.


unlock

public void unlock()
Used in conjunction with lock() in order to release a previously assigned lock on the OpenGL thread. This MUST be executed within the same thread that called lock() in the first place or the lock will not be released.