|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.app.AbstractGame
public abstract class AbstractGame
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:
initSystem()
- initialise the system (e.g. the display system);initGame()
- initialise the game (e.g. warm up caches);finish()
is called:
update(float)
- update the game data;render(float)
- render the updated data;cleanup()
- free up any resources.This class is not intended to be directly extended by client applications.
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 |
---|
protected boolean finished
protected GameSettings settings
protected DisplaySystem display
Constructor Detail |
---|
protected AbstractGame()
Method Detail |
---|
public java.lang.String getVersion()
getVersion
returns the version of the API.
protected void assertDisplayCreated() throws JmeException
assertDisplayCreated
determines if the display system was
successfully created before use.
JmeException
- if the display system was not successfully createdpublic void setConfigShowMode(AbstractGame.ConfigShowMode mode)
Setting the behaviour after start()
has been called has no
effect.
mode
- the properties dialog behaviour.setConfigShowMode(ConfigShowMode, URL)
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.
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").protected abstract GameSettings getNewSettings()
protected void getAttributes()
getAttributes
attempts to first obtain the properties
information from a GameSettings load, then a dialog depending on
the dialog behaviour.
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.
public void finish()
finish
breaks out of the main game loop. It is preferable
to call finish
instead of quit
.
protected abstract void quit()
quit
exits the program. By default, it simply uses the
System.exit()
method.
protected abstract void update(float interpolation)
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.
interpolation
- definition varies on implementation, -1.0f if unusedrender(float)
protected abstract void render(float interpolation)
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.
interpolation
- definition varies on implementation, -1.0f if unusedupdate(float)
protected abstract void initSystem()
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.
protected abstract void initGame()
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.
protected abstract void reinit()
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.
protected abstract void cleanup()
Subclasses should use this method to release any resources, for example
data that was loaded in the initXXX()
methods.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |