Class GameLoop

java.lang.Object
technology.sola.engine.core.GameLoop
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
FixedUpdateGameLoop

@NullMarked public abstract class GameLoop extends Object implements Runnable
GameLoop handles running a sequence of update and render commands at a target rate.
  • Field Details

    • eventHub

      protected final EventHub eventHub
      The EventHub instance.
    • fpsTracker

      protected final GameLoop.FpsTracker fpsTracker
      The GameLoop.FpsTracker instance.
    • updateMethod

      protected final Consumer<Float> updateMethod
      Method to call each update. The delta time is passed into the Consumer.
    • renderMethod

      protected final Runnable renderMethod
      Method to call each render frame.
    • deltaTime

      protected final float deltaTime
      The time since the last update.
    • previousLoopStartNanos

      protected long previousLoopStartNanos
      The previous time for when the previous loop started in nanoseconds.
    • updateCatchUpAccumulator

      protected float updateCatchUpAccumulator
      Holds accumulated lost time when the fixed update loop cannot keep up.
  • Constructor Details

    • GameLoop

      protected GameLoop(EventHub eventHub, Consumer<Float> updateMethod, Runnable renderMethod, int targetUpdatesPerSecond)
      Creates a game loop instance with desired update and render logic at target updates per second.
      Parameters:
      eventHub - the EventHub instance
      updateMethod - the update method that is called each frame
      renderMethod - the render method that is called each frame
      targetUpdatesPerSecond - the target updates per second for the game loop
    • GameLoop

      protected GameLoop(EventHub eventHub, Consumer<Float> updateMethod, Runnable renderMethod, int targetUpdatesPerSecond, boolean logFps)
      Creates a game loop instance with desired update and render logic at target updates per second.
      Parameters:
      eventHub - the EventHub instance
      updateMethod - the update method that is called each frame
      renderMethod - the render method that is called each frame
      targetUpdatesPerSecond - the target updates per second for the game loop
      logFps - whether the fps should be logged each second or not
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • startLoop

      protected abstract void startLoop()
      Called to start the main game loop.
    • isRunning

      public boolean isRunning()
      Returns:
      true if the game loop is currently running
    • isPaused

      public boolean isPaused()
      Returns:
      true if the game loop is paused
    • stop

      public void stop()
      Stops the game loop.