com.jme.app
Class BaseSimpleGame

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

public abstract class BaseSimpleGame
extends BaseGame

A game implementation that handles numerous common tasks.

This class implements all of the abstract methods and provides some default input handlers and code to report on memory usage and to display simple performance metrics on the screen.

All that is required to use this class is to build your scene graph (in simpleInitGame()) and add it to the rootNode.

A light state is provided with a single point light, (you can easily add more by accessing the lightState field) and there is an FPS and statistics display. The depth buffer compare function is automatically set to CF_LEQUAL. Wireframe mode and the lights may be toggled via T and L respectively.

Note that this class does not automatically render the root node, you need to do this yourself by overriding simpleRender(). If you need to update your game state then a corresponding simpleUpdate() hook is also provided.

Version:
$Revision: 4397 $, $Date: 2009-06-14 13:05:31 +0100 (Sun, 14 Jun 2009) $
Author:
Joshua Slack, (javadoc by cep21)

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.app.BaseGame
BaseGame.BaseGameSettings
 
Nested classes/interfaces inherited from class com.jme.app.AbstractGame
AbstractGame.ConfigShowMode
 
Field Summary
protected  int alphaBits
          Alpha bits to use for the renderer.
protected  Camera cam
          The camera that we see through.
protected  int depthBits
          Depth bits to use for the renderer.
protected  Node graphNode
          The root node for our stats graphs.
protected  InputHandler input
          Handles our mouse/keyboard input.
protected  LightState lightState
          A lightstate to turn on and off for the rootNode
protected  boolean pause
          boolean for toggling the simpleUpdate and geometric update parts of the game loop on and off.
protected  Node rootNode
          The root of our normal scene graph.
protected  int samples
          Number of samples to use for the multisample buffer.
protected  boolean showBounds
          True if the renderer should display bounds.
protected  boolean showDepth
          True if the renderer should display the depth buffer.
protected  boolean showGraphs
          True if the we should show the stats graphs.
protected  boolean showNormals
          True if the renderer should display normals.
protected  Node statNode
          The root node for our stats and text.
protected  int stencilBits
          Stencil bits to use for the renderer.
protected  Timer timer
          High resolution timer for jME.
protected  float tpf
          Simply an easy way to get at timer.getTimePerFrame().
protected  WireframeState wireState
          A wirestate to turn on and off for the rootNode
 
Fields inherited from class com.jme.app.BaseGame
throwableHandler
 
Fields inherited from class com.jme.app.AbstractGame
display, finished, settings
 
Constructor Summary
BaseSimpleGame()
           
 
Method Summary
protected  void cameraParallel()
           
protected  void cameraPerspective()
           
protected  void cleanup()
          Cleans up the keyboard.
protected  void doDebug(Renderer r)
           
protected  void initGame()
          Creates rootNode, lighting, statistic text, and other basic render states.
protected  void initSystem()
          Creates display, sets up camera, and binds keys.
protected  void quit()
          Calls the quit of BaseGame to clean up the display and then closes the JVM.
protected  void reinit()
          unused
protected  void render(float interpolation)
          Clears stats, the buffers and renders bounds and normals if on.
protected  void setupStatGraphs()
          Set up the graphers we will use and the quads we'll show the stats on.
protected  void setupStats()
          Set up which stats to graph
protected abstract  void simpleInitGame()
          Called near end of initGame().
protected  void simpleRender()
          Can be defined in derived classes for custom rendering.
protected  void simpleUpdate()
          Can be defined in derived classes for custom updating.
protected  void update(float interpolation)
          Updates the timer, sets tpf, updates the input and updates the fps string.
protected  void updateInput()
          Check for key/mouse updates.
 
Methods inherited from class com.jme.app.BaseGame
getNewSettings, getThrowableHandler, setThrowableHandler, start
 
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

cam

protected Camera cam
The camera that we see through.


rootNode

protected Node rootNode
The root of our normal scene graph.


input

protected InputHandler input
Handles our mouse/keyboard input.


timer

protected Timer timer
High resolution timer for jME.


statNode

protected Node statNode
The root node for our stats and text.


graphNode

protected Node graphNode
The root node for our stats graphs.


alphaBits

protected int alphaBits
Alpha bits to use for the renderer. Any changes must be made prior to call of start().


depthBits

protected int depthBits
Depth bits to use for the renderer. Any changes must be made prior to call of start().


stencilBits

protected int stencilBits
Stencil bits to use for the renderer. Any changes must be made prior to call of start().


samples

protected int samples
Number of samples to use for the multisample buffer. Any changes must be made prior to call of start().


tpf

protected float tpf
Simply an easy way to get at timer.getTimePerFrame(). Also saves math cycles since you don't call getTimePerFrame more than once per frame.


showDepth

protected boolean showDepth
True if the renderer should display the depth buffer.


showBounds

protected boolean showBounds
True if the renderer should display bounds.


showNormals

protected boolean showNormals
True if the renderer should display normals.


showGraphs

protected boolean showGraphs
True if the we should show the stats graphs.


wireState

protected WireframeState wireState
A wirestate to turn on and off for the rootNode


lightState

protected LightState lightState
A lightstate to turn on and off for the rootNode


pause

protected boolean pause
boolean for toggling the simpleUpdate and geometric update parts of the game loop on and off.

Constructor Detail

BaseSimpleGame

public BaseSimpleGame()
Method Detail

update

protected void update(float interpolation)
Updates the timer, sets tpf, updates the input and updates the fps string. Also checks keys for toggling pause, bounds, normals, lights, wire etc.

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

updateInput

protected void updateInput()
Check for key/mouse updates. Allow overriding this method to skip update in subclasses.


render

protected void render(float interpolation)
Clears stats, the buffers and renders bounds and normals if on.

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

doDebug

protected void doDebug(Renderer r)

initSystem

protected void initSystem()
                   throws JmeException
Creates display, sets up camera, and binds keys. Called in BaseGame.start() directly after the dialog box.

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

cameraPerspective

protected void cameraPerspective()

cameraParallel

protected void cameraParallel()

initGame

protected void initGame()
Creates rootNode, lighting, statistic text, and other basic render states. Called in BaseGame.start() after initSystem().

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

simpleInitGame

protected abstract void simpleInitGame()
Called near end of initGame(). Must be defined by derived classes.


simpleUpdate

protected void simpleUpdate()
Can be defined in derived classes for custom updating. Called every frame in update.


simpleRender

protected void simpleRender()
Can be defined in derived classes for custom rendering. Called every frame in render.


reinit

protected void reinit()
unused

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

cleanup

protected void cleanup()
Cleans up the keyboard.

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

quit

protected void quit()
Calls the quit of BaseGame to clean up the display and then closes the JVM.

Overrides:
quit in class BaseGame
See Also:
AbstractGame.quit()

setupStats

protected void setupStats()
Set up which stats to graph


setupStatGraphs

protected void setupStatGraphs()
Set up the graphers we will use and the quads we'll show the stats on.