|
|||||||||||
| 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
FixedLogicrateGame implements a main-loop designed to acheive
frame rate independence. The goal is to keep a consistent gameplay speed
regardless of the framerate acheived by the visuals. The game renders as fast
as the hardware permits, while running the game logic at a fixed rate. 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-timestep model has a number of benefits. Game logic is
simplified as there is no longer any need to add "*deltaTime" to acheive
frame rate independence. There is also a gain in efficiency: 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. In addition,
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.
| Field Summary |
| Fields inherited from class com.jme.app.AbstractGame |
ALWAYS_SHOW_PROPS_DIALOG, display, finished, FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG, NEVER_SHOW_PROPS_DIALOG, properties |
| Constructor Summary | |
FixedLogicrateGame()
|
|
| Method Summary | |
protected abstract void |
cleanup()
cleanup cleans up any created objects before exiting the
application. |
protected abstract void |
initGame()
initGame creates and initializes all game data required
for startup. |
protected abstract void |
initSystem()
initSystem creates all the necessary system components
for the client application. |
protected void |
quit()
Quits the program abruptly using System.exit. |
protected abstract void |
reinit()
reinit rebuilds the subsystems. |
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 updates the game state. |
| Methods inherited from class com.jme.app.AbstractGame |
assertDisplayCreated, finish, getAttributes, getVersion, setDialogBehaviour, setDialogBehaviour, setDialogBehaviour |
| 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 AbstractGameprotected void quit()
System.exit.
quit in class AbstractGameAbstractGame.quit()protected abstract void update(float interpolation)
AbstractGameupdate updates the game state. Physics, AI, networking, score
checking and like should be completed in this method. How often and when
this method is called depends on the main loop implementation.
update in class AbstractGameinterpolation - unused in this implementationAbstractGame.update(float interpolation)protected abstract void render(float percentWithinTick)
render in class AbstractGamepercentWithinTick - decimal value representing the position between update ticksAbstractGame.render(float interpolation)protected abstract void initSystem()
AbstractGameinitSystem creates all the necessary system components
for the client application. It is is called once after start
is called. The display must be initialized within this method.
initSystem in class AbstractGameAbstractGame.initSystem()protected abstract void initGame()
AbstractGameinitGame creates and initializes all game data required
for startup. It is suggested that caching of frequently used resources
is done within this method. It is called once after initSystem
has completed.
initGame in class AbstractGameAbstractGame.initGame()protected abstract void reinit()
AbstractGamereinit rebuilds the subsystems. It may be called at any time
by the client application.
reinit in class AbstractGameAbstractGame.reinit()protected abstract void cleanup()
AbstractGamecleanup cleans up any created objects before exiting the
application. It is called once after finish is called.
cleanup in class AbstractGameAbstractGame.cleanup()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||