game
Class CGameLoop

java.lang.Object
  extended by game.CGameLoop
All Implemented Interfaces:
java.lang.Runnable

public class CGameLoop
extends java.lang.Object
implements java.lang.Runnable

Game loop implementation, can be frame or time based. Associated to an IGame object.

Author:
sroccaserra

Field Summary
static int FRAME_BASED
           
private  java.lang.Thread m_animationThread
           
private  int m_animationType
           
private  CAverageTimer m_averageTimer
           
private  float m_fps
           
private  float m_fTheoricFps
           
private  IGame m_game
           
private  long m_msLastRecordedTime
           
private  long m_msTheoricFrameTime
           
private  int m_nbFramesPerRecord
           
private  int m_nbRecordedFrames
           
static int TIME_BASED
           
 
Constructor Summary
CGameLoop(IGame game, int animationType, float fps)
          Constructor.
 
Method Summary
private  float getDt()
          Computes the amount of time the animation should advance of.
 float getFps()
          Effective framerate.
private  void initRecord()
          Used for effective framerate evaluation.
 void run()
          Runs the loop thread.
 void setTheoricFps(float fTheoricFps)
          Sets the theoric framerate.
 void start()
          Inits and starts the loop thread.
 void stop()
          Stops the loop thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIME_BASED

public static final int TIME_BASED
See Also:
Constant Field Values

FRAME_BASED

public static final int FRAME_BASED
See Also:
Constant Field Values

m_fTheoricFps

private float m_fTheoricFps

m_fps

private float m_fps

m_msTheoricFrameTime

private long m_msTheoricFrameTime

m_msLastRecordedTime

private long m_msLastRecordedTime

m_nbFramesPerRecord

private int m_nbFramesPerRecord

m_nbRecordedFrames

private int m_nbRecordedFrames

m_animationType

private int m_animationType

m_animationThread

private volatile java.lang.Thread m_animationThread

m_game

private IGame m_game

m_averageTimer

private CAverageTimer m_averageTimer
Constructor Detail

CGameLoop

public CGameLoop(IGame game,
                 int animationType,
                 float fps)
Constructor.

Parameters:
game - : the game to be animated and drawn by this loop
animationType - : frame or time based
fps - : the theoric framerate to sustain.
Method Detail

start

public void start()
Inits and starts the loop thread.


stop

public void stop()
Stops the loop thread.


run

public void run()
Runs the loop thread.

Specified by:
run in interface java.lang.Runnable

getDt

private final float getDt()
Computes the amount of time the animation should advance of. This value is constant if the animation is frame based.

Returns:
the game time elapsed since last frame.

setTheoricFps

public void setTheoricFps(float fTheoricFps)
Sets the theoric framerate.

Parameters:
fTheoricFps - : the theoric framerate to sustain.

getFps

public float getFps()
Effective framerate.


initRecord

private void initRecord()
Used for effective framerate evaluation.