Hi
Many users complained after I switched to milliseconds for time
http://www.sfml-dev.org/forum/viewtopic.php?t=4864... this thread clearly shows that people need different resolutions and different types for representing time values.
I could of course provide the most precise (Uint64 nanoseconds) but that would not be
simple -- user code would be pretty ugly.
So here is a proposal for a new time API, that is a little more verbose than before but should make everyone happy.
class Time
{
public:
Time();
float ToSeconds() const;
Int32 ToMilliseconds() const;
Int64 ToMicroseconds() const;
private:
Int64 myMicroseconds;
};
Time Seconds(float amount);
Time Milliseconds(Int32 amount);
Time Microseconds(Int64 amount);
class Clock
{
public:
Time GetElapsedTime() const;
...
}
void Sleep(Time duration);
// same in all functions that require/return a time value
User code:
sf::Clock clock;
sf::Time elapsed = clock.GetElapsedTime();
game.Update(elapsed.ToSeconds());
sf::Sleep(sf::Milliseconds(100));
sf::Time would be a time span, not a time point, so negative values would be allowed (hence the signed integers). It would have comparison and mathematical operators.
It could also support implicit conversions to/from std::chrono classes in the future.