|
||||||||||
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.FixedLogicrateGame
public abstract class FixedLogicrateGame
A game that attempts to run at a fixed logic rate.
The main loop makes every effort to update at the specified rate. The goal is to keep a consistent game-play speed regardless of the frame rate achieved by the visuals (i.e. the game will render as fast as the hardware permits, while running it's logic at a fixed rate). This gives tighter control on how the game state is processed, including such things as AI and physics.
The concept behind this is forcing every game logic tick to represent a fixed amount of real-time. For example, if the logic is updated at a rate of 15 times per second, and we have a person moving at 30 pixels per second, each update the person should move 2 pixels. To compensate for the non-constant frame rate, we smooth the visuals using interpolation. So, if the scene is rendered twice without the game logic being updated, we do not render the same thing twice.
Using a fixed time-step model has a number of benefits: game logic is simplified as there is no longer any need to add time deltas to achieve frame rate independence. There is also a gain in efficiency as the logic can be run at a lower frequency than the rendering, meaning that the logic may be updated only once every second game - a net save in time. Finally, because the exact same sequence of game logic code is executed every time, the game becomes deterministic (that is to say, it will run the exact same way every time).
Further extension of this class could be used to integrate both a fixed logic rate and a fixed frame rate.
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 | |
---|---|
FixedLogicrateGame()
|
Method Summary | |
---|---|
protected abstract void |
cleanup()
Called once the game loop has finished. |
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 percentWithinTick)
Renders the scene. |
void |
setLogicTicksPerSecond(int tps)
setLogicTicksPerSecond sets the number of logic times per
second the game should update the logic. |
void |
start()
Ticks logic at a fixed rate while rendering as fast as hardware permits. |
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 FixedLogicrateGame()
Method Detail |
---|
public void setLogicTicksPerSecond(int tps)
setLogicTicksPerSecond
sets the number of logic times per
second the game should update the logic. This should not be called prior
to the application being start()
-ed.
tps
- the desired logic rate in ticks per secondpublic 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 percentWithinTick)
render
in class AbstractGame
percentWithinTick
- decimal value representing the position between update ticksAbstractGame.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 |