Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and Render loop for constant update time #14

Open
DominicDolan opened this issue Oct 17, 2020 · 0 comments
Open

Update and Render loop for constant update time #14

DominicDolan opened this issue Oct 17, 2020 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@DominicDolan
Copy link
Owner

Info

The code currently has a way of setting custom logic for updating and rendering. This can be done while configuring the game:

Game.configure {
    setDeltaTimeCalculator(DeltaCalculator.basicConstantCalculator(60.0))
}

There are a lot of default ways of doing this algorithm in the DeltaCalculator companion object but none of them are ideal.

A better way of updating the game loop needs to be worked out. Custom algorithms can be made by extending DeltaCalculator like so:

class BasicConstantCalculator(frameRate: Double) : DeltaCalculator {
    override fun Updater.updateAndRender(lastFrame: Double, thisFrame: Double) {
        // Both update and render have to be called inside this function
        val delta = thisFrame - lastFrame
        update(delta)
        render()
    }
}

Motive

There are two stages to the game loop

  • The update stage which should update physics/movement and logic
  • The render stage which draws everything to the screen in their already calculated positions

It is generally recommended to, firstly, have the update and render stages decoupled from one another and, secondly, have the update stage simulate a constant amount of time. Most physics engines require an update that takes a constant value and online multiplayer games will also depend on a constant update time. More information about this and how to partially solve this issue can be seen here.

Task

Create an implementation of DeltaCalculator that updates the game with constant delta and does not cause games to look jittery or unsmooth

@DominicDolan DominicDolan added bug Something isn't working enhancement New feature or request labels Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant