Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Time & sf::Clock vs C++11 chrono  (Read 14862 times)

0 Members and 1 Guest are viewing this topic.

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: sf::Time & sf::Clock vs C++11 chrono
« Reply #15 on: March 13, 2017, 03:31:07 pm »
If my input is of any use:

We all use std::chrono for our internal timing, but it's not far off from sf::Clock.
Sort of like:

CurrFrameStart = std::chrono::high_resolution_clock::now();
TickDelta = std::chrono::duration<double, std::milli>(CurrFrameStart - LastFrameStart).count();

I'd argue that SFML's timing libraries are easier to use, and certainly less verbose, but I see no reason SFML couldn't wrap the C++11 implementation.  It would allow, like Laurent said, conversion between representations, and you'd have access to the system's highest resolution clock if needed.
It would also strip off some more platform-dependent code (and remove that oh-so-beautiful "isWindowsXpOrOlder" check), at least for compilers that support the C++11 standard chrono addition (though I've yet to encounter one that doesn't).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Time & sf::Clock vs C++11 chrono
« Reply #16 on: March 13, 2017, 03:34:24 pm »
Of course, the implied goal is to remove all that ugly OS-specific stuff when a standard implementation exists. We don't want to re-invent std::chrono from scratch.
Laurent Gomila - SFML developer

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: sf::Time & sf::Clock vs C++11 chrono
« Reply #17 on: March 14, 2017, 07:57:08 pm »
Well, if there still will be sf::Time in SFML3 it would be quite important to provide method like asStandardDuration() (in addition to asSeconds() etc.) so it wouldn't be a problem to get it work with stuff like std::this_thread::sleep_for(). I fear that making new sf::Time compatible with std::chrono can cause code to be huge and, as far as I know, we don't want it to happen. At least I don't.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Time & sf::Clock vs C++11 chrono
« Reply #18 on: March 14, 2017, 08:00:26 pm »
Quote
Well, if there still will be sf::Time in SFML3 it would be quite important to provide method like asStandardDuration() (in addition to asSeconds() etc.) so it wouldn't be a problem to get it work with stuff like std::this_thread::sleep_for()
It was already said at least twice ;)
Laurent Gomila - SFML developer

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: sf::Time & sf::Clock vs C++11 chrono
« Reply #19 on: March 14, 2017, 08:04:56 pm »
Quote
Well, if there still will be sf::Time in SFML3 it would be quite important to provide method like asStandardDuration() (in addition to asSeconds() etc.) so it wouldn't be a problem to get it work with stuff like std::this_thread::sleep_for()
It was already said at least twice ;)
I also read trough it twice and still didn't notice that. ;-; Well, that's my opinion, at least you know what folks think.

aggsol

  • Newbie
  • *
  • Posts: 24
  • C++
    • View Profile
    • My Github Account
Re: sf::Time & sf::Clock vs C++11 chrono
« Reply #20 on: March 23, 2018, 04:48:45 pm »
I vote for complete removal including sf::Time. As the example from JayhawkZombie shows there is so little gained from keeping sf::Time. It is IMO not worth the overhead. The additional verbosity and relying on the standard will lower the entry barrier of SFML und will introduce beginners  to more std functions.