com.jme.app
Class AbstractGame

java.lang.Object
  extended by com.jme.app.AbstractGame
Direct Known Subclasses:
BaseGame, BaseHeadlessApp, FixedFramerateGame, FixedLogicrateGame, StandardGame, VariableTimestepGame

public abstract class AbstractGame
extends java.lang.Object

Functionality common to all game types.

This class provides a basic API for gmes and also holds some implementation details common to all game types. In particular it defines the various steps in the game life-cycle:

  1. initSystem() - initialise the system (e.g. the display system);
  2. initGame() - initialise the game (e.g. warm up caches);
  3. The game loop, repeat until finish() is called:
    1. update(float) - update the game data;
    2. render(float) - render the updated data;
  4. cleanup() - free up any resources.
Note that the actual definition of the lifecycle is not defined here, this is to allow subclasses to insert specialised timing code into the loop.

This class is not intended to be directly extended by client applications.

Version:
$Revision: 4131 $, $Date: 2009-03-19 20:15:28 +0000 (Thu, 19 Mar 2009) $
Author:
Eric Woroshow

Nested Class Summary
static class AbstractGame.ConfigShowMode
           
 
Field Summary
protected  DisplaySystem display
          Renderer used to display the game
protected  boolean finished
          Flag for running the system.
protected  GameSettings settings
          Game display properties.
 
Constructor Summary
protected AbstractGame()
           
 
Method Summary
protected  void assertDisplayCreated()
          assertDisplayCreated determines if the display system was successfully created before use.
protected abstract  void cleanup()
          Called once the game loop has finished.
 void finish()
          finish breaks out of the main game loop.
protected  void getAttributes()
          getAttributes attempts to first obtain the properties information from a GameSettings load, then a dialog depending on the dialog behaviour.
protected abstract  GameSettings getNewSettings()
          Subclasses must implement getNewSettings to instantiate and populate a GameSettings object.
 java.lang.String getVersion()
          getVersion returns the version of the API.
protected abstract  void initGame()
          Create and initialise all game data.
protected abstract  void initSystem()
          Initialise the display system.
protected abstract  void quit()
          quit exits the program.
protected abstract  void reinit()
          Rebuild the system.
protected abstract  void render(float interpolation)
          Display the updated game information.
 void setConfigShowMode(AbstractGame.ConfigShowMode mode)
          Defines if and when the display properties dialog should be shown.
 void setConfigShowMode(AbstractGame.ConfigShowMode mode, java.net.URL imageOverride)
          setConfigShowMode defines if and when the display properties dialog should be shown as well as its accompanying image.
abstract  void start()
          start begins the game.
protected abstract  void update(float interpolation)
          Update the game state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

finished

protected boolean finished
Flag for running the system.


settings

protected GameSettings settings
Game display properties.


display

protected DisplaySystem display
Renderer used to display the game

Constructor Detail

AbstractGame

protected AbstractGame()
Method Detail

getVersion

public java.lang.String getVersion()
getVersion returns the version of the API.

Returns:
the version of the API.

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

setConfigShowMode

public void setConfigShowMode(AbstractGame.ConfigShowMode mode)
Defines if and when the display properties dialog should be shown.

Setting the behaviour after start() has been called has no effect.

Parameters:
mode - the properties dialog behaviour.
See Also:
setConfigShowMode(ConfigShowMode, URL)

setConfigShowMode

public void setConfigShowMode(AbstractGame.ConfigShowMode mode,
                              java.net.URL imageOverride)
setConfigShowMode defines if and when the display properties dialog should be shown as well as its accompanying image. Setting the behaviour after start has been called has no effect.

Parameters:
mode - properties dialog behaviour. ALWAYS_SHOW_PROPS, NEVER_SHOW_PROPS and FIRSTRUN_OR_NOCONFIGFILE are the valid choices.
imageOverride - URL specifying the filename of an image to be displayed with the PropertiesDialog. Passing null will result in no image being used. You would normally use .getResource...() to get (and verify) the URL. For hacking or prototype, you can get image from filesystem like new URL("file:" + filepath").

getNewSettings

protected abstract GameSettings getNewSettings()
Subclasses must implement getNewSettings to instantiate and populate a GameSettings object. The default getAttributest method in AbstractGame calls this to get an initial GameSettings, which is conditionally updated interactively.


getAttributes

protected void getAttributes()
getAttributes attempts to first obtain the properties information from a GameSettings load, then a dialog depending on the dialog behaviour.


start

public abstract void start()
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.


finish

public void finish()
finish breaks out of the main game loop. It is preferable to call finish instead of quit.


quit

protected abstract void quit()
quit exits the program. By default, it simply uses the System.exit() method.


update

protected abstract void update(float interpolation)
Update the game state.

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.

Parameters:
interpolation - definition varies on implementation, -1.0f if unused
See Also:
render(float)

render

protected abstract void render(float interpolation)
Display the updated game information.

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.

Parameters:
interpolation - definition varies on implementation, -1.0f if unused
See Also:
update(float)

initSystem

protected abstract void initSystem()
Initialise the display system.

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.


initGame

protected abstract void initGame()
Create and initialise all game data.

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 initSystem() has completed.


reinit

protected abstract void reinit()
Rebuild the system.

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.


cleanup

protected abstract void cleanup()
Called once the game loop has finished.

Subclasses should use this method to release any resources, for example data that was loaded in the initXXX() methods.