com.jme.app
Class AbstractGame

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

public abstract class AbstractGame
extends java.lang.Object

AbstractGame defines a common method for implementing game functionality. Client applications should not subclass AbstractGame directly.

Version:
$Id: AbstractGame.java,v 1.20 2004/08/31 05:14:29 mojomonkey Exp $
Author:
Eric Woroshow

Field Summary
protected static int ALWAYS_SHOW_PROPS_DIALOG
          Always displays a PropertiesDialog on startup.
protected  DisplaySystem display
          Renderer used to display the game
protected  boolean finished
          Flag for running the system.
protected static int FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG
          Displays a PropertiesDialog only if the properties file is not found or could not be loaded.
protected static int NEVER_SHOW_PROPS_DIALOG
          Never displays a PropertiesDialog on startup, using defaults if no configuration file is found.
protected  PropertiesIO properties
          Game display properties.
 
Constructor Summary
AbstractGame()
           
 
Method Summary
protected  void assertDisplayCreated()
          assertDisplayCreated determines if the display system was successfully created before use.
protected abstract  void cleanup()
          cleanup cleans up any created objects before exiting the application.
 void finish()
          finish breaks out of the main game loop.
protected  void getAttributes()
          getAttributes attempts to first obtain the properties information from the "properties.cfg" file, then a dialog depending on the dialog behaviour.
 java.lang.String getVersion()
          getVersion returns the version of the API.
protected abstract  void initGame()
          initGame creates and initializes all game data required for startup.
protected abstract  void initSystem()
          initSystem creates all the necessary system components for the client application.
protected abstract  void quit()
          quit exits the program.
protected abstract  void reinit()
          reinit rebuilds the subsystems.
protected abstract  void render(float interpolation)
          render displays the game information to the OpenGL context.
 void setDialogBehaviour(int behaviour)
          setDialogBehaviour defines if and when the display properties dialog should be shown.
 void setDialogBehaviour(int behaviour, java.lang.String image)
          setDialogBehaviour defines if and when the display properties dialog should be shown as well as its accompanying image.
 void setDialogBehaviour(int behaviour, java.net.URL image)
          setDialogBehaviour sets how the properties dialog should appear.
abstract  void start()
          start begins the game.
protected abstract  void update(float interpolation)
          update updates 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.


NEVER_SHOW_PROPS_DIALOG

protected static final int NEVER_SHOW_PROPS_DIALOG
Never displays a PropertiesDialog on startup, using defaults if no configuration file is found.

See Also:
Constant Field Values

FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG

protected static final int FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG
Displays a PropertiesDialog only if the properties file is not found or could not be loaded.

See Also:
Constant Field Values

ALWAYS_SHOW_PROPS_DIALOG

protected static final int ALWAYS_SHOW_PROPS_DIALOG
Always displays a PropertiesDialog on startup.

See Also:
Constant Field Values

properties

protected PropertiesIO properties
Game display properties.


display

protected DisplaySystem display
Renderer used to display the game

Constructor Detail

AbstractGame

public 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

setDialogBehaviour

public void setDialogBehaviour(int behaviour)
setDialogBehaviour defines if and when the display properties dialog should be shown. Setting the behaviour after start has been called has no effect.

Parameters:
behaviour - properties dialog behaviour ID

setDialogBehaviour

public void setDialogBehaviour(int behaviour,
                               java.lang.String image)
setDialogBehaviour 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:
behaviour - properties dialog behaviour ID
image - a String specifying the filename of an image to be displayed with the PropertiesDialog. Passing null will result in no image being used.

setDialogBehaviour

public void setDialogBehaviour(int behaviour,
                               java.net.URL image)
setDialogBehaviour sets how the properties dialog should appear. ALWAYS_SHOW_PROPS, NEVER_SHOW_PROPS and FIRSTRUN_OR_NOCONFIGFILE are the three valid choices. The url of an image file is also used so you can customize the dialog.

Parameters:
behaviour - ALWAYS_SHOW_PROPS, NEVER_SHOW_PROPS and FIRSTRUN_OR_NOCONFIGFILE are the valid choices.
image - the image to display in the box.

getAttributes

protected void getAttributes()
getAttributes attempts to first obtain the properties information from the "properties.cfg" file, 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 updates the game state. Physics, AI, networking, score checking and like should be completed in this method. How often and when this method is called depends on the main loop implementation.

Parameters:
interpolation - definition varies on implementation, -1.0f if unused

render

protected abstract void render(float interpolation)
render displays the game information to the OpenGL context. Nothing altering the game state should be run during a render. How often and when this method is called depends on the main loop implementation.

Parameters:
interpolation - definition varies on implementation, -1.0f if unused

initSystem

protected abstract void initSystem()
initSystem creates all the necessary system components for the client application. It is is called once after start is called. The display must be initialized within this method.


initGame

protected abstract void initGame()
initGame creates and initializes all game data required for startup. It is suggested that caching of frequently used resources is done within this method. It is called once after initSystem has completed.


reinit

protected abstract void reinit()
reinit rebuilds the subsystems. It may be called at any time by the client application.


cleanup

protected abstract void cleanup()
cleanup cleans up any created objects before exiting the application. It is called once after finish is called.