I am at the part where I am trying to implement a fixed timestep game loop
I have read articles like:
https://gafferongames.com/post/fix_your_timestep/
https://dewitters.com/dewitters-gameloop/
And I understand the basics as follows:
1. Calculate the current frame's delta time
2. Add the delta time to a “update time” counter
3. While you have enough “update time” left in the counter update your game logic and minus the target timestep / FPS amount
4. Calculate a interpolation value and pass it to the render method
My confusion sets in and everything kind of falls apart with step 4. I understand I should be calculating the interpolation value to more or less “smooth out” the render from Frame A to Frame B. But I don't really understand how it should be done or how it should be applied
For example, if my logic looks like this
//Timestep
double timestepInMS = 1000.0 / 60.0;
//Game loop
void gameloop() {
previousTime = nowTime;
nowTime = Timer.now();
//Return "now time" in milliseconds
dt = nowTime - previousTime;
updateTime += dt;
while (updateTime >= timestepInMS) {
updatePlayer();
updateTime -= timestepInMS;
}
//=== interpolation value ???
//interpolationValue = updateTime / timestepInMS;
render();
}
//Logic update
void updatePlayer() {
if (keyboard.isKeyDown('D') == true)
player.position.x += 5.0;
}
//Render update
void render() {
player.draw() //Put the player's sprite vertices into a GPU buffer
}
From this point, I don't really understand where to use the interpolation value. If I'm just placing vertices of a quad into a vertex buffer in my player.draw() where does the interpolation value get used? Everything dealing with position and other related logic was done in the playerUpdate() method.
Where am I going wrong with all of this?