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.
See Also:
IUpdateable.update(), Game.loop(), RenderComponent.render()
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Thread

    java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
  • Field Summary

    Fields 
    Modifier and TypeFieldDescription
    static intTICK_DELTATIME_LAG
    The tick UpdateLoop.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 TypeMethodDescription
    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, the GameLoop performs registered action at the required time and tracks some detailed metrics.
    voidremoveAction​(int id)
    Removes the TimedAction with the specified it.
    voidsetTimeScale​(float timeScale)
    Sets the game loop's time scale.

    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.ILaunchable

    start, terminate

    Methods inherited from interface de.gurkenlabs.litiengine.ILoop

    attach, detach, getDeltaTime, getLock, getProcessTime, getTickRate, getTicks, getUpdatableCount, setTickRate
  • Field Details

  • 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 interface IGameLoop
      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 interface IGameLoop
      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 interface IGameLoop
      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 interface IGameLoop
      Parameters:
      index - The id of the TimedAction.
      ticks - The tick at which to perform the action instead.
    • removeAction

      public void removeAction​(int id)
      Description copied from interface: IGameLoop
      Removes the TimedAction with the specified it.
      Specified by:
      removeAction in interface IGameLoop
      Parameters:
      id - The id of the TimedAction.
    • process

      protected void process()
      In addition to the normal base implementation, the GameLoop performs registered action at the required time and tracks some detailed metrics.
      Overrides:
      process in class UpdateLoop
    • getExpectedDelta

      protected long getExpectedDelta()
      Overrides:
      getExpectedDelta in class UpdateLoop