com.jmex.game
Class StandardGame

java.lang.Object
  extended by com.jme.app.AbstractGame
      extended by com.jmex.game.StandardGame
All Implemented Interfaces:
Runnable

public final class StandardGame
extends AbstractGame
implements Runnable

StandardGame intends to be a basic implementation of a game that can be utilized in games as a logical next step from SimpleGame and can be utilized in production games.

Author:
Matthew D. Hicks

Nested Class Summary
static class StandardGame.GameType
           
 
Nested classes/interfaces inherited from class com.jme.app.AbstractGame
AbstractGame.ConfigShowMode
 
Field Summary
static int DISPLAY_CANVAS
           
static int DISPLAY_MODE
           
static int DISPLAY_WINDOW
           
static boolean THREAD_FRIENDLY
           
 
Constructor Summary
StandardGame(String gameName)
           
StandardGame(String gameName, StandardGame.GameType type)
           
StandardGame(String gameName, StandardGame.GameType type, GameSettings settings)
           
StandardGame(String gameName, StandardGame.GameType type, GameSettings settings, Thread.UncaughtExceptionHandler exceptionHandler)
           
 
Method Summary
 void delayForUpdate()
          Causes the current thread to wait for an update to occur in the OpenGL thread.
<T> T
executeInGL(Callable<T> callable)
          Convenience method that will make sure callable is executed in the OpenGL thread.
 Camera getCamera()
          The internally used Camera for this instance of StandardGame.
 Canvas getCanvas()
          The java.awt.Canvas if DISPLAY_CANVAS is the DISPLAY_MODE
 DisplaySystem getDisplay()
          The internally used DisplaySystem for this instance of StandardGame
 StandardGame.GameType getGameType()
           
 GameSettings getSettings()
          The GameSettings implementation being utilized in this instance of StandardGame.
 boolean inGLThread()
          Convenience method to let you know if the thread you're in is the OpenGL thread
 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.
 void recreateGraphicalContext()
           
 void reinit()
          reinit rebuilds the subsystems.
 void reinitAudio()
           
 void reinitVideo()
           
 void resetCamera()
           
 void run()
           
 void setBackgroundColor(ColorRGBA backgroundColor)
          Override the background color defined for this game.
 void setIcons(Image[] icons)
           
 void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler)
          Specify the UncaughtExceptionHandler for circumstances where an exception in the OpenGL thread is not captured properly.
 void shutdown()
          Gracefully shutdown the main game loop thread.
 void start()
          start begins the game.
 void unlock()
          Used in conjunction with lock() in order to release a previously assigned lock on the OpenGL thread.
 
Methods inherited from class com.jme.app.AbstractGame
finish, getVersion, setConfigShowMode, setConfigShowMode
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISPLAY_WINDOW

public static final int DISPLAY_WINDOW
See Also:
Constant Field Values

DISPLAY_CANVAS

public static final int DISPLAY_CANVAS
See Also:
Constant Field Values

THREAD_FRIENDLY

public static boolean THREAD_FRIENDLY

DISPLAY_MODE

public static int DISPLAY_MODE
Constructor Detail

StandardGame

public StandardGame(String gameName)

StandardGame

public StandardGame(String gameName,
                    StandardGame.GameType type)

StandardGame

public StandardGame(String gameName,
                    StandardGame.GameType type,
                    GameSettings settings)

StandardGame

public StandardGame(String gameName,
                    StandardGame.GameType type,
                    GameSettings settings,
                    Thread.UncaughtExceptionHandler exceptionHandler)
Method Detail

getGameType

public StandardGame.GameType getGameType()

start

public void start()
Description copied from class: AbstractGame
start begins the game. The game is initialized by calling first initSystem then initGame. Assuming no errors were encountered during initialization, the main game loop is entered. How the loop operates is implementation-dependent. After the game loop is broken out of via a call to finish, cleanup is called. Subclasses should declare this method final.

Specified by:
start in class AbstractGame

run

public void run()
Specified by:
run in interface Runnable

getCanvas

public Canvas getCanvas()
The java.awt.Canvas if DISPLAY_CANVAS is the DISPLAY_MODE

Returns:
Canvas

resetCamera

public void resetCamera()

reinit

public void reinit()
Description copied from class: AbstractGame
reinit rebuilds the subsystems. It may be called at any time by the client application.


reinitAudio

public void reinitAudio()

reinitVideo

public void reinitVideo()

recreateGraphicalContext

public void recreateGraphicalContext()

getDisplay

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

Returns:
DisplaySystem
See Also:
DisplaySystem

getCamera

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

Returns:
Camera
See Also:
Camera

getSettings

public GameSettings getSettings()
The GameSettings implementation being utilized in this instance of StandardGame.

Returns:
GameSettings
See Also:
GameSettings

setBackgroundColor

public void setBackgroundColor(ColorRGBA backgroundColor)
Override the background color defined for this game. The reinit() method must be invoked if the game is currently running before this will take effect.

Parameters:
backgroundColor -

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:
AbstractGame.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

setUncaughtExceptionHandler

public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler)
Specify the UncaughtExceptionHandler for circumstances where an exception in the OpenGL thread is not captured properly.

Parameters:
exceptionHandler -

delayForUpdate

public void delayForUpdate()
                    throws InterruptedException,
                           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:
InterruptedException
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(Callable<T> callable)
              throws 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:
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.


setIcons

public void setIcons(Image[] icons)