1
General / Re: Should i use this game loop?
« on: May 22, 2014, 04:13:52 am »Quote
Looks like only these two have to be swapped and you should pass TimePerFrame to your updateStatistics function instead of dt, like you did with your update function.
Audio is a strange title btw haha
actually, this source code come from 'SFML Game Development' Book and original code is:
void Application::run()
{
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
while (mWindow.isOpen())
{
sf::Time dt = clock.restart();
timeSinceLastUpdate += dt;
while (timeSinceLastUpdate > TimePerFrame)
{
timeSinceLastUpdate -= TimePerFrame;
processInput();
update(TimePerFrame);
// Check inside this loop, because stack might be empty before update() call
if (mStateStack.isEmpty())
mWindow.close();
}
updateStatistics(dt);
render();
}
}
{
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
while (mWindow.isOpen())
{
sf::Time dt = clock.restart();
timeSinceLastUpdate += dt;
while (timeSinceLastUpdate > TimePerFrame)
{
timeSinceLastUpdate -= TimePerFrame;
processInput();
update(TimePerFrame);
// Check inside this loop, because stack might be empty before update() call
if (mStateStack.isEmpty())
mWindow.close();
}
updateStatistics(dt);
render();
}
}