SFML community forums

General => Feature requests => Topic started by: Nexus on May 03, 2008, 01:03:08 am

Title: sf::Clock Improvement
Post by: Nexus 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?.
Title: sf::Clock Improvement
Post by: SirJulio 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. =)
Title: sf::Clock Improvement
Post by: Laurent 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).
Title: sf::Clock Improvement
Post by: Nexus 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!
Title: sf::Clock Improvement
Post by: Laurent 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
Title: sf::Clock Improvement
Post by: Nexus 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?
Title: sf::Clock Improvement
Post by: Laurent 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 ;)
Title: sf::Clock Improvement
Post by: workmad3 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 :)
Title: sf::Clock Improvement
Post by: MadMartin 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
Title: sf::Clock Improvement
Post by: Laurent 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, ...).
Title: sf::Clock Improvement
Post by: Nexus on August 01, 2008, 02:09:59 pm
The standard header <ctime> provides some useful time functions, too.
Title: sf::Clock Improvement
Post by: MadMartin 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?
Title: sf::Clock Improvement
Post by: Nexus 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 ;)
Title: sf::Clock Improvement
Post by: zarka 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 :)