So ive read both http://gameprogrammingpatterns.com/game-loop.html and http://gafferongames.com/game-physics/fix-your-timestep/ and I kind of understand how I'm supposed to do it, but some parts are still blurry and I would like some guidance.
By the way, I have programmed my game from scratch and i do not want to change to some framework or anything that has an built in main loop, i want to do this by myself.
Anyway, this is what I have accomplished code-wise, I will re-produce my solution it in psudocode below.
func createPlayer()
{
oData = Empty Object()
oData.id
oData.name
oData.etc.....
Player = LoadSprite("filename", oData)
// Properties
Player.oSprite.x
Player.oSprite.y
Player.oSprite.scale
Player.oSprite.width
Player.oSprite.height
//Methods (Self-explanatory)
Player.oSprite.width()
Player.oSprite.height()
Player.oSprite.centerX()
Player.oSprite.centerY()
return Player
}
// Startup
oPlayer = createPlayer()
oWorld = 1D array of objects which has identical properties and methods from createPlayer()
// Main game loop
while(game){
//User inputs
_game_userInputs(byref oPlayer)
// "Physics" jumps and world collission is done here.
_game_Physics(byref oWorld, byref oPlayer)
// rendering, draws the world frame with all inputs and physics done beforehand
_game_render(byref boWorld,byref oPlayer)
}
This is how I "understand" what flow the loop should have
t = 0.0
dt = 0.0
currentTime = 0.0
accumulator = 0.0
while(game)
{
newTime = _Timer_QueryPerformanceCounter() // Im feeling like this need something more than just the QueryPeformenceCounter?
frameTime = newTime - currentTime
if (frameTime > 0.25) {
frameTime = 0.25
}
currentTime = newTime
game_input()
//This is causing my game to get stuck here, i belive it has something to do with my type of timer
while accumulator > dt
{
game_physics(t, dt) //how is the deltatime helping me in my physics?
t += dt
accumulator -= dt
}
alpha = accumulator / dt
game_render(alpha) // I dont know what im supopsed to do with this.
}
TLDR, what do i do with the t, dt in my physics? before i render?
dt
is zero. It is the constant, desired update interval; it is never calculated. That leads you into an infinite loop, as the accumulated time is never consumed. \$\endgroup\$