org.jrabbit.base.core.loop
Class Loop

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

public abstract class Loop
extends java.lang.Object
implements Updateable, Renderable

A time-controlled loop that is intended to form the base of any singly threaded game. The general process is: 1: Update time step. 2: Update the game. 3: Render the game. 4: Sleep the loop to control frame rate and save system resources. It also has methods to execute commands before and after the loop begins and ends. The loop can be told to stop execution via the exit() command. Note that this doesn't shut down the loop immediately, but allows the frame to finish.

Author:
Chris Molini

Field Summary
protected  LoopController controller
          Controls the timing and resolution of the game loop.
protected  boolean exit
          A boolean that controls if the loop should continue.
 
Constructor Summary
Loop()
          Creates a Loop with a default time controller.
 
Method Summary
 LoopController controller()
          Gains access to the loop's execution controller.
protected  void end()
          Can be overridden to make the loop call particular commands after execution.
 void exit()
          Flags the loop to stop after the current cycle is finished.
 void render()
          Renders the object.
 void run()
          Calls the loop's execution cycle.
protected  void start()
          Can be overridden to make the loop call particular commands before execution.
 void update(int delta)
          Updates the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exit

protected boolean exit
A boolean that controls if the loop should continue.


controller

protected LoopController controller
Controls the timing and resolution of the game loop.

Constructor Detail

Loop

public Loop()
Creates a Loop with a default time controller.

Method Detail

run

public void run()
Calls the loop's execution cycle. Automatically calls start() and end() before and after the actually looping process.


start

protected void start()
Can be overridden to make the loop call particular commands before execution.


end

protected void end()
Can be overridden to make the loop call particular commands after execution.


update

public void update(int delta)
Description copied from interface: Updateable
Updates the object.

Specified by:
update in interface Updateable
Parameters:
delta - The time passed since the last update. The default units are in microseconds.

render

public void render()
Description copied from interface: Renderable
Renders the object.

Specified by:
render in interface Renderable

exit

public void exit()
Flags the loop to stop after the current cycle is finished.


controller

public LoopController controller()
Gains access to the loop's execution controller.

Returns:
The object that controls both the loop's rate of execution and the resolution of update commands.