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 IGameLoopThe 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 intTICK_DELTATIME_LAGThe tickUpdateLoop.getDeltaTime()at which we consider the game not to run fluently anymore.Method Summary
Modifier and Type Method Description voidalterExecutionTime(int index, long ticks)Alters the execution time of the timed action with the specified index to the defined tick.protected longgetExpectedDelta()floatgetTimeScale()Gets the game loop's current time scale (default = 1).intperform(int delay, java.lang.Runnable action)Performs a timed action with the specified delay in ms.protected voidprocess()In addition to the normal base implementation, theGameLoopperforms registered action at the required time and tracks some detailed metrics.voidremoveAction(int id)Removes theTimedActionwith the specified it.voidsetTimeScale(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, updateMethods 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, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:IGameLoopPerforms a timed action with the specified delay in ms.- Specified by:
performin interfaceIGameLoop- Parameters:
delay- The delay in milliseconds.action- The action to perform, once the delay has passed.- Returns:
- The id of the
TimedActionthat 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:IGameLoopGets the game loop's current time scale (default = 1).- Specified by:
getTimeScalein interfaceIGameLoop- Returns:
- The game loop's current time scale.
setTimeScale
public void setTimeScale(float timeScale)Description copied from interface:IGameLoopSets the game loop's time scale.This can be used to fast-forward the gameplay or to introduce slow-motion effects.
- Specified by:
setTimeScalein interfaceIGameLoop- Parameters:
timeScale- The time scale to set.
alterExecutionTime
public void alterExecutionTime(int index, long ticks)Description copied from interface:IGameLoopAlters the execution time of the timed action with the specified index to the defined tick. This overwrites the originally specified delay.- Specified by:
alterExecutionTimein 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:IGameLoopRemoves theTimedActionwith the specified it.- Specified by:
removeActionin interfaceIGameLoop- Parameters:
id- The id of theTimedAction.
process
protected void process()In addition to the normal base implementation, theGameLoopperforms registered action at the required time and tracks some detailed metrics.- Overrides:
processin classUpdateLoop
getExpectedDelta
protected long getExpectedDelta()- Overrides:
getExpectedDeltain classUpdateLoop
