Skip to content

GameLoop

matthiascy edited this page Feb 6, 2020 · 1 revision

Game loop is defined inside of class GameApp under src/Engine/GameFramework.

while game is running
    currentTime = elapsed time since game begin
    fps = frames / (currentTime - startTime)
    frameTime = currentTime - lastTime
    lastTime = currentTime

    inputSystem.preUpdate(frameTime)
    renderSystem.preUpdate(frameTime)
    behaviorSystem.preUpdate(frameTime)
    physicsSystem.preUpdate(frameTime)
    animationSystem.preUpdate(frameTime)

    inputSystem.update(frameTime)
    behaviorSystem.update(frameTime)
    physicsSystem.update(frameTime)
    animationSystem.update(frameTime)
    
    while (frameTime > 0.0) {
        float deltaTime = min(frameTime, fixedDelta)
        inputSystem->fixedUpdate(deltaTime);
        physicsSystem->fixedUpdate(deltaTime);
        behaviorSystem->fixedUpdate(deltaTime);
        frameTime -= deltaTime
    }

    renderSystem->update(frameTime)

    renderSystem->postUpdate(frameTime)
    inputSystem->postUpdate(frameTime)
    physicsSystem->postUpdate(frameTime)
    behaviorSystem->postUpdate(frameTime)
    animationSystem->postUpdate(frameTime)    
    
    frames++
    
    window repaint
    Qt process events
end
Clone this wiki locally