|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.app.AbstractGame
com.jmex.game.StandardGame
public final class StandardGame
A game that implements all of the basic functionality that you will need.
This is intended to be the next logical step up from SimpleGame
and can be utilised in production games.
StandardGame
provides the following features to ease game development:
However, even with all of the extras that StandardGame
provides it
does not force anything extra on you as the non-necessary items should be
put into your GameState
s and managed
there. This process helps to organise the different aspects of your game and
get the game process started ASAP to kill the long-standing problem of
start-up lag.
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
|
Fields inherited from class com.jme.app.AbstractGame |
---|
display, finished, settings |
Constructor Summary | |
---|---|
StandardGame(java.lang.String gameName)
|
|
StandardGame(java.lang.String gameName,
StandardGame.GameType type)
|
|
StandardGame(java.lang.String gameName,
StandardGame.GameType type,
GameSettings settings)
|
|
StandardGame(java.lang.String gameName,
StandardGame.GameType type,
GameSettings settings,
java.lang.Thread.UncaughtExceptionHandler exceptionHandler)
|
Method Summary | ||
---|---|---|
protected void |
cleanup()
Called once the game loop has finished. |
|
void |
delayForUpdate()
Causes the current thread to wait for an update to occur in the OpenGL thread. |
|
|
executeInGL(java.util.concurrent.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 . |
|
java.awt.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()
|
|
protected GameSettings |
getNewSettings()
Subclasses must implement getNewSettings to instantiate and populate a GameSettings object. |
|
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 |
|
protected void |
initGame()
Create and initialise all game data. |
|
protected void |
initSound()
|
|
protected void |
initSystem()
Initialise the display system. |
|
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()
quit exits the program. |
|
void |
recreateGraphicalContext()
|
|
void |
reinit()
Rebuild the system. |
|
void |
reinitAudio()
|
|
void |
reinitVideo()
|
|
protected void |
render(float interpolation)
Display the updated game information. |
|
void |
resetCamera()
|
|
void |
run()
|
|
void |
setBackgroundColor(ColorRGBA backgroundColor)
Override the background color defined for this game. |
|
void |
setIcons(Image[] icons)
|
|
void |
setUncaughtExceptionHandler(java.lang.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. |
|
protected void |
update(float interpolation)
Update the game state. |
Methods inherited from class com.jme.app.AbstractGame |
---|
assertDisplayCreated, finish, getAttributes, getVersion, setConfigShowMode, setConfigShowMode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DISPLAY_WINDOW
public static final int DISPLAY_CANVAS
public static boolean THREAD_FRIENDLY
public static int DISPLAY_MODE
Constructor Detail |
---|
public StandardGame(java.lang.String gameName)
public StandardGame(java.lang.String gameName, StandardGame.GameType type)
public StandardGame(java.lang.String gameName, StandardGame.GameType type, GameSettings settings)
public StandardGame(java.lang.String gameName, StandardGame.GameType type, GameSettings settings, java.lang.Thread.UncaughtExceptionHandler exceptionHandler)
Method Detail |
---|
protected GameSettings getNewSettings()
AbstractGame
getNewSettings
in class AbstractGame
AbstractGame.getNewSettings()
public StandardGame.GameType getGameType()
public void start()
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.
start
in class AbstractGame
public void run()
run
in interface java.lang.Runnable
protected void initSystem()
AbstractGame
This includes not just the DisplaySystem
but also any other
input and display related elements such as windows, cameras, and the
input system.
Note that the display must be initialised in this method.
initSystem
in class AbstractGame
public java.awt.Canvas getCanvas()
protected void initSound()
public void resetCamera()
protected void initGame()
AbstractGame
What happens here is purely application dependent; it is where, for example, the initial scene graph and the starting environment could be loaded. It is suggested that any frequently used resources are loaded and cached in this method.
This method is called once after AbstractGame.initSystem()
has completed.
initGame
in class AbstractGame
protected void update(float interpolation)
AbstractGame
Any user input checks, changes to game physics, AI, networking, score table updates, and so on, should happen in this method. The rate at which this method is called will depend on the specific game implementation in use.
Note that this method should not update the screen.
update
in class AbstractGame
interpolation
- definition varies on implementation, -1.0f if unusedAbstractGame.render(float)
protected void render(float interpolation)
AbstractGame
This method normally involves clearing the display and rendering the scene graph, although subclasses are free to do any screen related work here. The rate at which this method is called will depend on the specific game implementation in use.
Note that this method is run on the OpenGL thread, it should not alter the game state in any way.
render
in class AbstractGame
interpolation
- definition varies on implementation, -1.0f if unusedAbstractGame.update(float)
public void reinit()
AbstractGame
This method is called when the system requires rebuilding, for example is the screen resolution is altered. This method may be called at any time by client code.
reinit
in class AbstractGame
public void reinitAudio()
public void reinitVideo()
public void recreateGraphicalContext()
protected void cleanup()
AbstractGame
Subclasses should use this method to release any resources, for example
data that was loaded in the initXXX()
methods.
cleanup
in class AbstractGame
protected void quit()
AbstractGame
quit
exits the program. By default, it simply uses the
System.exit()
method.
quit
in class AbstractGame
public DisplaySystem getDisplay()
DisplaySystem
for this instance
of StandardGame
DisplaySystem
public Camera getCamera()
Camera
for this instance of
StandardGame
.
Camera
public GameSettings getSettings()
GameSettings
implementation being utilized in
this instance of StandardGame
.
GameSettings
public void setBackgroundColor(ColorRGBA backgroundColor)
backgroundColor
- public void shutdown()
AbstractGame.finish()
public boolean isStarted()
public void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler exceptionHandler)
exceptionHandler
- public void delayForUpdate() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public boolean inGLThread()
public <T> T executeInGL(java.util.concurrent.Callable<T> callable) throws java.lang.Exception
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.
T
- callable
-
java.lang.Exception
public void lock()
public void unlock()
public void setIcons(Image[] icons)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |