Hey all I wanted to share an issue I have discovered in SFML 2 regarding sf::Clock timing. My goal is to be able to measure how much time has elapsed since the last time the main game loop was run, and accumulate that amount toward a main game timer variable.
Here is Method 1, taking advantage of clock.Restart():
sf::Clock clock;
int gameTime = 0;
while (true) {
int elapsed = clock.Restart().AsMilliseconds();
gameTime += elapsed;
// do stuff...
}
Here is Method 2, which uses an extra variable to keep track of the previous loop time:
sf::Clock clock;
int gameTime = 0;
int prevTime = 0;
while (true) {
int time = clock.GetElapsedTime().AsMilliseconds();
int elapsed = time - prevTime;
prevTime = time;
gameTime += elapsed;
// do stuff...
}
It is my belief that Method 1 is just an SFML shortcut for Method 2 and so these should result in the same timings. However, I have found that's not the case. Method 1 runs slower than Method 2, and seems to be off by milliseconds for each loop.
Am I understanding the usage improperly, or is this a problem with SFML 2?