SFML community forums

Help => System => Topic started by: natchos on April 13, 2012, 02:16:37 pm

Title: Yet another clock thread
Post by: natchos on April 13, 2012, 02:16:37 pm
Hey, I'm using SFML 1.6 on a win 7 machine.

My problem is that my program needs a stopable watch, so I am trying to modify the sf::clock class to include a stopwatch function. The function looks like this.

bool Clock::stopwatch(int ms)
{
        if (GetTime() > stopwatch_start + ms ) {
        stopwatch_start = GetTime();
        return true;}
        else return false;
}
 
GetTime() is just: return static_cast<double>sf::priv::Platform::GetSystemTime();
Anyhow, the problem isn't with the function itself. The problem is the stopwatch_start.
Apparently declaring a extra int/float/double/dword variable in the clock.hpp file causes the Renderwindow function Clear(); to malfunction and give me an access violation reading error on the next line.

The program runs fine(with the exclusion of the stopwatch function) if I remove declaration of the stopwatch_start. (for the reference it is declared as double stopwatch_start; as a private member of clock).

Could anyone post me any tips?
Title: Re: Yet another clock thread
Post by: Laurent on April 13, 2012, 02:24:18 pm
You can't change SFML's source code without recompiling it.

And is it really necessary to modify SFML? Can't you implement a StopWatch class in your own code?

By the way, the Thor library has such a pausable clock.
Title: Re: Yet another clock thread
Post by: natchos on April 13, 2012, 02:40:44 pm
Ya, I suppose I'll have to make a stopwatch in my own code :P.
Also when I went to Thors website it said that I had to have C++ TR1, which I do not(I think).

The reason I wanted to use sfmls class instead was simply convenience.
Title: Re: Yet another clock thread
Post by: Laurent on April 13, 2012, 02:48:05 pm
Quote
Also when I went to Thors website it said that I had to have C++ TR1, which I do not(I think)
Which compiler do you use?
Title: Re: Yet another clock thread
Post by: natchos on April 13, 2012, 02:52:19 pm
VC++2007
Title: Re: Yet another clock thread
Post by: Laurent on April 13, 2012, 02:54:56 pm
This version of VC++ doesn't exist ;D
Title: Re: Yet another clock thread
Post by: natchos on April 13, 2012, 02:55:49 pm
Dang, meant 2008 ^^
Title: Re: Yet another clock thread
Post by: Laurent on April 13, 2012, 02:57:27 pm
VC++ 2008 has TR1, as far as I know.
Title: Re: Yet another clock thread
Post by: natchos on April 13, 2012, 02:58:46 pm
Ah, nice then I will try to recompile my code with thors clock. Much obliged for your help.
Title: Re: Yet another clock thread
Post by: Nexus on April 13, 2012, 05:34:57 pm
Bad news:
Sorry :-\
But thanks for the hint to update my website! ;)
Title: Re: Yet another clock thread
Post by: Hiura on April 13, 2012, 07:01:11 pm
for what it's worth : http://www.sfml-dev.org/wiki/en/sources/pausableclock
Title: Re: Yet another clock thread
Post by: natchos on April 14, 2012, 06:50:43 pm
H: Thanky you!

N: Ah ok, well good to know atleast :)