org.jrabbit.standard.game.loop
Class GameLoop

java.lang.Object
  extended by org.jrabbit.base.core.loop.Loop
      extended by org.jrabbit.standard.game.loop.GameLoop
All Implemented Interfaces:
Renderable, Updateable
Direct Known Subclasses:
StandardGame

public class GameLoop
extends Loop

A GameLoop is an advanced Loop that has more defined methods for running a game. It also has a built-in profiler that is useful for monitoring the game's performance as it plays. A GameLoop contains a World reference that it continuously updates and renders. Essentially, the game IS that world. This reference is dynamic and can switch between different worlds on the fly (allowing the user to have different levels, types of gameplay, etc. very easily). However, it should be noted that if a World is being updated and rendered in one game cycle, it will finish that cycle before anything happens to the newly set World.

Author:
Chris Molini

Field Summary
private  World activeWorld
          The World currently being updated and rendered.
protected  GameLoopProfiler profiler
          The profiler that the GameLoop uses to determine how well the game engine is performing.
protected  World world
          The general World reference.
 
Fields inherited from class org.jrabbit.base.core.loop.Loop
controller, exit
 
Constructor Summary
GameLoop()
          Creates a GameLoop that uses a default World and a default GameLoopProfiler.
GameLoop(World world)
          Creates a GameLoop that starts out with the indicated World.
GameLoop(World world, GameLoopProfiler profiler)
          Creates a GameLoop with the indicated World and Profiler.
 
Method Summary
 void advanceGame(int delta)
          This method can be used to put additional logic code in GameLoop that is independent of the current World.
protected  void end()
          Flags the GameManager that this GameLoop has finished and should be removed from the stack.
 ProfilerDisplay profiler()
          Accesses this GameLoop's profiler.
 void render()
          Renders the game and profiler information, measuring the amount of time taken.
 void run()
          Loops the game, updating and rendering as necessary.
 void setProfiler(GameLoopProfiler profiler)
          Redefines the object the GameLoop uses to profile its performance.
 void setWorld(World world)
          Redefines the current gameworld.
protected  void start()
          Tells the GameManager that this GameLoop is beginning, and pushes it on top of the stack.
 void update(int delta)
          Updates the game.
 World world()
          Accesses the World the GameLoop is currently using.
 
Methods inherited from class org.jrabbit.base.core.loop.Loop
controller, exit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

profiler

protected GameLoopProfiler profiler
The profiler that the GameLoop uses to determine how well the game engine is performing.


world

protected World world
The general World reference.


activeWorld

private World activeWorld
The World currently being updated and rendered.

Constructor Detail

GameLoop

public GameLoop()
Creates a GameLoop that uses a default World and a default GameLoopProfiler.


GameLoop

public GameLoop(World world)
Creates a GameLoop that starts out with the indicated World. It uses a default GameLoopProfiler.

Parameters:
world - The World for the GameLoop to initially update and render.

GameLoop

public GameLoop(World world,
                GameLoopProfiler profiler)
Creates a GameLoop with the indicated World and Profiler.

Parameters:
world - The World for the GameLoop to initially update and render.
profiler - The GameLoopProfiler used to profile the game's performance.
Method Detail

profiler

public ProfilerDisplay profiler()
Accesses this GameLoop's profiler.

Returns:
The PofilerDisplay used to monitor this GameLoop's performance.

setProfiler

public void setProfiler(GameLoopProfiler profiler)
Redefines the object the GameLoop uses to profile its performance.

Parameters:
profiler - The new GameLoopProfiler to use.

world

public World world()
Accesses the World the GameLoop is currently using.

Returns:
The current gameworld.

setWorld

public void setWorld(World world)
Redefines the current gameworld.

Parameters:
world - The new World to use in updating and rendering.

start

protected void start()
Tells the GameManager that this GameLoop is beginning, and pushes it on top of the stack.

Overrides:
start in class Loop

run

public void run()
Loops the game, updating and rendering as necessary.

Overrides:
run in class Loop

end

protected void end()
Flags the GameManager that this GameLoop has finished and should be removed from the stack.

Overrides:
end in class Loop

advanceGame

public void advanceGame(int delta)
This method can be used to put additional logic code in GameLoop that is independent of the current World. An example would be a check determining is the user has elected to exit the game (by pressing ESC or something similar).

Parameters:
delta - The number of clock ticks that have passed since the last update.

update

public void update(int delta)
Updates the game.

Specified by:
update in interface Updateable
Overrides:
update in class Loop
Parameters:
delta - The number of clock ticks that have passed since the last update.

render

public void render()
Renders the game and profiler information, measuring the amount of time taken.

Specified by:
render in interface Renderable
Overrides:
render in class Loop