com.jme.app
Class BaseGame

java.lang.Object
  extended by com.jme.app.AbstractGame
      extended by com.jme.app.BaseGame
Direct Known Subclasses:
BaseSimpleGame

public abstract class BaseGame
extends AbstractGame

The simplest possible implementation of a game loop.

This class defines a pure high speed game loop that runs as fast as CPU/GPU will allow. No handling of variable frame rates is included and, as a result, this class is unsuitable for most production applications; it is useful as a base for applications which require more specialised behaviour as it includes basic game configuration code.

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

Nested Class Summary
(package private) static class BaseGame.BaseGameSettings
          A PropertiesGameSettings which defaults Fullscreen to TRUE.
 
Nested classes/interfaces inherited from class com.jme.app.AbstractGame
AbstractGame.ConfigShowMode
 
Field Summary
protected  ThrowableHandler throwableHandler
           
 
Fields inherited from class com.jme.app.AbstractGame
display, finished, settings
 
Constructor Summary
BaseGame()
           
 
Method Summary
protected abstract  void cleanup()
          Called once the game loop has finished.
protected  GameSettings getNewSettings()
          Subclasses must implement getNewSettings to instantiate and populate a GameSettings object.
protected  ThrowableHandler getThrowableHandler()
          Get the exception handler if one hs been set.
protected abstract  void initGame()
          Create and initialise all game data.
protected abstract  void initSystem()
          Initialise the display system.
protected  void quit()
          Closes the display
protected abstract  void reinit()
          Rebuild the system.
protected abstract  void render(float interpolation)
          Display the updated game information.
protected  void setThrowableHandler(ThrowableHandler throwableHandler)
           
 void start()
          The simplest main game loop possible: render and update as fast as possible.
protected abstract  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

throwableHandler

protected ThrowableHandler throwableHandler
Constructor Detail

BaseGame

public BaseGame()
Method Detail

start

public final void start()
The simplest main game loop possible: render and update as fast as possible.

Specified by:
start in class AbstractGame

quit

protected void quit()
Closes the display

Specified by:
quit in class AbstractGame
See Also:
AbstractGame.quit()

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 -

update

protected abstract void update(float interpolation)
Description copied from class: AbstractGame
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.

Specified by:
update in class AbstractGame
Parameters:
interpolation - unused in this implementation
See Also:
AbstractGame.update(float interpolation)

render

protected abstract void render(float interpolation)
Description copied from class: AbstractGame
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.

Specified by:
render in class AbstractGame
Parameters:
interpolation - unused in this implementation
See Also:
AbstractGame.render(float interpolation)

initSystem

protected abstract void initSystem()
Description copied from class: AbstractGame
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.

Specified by:
initSystem in class AbstractGame
See Also:
AbstractGame.initSystem()

initGame

protected abstract void initGame()
Description copied from class: AbstractGame
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 AbstractGame.initSystem() has completed.

Specified by:
initGame in class AbstractGame
See Also:
AbstractGame.initGame()

reinit

protected abstract void reinit()
Description copied from class: AbstractGame
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.

Specified by:
reinit in class AbstractGame
See Also:
AbstractGame.reinit()

cleanup

protected abstract void cleanup()
Description copied from class: AbstractGame
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.

Specified by:
cleanup in class AbstractGame
See Also:
AbstractGame.cleanup()

getNewSettings

protected GameSettings getNewSettings()
Description copied from class: AbstractGame
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.

Specified by:
getNewSettings in class AbstractGame
See Also:
AbstractGame.getNewSettings()