I've been building an SFML engine and I've been very confused on the FPS, frame independent movement and game loop.
My particular problem is that I have a variable set to 60 for the frame limit but changing this value doesn't seem to change the frame limit. I used the built in SFML window function to set a limit and it seems to work.
Am I doing something wrong with this loop?
while (mWindow.isOpen())
{
time=renderClock.getElapsedTime();
float fFps=1000000/time.asMicroseconds();
std::stringstream s;
s<<fFps<<" fps";
fps.setString(s.str());
renderClock.restart();
const sf::Int64 frameTime = 1000000/FRAMES_PER_SECOND;
sf::Clock c;
sf::Time t=c.getElapsedTime();
sf::Int64 nextFrameTime=t.asMicroseconds()+frameTime;
int loops = 0;
while( t.asMicroseconds() < nextFrameTime && loops < MAX_FRAMESKIP)
{
processEvents();
updateTime=updateClock.restart().asMilliseconds();
update(updateTime);
t=c.getElapsedTime();
loops++;
}
render();
}
Here's a link to my full code: https://github.com/csharpest94/SFML/blob/master/src/Game.cpp
t.asMicroseconds() < nextFrameTime
orloops < MAX_FRAMESKIP
, please ? You probably reach MAX_FRAMESKIP very fast if it is set to 10. – Heckel Apr 1 '15 at 14:21