java.lang.Object
technology.sola.engine.core.GameLoop
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
FixedUpdateGameLoop
GameLoop handles running a sequence of update and render commands at a target rate.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
FpsTracker is a simple class for tracking update and frame ticks. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final float
The time since the last update.protected final EventHub
TheEventHub
instance.protected final GameLoop.FpsTracker
TheGameLoop.FpsTracker
instance.protected long
The previous time for when the previous loop started in nanoseconds.protected final Runnable
Method to call each render frame.protected float
Holds accumulated lost time when the fixed update loop cannot keep up.Method to call each update. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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.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. -
Method Summary
-
Field Details
-
eventHub
TheEventHub
instance. -
fpsTracker
TheGameLoop.FpsTracker
instance. -
updateMethod
Method to call each update. The delta time is passed into theConsumer
. -
renderMethod
Method to call each render frame. -
deltaTime
protected final float deltaTimeThe time since the last update. -
previousLoopStartNanos
protected long previousLoopStartNanosThe previous time for when the previous loop started in nanoseconds. -
updateCatchUpAccumulator
protected float updateCatchUpAccumulatorHolds 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
- theEventHub
instanceupdateMethod
- the update method that is called each framerenderMethod
- the render method that is called each frametargetUpdatesPerSecond
- 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
- theEventHub
instanceupdateMethod
- the update method that is called each framerenderMethod
- the render method that is called each frametargetUpdatesPerSecond
- the target updates per second for the game looplogFps
- whether the fps should be logged each second or not
-
-
Method Details
-
run
public void run() -
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.
-