org.xith3d.loop
Class UpdatingThread

java.lang.Object
  extended by org.xith3d.loop.UpdatingThread
All Implemented Interfaces:
java.lang.Runnable, GameTimeHost, Updatable
Direct Known Subclasses:
OperationSchedulerImpl, OperationSchedulerQueue, RenderLoop

public abstract class UpdatingThread
extends java.lang.Object
implements java.lang.Runnable, Updatable, GameTimeHost

This is the base for any threaded operation. RenderLoop uses it and you can use it in OperationScheduler, etc.


Nested Class Summary
static class UpdatingThread.TimingMode
          This enum contains constants to control the timing of this thread.
 
Field Summary
static int PAUSE_NONE
           
static int PAUSE_TOTAL
           
 
Constructor Summary
UpdatingThread()
           
UpdatingThread(GameTimeHost gameTimeHost)
           
UpdatingThread(long minItTime)
           
UpdatingThread(long minItTime, GameTimeHost gameTimeHost)
           
 
Method Summary
protected  void begin(boolean startNewThread)
           
 void end()
           
 FPSLimiter getFPSLimiter()
           
 long getGameMicroTime()
          
 long getGameMilliTime()
          
 long getGameNanoTime()
          
 long getGameTime()
          
 long getIterationsCount()
           
 long getLastFrameTime()
          
 long getLastNanoFrameTime()
          
 long getMinIterationTime()
           
 int getPauseMode()
           
 java.lang.Thread getThread()
           
 org.jagatoo.util.timing.TimerInterface getTimer()
           
 UpdatingThread.TimingMode getTimingMode()
           
 boolean isRunning()
           
protected  boolean isStopping()
           
protected  void loop()
          This method defines the main loop of the Thread.
protected  long nextIteration(boolean force)
           
 void run()
          
 void setFPSLimiter(FPSLimiter fpsLimiter)
          Sets the FPSLimiter capable of limiting the FPS/iteration time.
protected  void setMinIterationTime(long minItTime)
          Sets the minimum time, an iteration must take.
 void setPauseMode(int pauseMode)
          Sets the pauseMode.
 void setTimer(org.jagatoo.util.timing.TimerInterface timer)
          Sets the timer used by the loop.
 void setTimingMode(UpdatingThread.TimingMode mode)
          Sets the timing mode for the frameTime.
abstract  void update(long gameTime, long frameTime, UpdatingThread.TimingMode timingMode)
          Updates this Updatable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAUSE_NONE

public static final int PAUSE_NONE
See Also:
Constant Field Values

PAUSE_TOTAL

public static final int PAUSE_TOTAL
See Also:
Constant Field Values
Constructor Detail

UpdatingThread

public UpdatingThread(long minItTime,
                      GameTimeHost gameTimeHost)

UpdatingThread

public UpdatingThread(long minItTime)

UpdatingThread

public UpdatingThread(GameTimeHost gameTimeHost)

UpdatingThread

public UpdatingThread()
Method Detail

setTimer

public final void setTimer(org.jagatoo.util.timing.TimerInterface timer)
Sets the timer used by the loop.

Parameters:
timer - could be an instance of org.xith3d.utility.timing.JavaTimer, e.g.

getTimer

public final org.jagatoo.util.timing.TimerInterface getTimer()
Returns:
the timer used by the loop.

setMinIterationTime

protected final void setMinIterationTime(long minItTime)
Sets the minimum time, an iteration must take.

Parameters:
minItTime -

getMinIterationTime

public final long getMinIterationTime()
Returns:
the minimum time, an iteration must take.

setFPSLimiter

public void setFPSLimiter(FPSLimiter fpsLimiter)
Sets the FPSLimiter capable of limiting the FPS/iteration time.

Parameters:
fpsLimiter -

getFPSLimiter

public final FPSLimiter getFPSLimiter()
Returns:
the FPSLimiter capable of limiting the FPS/iteration time.

getIterationsCount

public final long getIterationsCount()
Returns:
the count of iterations done by this RenderLoop

setTimingMode

public final void setTimingMode(UpdatingThread.TimingMode mode)
Sets the timing mode for the frameTime.

Specified by:
setTimingMode in interface GameTimeHost
Parameters:
mode -

getTimingMode

public final UpdatingThread.TimingMode getTimingMode()
Specified by:
getTimingMode in interface GameTimeHost
Returns:
the timing mode for the frameTime.

getGameNanoTime

public final long getGameNanoTime()

Specified by:
getGameNanoTime in interface GameTimeHost
Returns:
the number of nanoseconds the game is running.

getGameMicroTime

public final long getGameMicroTime()

Specified by:
getGameMicroTime in interface GameTimeHost
Returns:
the number of microseconds the game is running.

getGameMilliTime

public final long getGameMilliTime()

Specified by:
getGameMilliTime in interface GameTimeHost
Returns:
the number of milliseconds the game is running.

getGameTime

public final long getGameTime()

Specified by:
getGameTime in interface GameTimeHost
Returns:
the time, the game is running. This number depends on the current UpdatingThread.TimingMode.
See Also:
GameTimeHost.getTimingMode()

getLastNanoFrameTime

public final long getLastNanoFrameTime()

Specified by:
getLastNanoFrameTime in interface GameTimeHost
Returns:
the number of nanoseconds the last frame took.

getLastFrameTime

public final long getLastFrameTime()

Specified by:
getLastFrameTime in interface GameTimeHost
Returns:
the number of time-slices (depending on the UpdatingThread.TimingMode) the last frame took.

setPauseMode

public final void setPauseMode(int pauseMode)
Sets the pauseMode.

Parameters:
pauseMode -
See Also:
PAUSE_NONE, PAUSE_TOTAL

getPauseMode

public final int getPauseMode()
Returns:
the pauseMode.
See Also:
PAUSE_NONE, PAUSE_TOTAL

update

public abstract void update(long gameTime,
                            long frameTime,
                            UpdatingThread.TimingMode timingMode)
Updates this Updatable object.

Specified by:
update in interface Updatable
Parameters:
gameTime - the gameTime in Milliseconds
frameTime - the frameTime in Milliseconds (needed time for the last frame)
timingMode - the TimingMode to use for frameTime.

nextIteration

protected long nextIteration(boolean force)

isStopping

protected final boolean isStopping()

loop

protected void loop()
This method defines the main loop of the Thread.
Override it to change its behavior.


run

public void run()

Specified by:
run in interface java.lang.Runnable

getThread

public java.lang.Thread getThread()
Returns:
the Thread, that runs this loop.

isRunning

public boolean isRunning()
Returns:
true, if this thread is running.

begin

protected void begin(boolean startNewThread)

end

public void end()