|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.app.AbstractGame
com.jme.app.FixedFramerateGame
public abstract class FixedFramerateGame
A game that attempts to run at a fixed frame rate.
The main loop makes every effort to render at the specified rate, however this is not guaranteed and the frame rate may dip below the desired value. The game logic is updated at the same rate as the rendering; for example, if the rendering is running at 60 frames per second, the logic will also be updated 60 times per second.
Limiting the frame rate of the game is useful for playing nice with the underlying operating system. That is, if the game loop is left unchecked, it tends to use up 100% of the CPU cycles; while this may be fine for fullscreen applications (as it will yield to important processes) it can cause issues with applications running in a normal window.
If no frame rate is specified, the game will run at 60 frames per second.
Note that setFrameRate(int)
cannot be called prior to calling
start()
or a NullPointerException
will be thrown.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.jme.app.AbstractGame |
---|
AbstractGame.ConfigShowMode |
Field Summary |
---|
Fields inherited from class com.jme.app.AbstractGame |
---|
display, finished, settings |
Constructor Summary | |
---|---|
FixedFramerateGame()
|
Method Summary | |
---|---|
protected abstract void |
cleanup()
Called once the game loop has finished. |
float |
getFramesPerSecond()
Gets the current frame rate. |
protected abstract void |
initGame()
Create and initialise all game data. |
protected abstract void |
initSystem()
Initialise the display system. |
protected void |
quit()
Quits the program abruptly using System.exit . |
protected abstract void |
reinit()
Rebuild the system. |
protected abstract void |
render(float interpolation)
Display the updated game information. |
void |
setFrameRate(int fps)
Set preferred frame rate. |
void |
start()
Render and update logic at a specified fixed rate. |
protected abstract void |
update(float interpolation)
Update the game state. |
Methods inherited from class com.jme.app.AbstractGame |
---|
assertDisplayCreated, finish, getAttributes, getNewSettings, getVersion, setConfigShowMode, setConfigShowMode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FixedFramerateGame()
Method Detail |
---|
public void setFrameRate(int fps)
start()
-ed.
fps
- the desired frame rate in frames per secondpublic float getFramesPerSecond()
public final void start()
start
in class AbstractGame
protected void quit()
System.exit
.
quit
in class AbstractGame
AbstractGame.quit()
protected abstract void update(float interpolation)
AbstractGame
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.
update
in class AbstractGame
interpolation
- unused in this implementationAbstractGame.update(float interpolation)
protected abstract void render(float interpolation)
AbstractGame
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.
render
in class AbstractGame
interpolation
- unused in this implementationAbstractGame.render(float interpolation)
protected abstract void initSystem()
AbstractGame
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.
initSystem
in class AbstractGame
AbstractGame.initSystem()
protected abstract void initGame()
AbstractGame
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.
initGame
in class AbstractGame
AbstractGame.initGame()
protected abstract void reinit()
AbstractGame
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.
reinit
in class AbstractGame
AbstractGame.reinit()
protected abstract void cleanup()
AbstractGame
Subclasses should use this method to release any resources, for example
data that was loaded in the initXXX()
methods.
cleanup
in class AbstractGame
AbstractGame.cleanup()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |