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

Author Topic: sf::Clock Improvement  (Read 27269 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Clock Improvement
« on: May 03, 2008, 01:03:08 am »
Hi
What do you think about some more features to the sf::Clock class?
For example a function which could pause the timer would be useful. Setting the time to a given float parameter might be of advantage, too.

I think adding a Pause() and SetTime(float Time) function shouldn't be a big problem - or does it upset the whole system because you can't just take the difference between starting and current time anymore?.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

SirJulio

  • Full Member
  • ***
  • Posts: 241
    • View Profile
sf::Clock Improvement
« Reply #1 on: May 03, 2008, 02:06:27 am »
Hi Nexus,

as you said, sf::Clock is a ... Clock. =p

You don't have to pause a clock, just ask it elpased time. (maybe a stopwatch, and i'm sure, you could easily do that with an encapsulated Clock).

So, IMO, Clock doesn't need this kind of feat. =)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Clock Improvement
« Reply #2 on: May 03, 2008, 03:44:44 am »
Other users already wrote such class, you may find some code on the forum (maybe the french one).
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Clock Improvement
« Reply #3 on: May 03, 2008, 11:34:29 pm »
Ok, the problem is, to write an own clock/stopwatch class I can't use the existing sf::Clock since the member myStartTime is private. I should always use GetElapsedTime()... Isn't that a little bit waste of performance?

But in the french forum, I found some propositions...
Thank you!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Clock Improvement
« Reply #4 on: May 04, 2008, 08:08:48 am »
Quote
Ok, the problem is, to write an own clock/stopwatch class I can't use the existing sf::Clock since the member myStartTime is private. I should always use GetElapsedTime()... Isn't that a little bit waste of performance?

If you think calling a function will waste performances... then never look inside SFML source code, there are tons of them :D
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Clock Improvement
« Reply #5 on: May 04, 2008, 01:31:33 pm »
Hehe, ok... But SFML is still quite fast ;)
And besides, algorithms like the Clock functions should not be very time-critical... I think, for example graphic rendering requires a lot more performance, doesn't it?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Clock Improvement
« Reply #6 on: May 04, 2008, 02:53:28 pm »
Quote
And besides, algorithms like the Clock functions should not be very time-critical... I think, for example graphic rendering requires a lot more performance, doesn't it?

Absolutely ;)
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
sf::Clock Improvement
« Reply #7 on: May 04, 2008, 08:25:17 pm »
Always use the getters and setters provided... if you find they are a performance drain then we should bug Laurent to change them to inline functions instead :) Data members should stay private so that we can't mess around with SFML's private data and possibly break the clock :)

MadMartin

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
sf::Clock Improvement
« Reply #8 on: July 31, 2008, 12:10:29 pm »
I'll just pick this thread up:

What's about adding a (static) method to sf::Clock which provides the current system time? Would that make sense? Are there other developers who would appreciate it?

There would be many possibilities for use, e.g. in logging, displaying current time in GUIs, add to savegames for easy identify, e.t.c...

So, Laurent, any comments? :wink:

greetings
Martin

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Clock Improvement
« Reply #9 on: July 31, 2008, 02:15:46 pm »
For most of your examples, using the application time (a global sf::Clock) is enough. System time usually doesn't mean anything, I guess what you request is the current date and time. There are plenty of good and complete libraries which provide that, like boost.date_time or any GUI library (Qt, wxWidgets, MFC, ...).
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Clock Improvement
« Reply #10 on: August 01, 2008, 02:09:59 pm »
The standard header <ctime> provides some useful time functions, too.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

MadMartin

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
sf::Clock Improvement
« Reply #11 on: August 01, 2008, 03:51:00 pm »
Ah, yes, Boost. Should've thought about that :!:

@Nexus:
No, no ctime :D
I don't like it to mix C and C++, I'm trying to stick to as clean as possible C++  :wink:

BTW: Bist du der Nexus, der im Forum von c-plusplus.de unterwegs ist?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
sf::Clock Improvement
« Reply #12 on: August 01, 2008, 06:00:44 pm »
Quote from: "MadMartin"
BTW: Bist du der Nexus, der im Forum von c-plusplus.de unterwegs ist?

Genau der ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
sf::Clock Improvement
« Reply #13 on: August 02, 2008, 06:23:14 pm »
Quote from: "workmad3"
Always use the getters and setters provided... if you find they are a performance drain then we should bug Laurent to change them to inline functions instead :) Data members should stay private so that we can't mess around with SFML's private data and possibly break the clock :)


the compiler is usualy smart enough to make simple getters and setters inline anyway so ther should be no worries :)
//Zzzarka

 

anything