Package de.gurkenlabs.litiengine
Class GameLoop
java.lang.Object
java.lang.Thread
de.gurkenlabs.litiengine.UpdateLoop
de.gurkenlabs.litiengine.GameLoop
- All Implemented Interfaces:
IGameLoop
,ILaunchable
,ILoop
,java.lang.AutoCloseable
,java.lang.Runnable
public final class GameLoop
extends UpdateLoop
implements IGameLoop
The main update loop that executes the game logic by calling the update functions on all registered
IUpdatable
instances.
Subsequently, it performs the rendering of the current frame and tracks some performance metrics on the process.Nested Class Summary
Field Summary
Fields Modifier and Type Field Description static int
TICK_DELTATIME_LAG
The tickUpdateLoop.getDeltaTime()
at which we consider the game not to run fluently anymore.Method Summary
Modifier and Type Method Description void
alterExecutionTime(int index, long ticks)
Alters the execution time of the timed action with the specified index to the defined tick.protected long
getExpectedDelta()
float
getTimeScale()
Gets the game loop's current time scale (default = 1).int
perform(int delay, java.lang.Runnable action)
Performs a timed action with the specified delay in ms.protected void
process()
In addition to the normal base implementation, theGameLoop
performs registered action at the required time and tracks some detailed metrics.void
removeAction(int id)
Removes theTimedAction
with the specified it.void
setTimeScale(float timeScale)
Sets the game loop's time scale.Methods inherited from class de.gurkenlabs.litiengine.UpdateLoop
attach, close, delay, detach, getDeltaTime, getLock, getProcessTime, getTickRate, getTicks, getUpdatableCount, getUpdatables, run, setTickRate, terminate, update
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface de.gurkenlabs.litiengine.ILoop
attach, detach, getDeltaTime, getLock, getProcessTime, getTickRate, getTicks, getUpdatableCount, setTickRate
Field Details
TICK_DELTATIME_LAG
public static final int TICK_DELTATIME_LAGThe tickUpdateLoop.getDeltaTime()
at which we consider the game not to run fluently anymore.- 16.6 ms: 60 FPS
- 33.3 ms: 30 FPS
- 66.6 ms: 15 FPS
- See Also:
- Constant Field Values
Method Details
perform
public int perform(int delay, java.lang.Runnable action)Description copied from interface:IGameLoop
Performs a timed action with the specified delay in ms.- Specified by:
perform
in interfaceIGameLoop
- Parameters:
delay
- The delay in milliseconds.action
- The action to perform, once the delay has passed.- Returns:
- The id of the
TimedAction
that can be used to alter the execution time of the action or remove it. - See Also:
IGameLoop.alterExecutionTime(int, long)
getTimeScale
public float getTimeScale()Description copied from interface:IGameLoop
Gets the game loop's current time scale (default = 1).- Specified by:
getTimeScale
in interfaceIGameLoop
- Returns:
- The game loop's current time scale.
setTimeScale
public void setTimeScale(float timeScale)Description copied from interface:IGameLoop
Sets the game loop's time scale.This can be used to fast-forward the gameplay or to introduce slow-motion effects.
- Specified by:
setTimeScale
in interfaceIGameLoop
- Parameters:
timeScale
- The time scale to set.
alterExecutionTime
public void alterExecutionTime(int index, long ticks)Description copied from interface:IGameLoop
Alters the execution time of the timed action with the specified index to the defined tick. This overwrites the originally specified delay.- Specified by:
alterExecutionTime
in interfaceIGameLoop
- Parameters:
index
- The id of theTimedAction
.ticks
- The tick at which to perform the action instead.
removeAction
public void removeAction(int id)Description copied from interface:IGameLoop
Removes theTimedAction
with the specified it.- Specified by:
removeAction
in interfaceIGameLoop
- Parameters:
id
- The id of theTimedAction
.
process
protected void process()In addition to the normal base implementation, theGameLoop
performs registered action at the required time and tracks some detailed metrics.- Overrides:
process
in classUpdateLoop
getExpectedDelta
protected long getExpectedDelta()- Overrides:
getExpectedDelta
in classUpdateLoop