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,AutoCloseable,Runnable
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.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe tickUpdateLoop.getDeltaTime()at which we consider the game not to run fluently anymore.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Method Summary
Modifier and TypeMethodDescriptionvoidalterExecutionTime(int index, long ticks) Alters the execution time of the timed action with the specified index to the defined tick.protected longfloatGets the game loop's current time scale (default = 1).intPerforms 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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface de.gurkenlabs.litiengine.ILaunchable
start, terminateMethods 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:
-
-
Method Details
-
perform
Description copied from interface:IGameLoopPerforms a timed action with the specified delay in ms. -
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
-