Whats the best way of telling when 10 seconds has gone by,for example?
rest( 10 * 1000 );
Do you want to do something while 10 seconds is going by or just wait for 10 seconds? If the former you can set up a timer with
increment a variable every tick and then when the variable * ticks reaches 10 seconds you know 10 seconds will have past.
Timer::time_t t = timer.secs(); ... if(timer.secs() - t > 9) .. 10 seconds have elapsed ..
Even easier:
stopwatch sw; sw.start(10000); .. if(sw.check()) .. 10 seconds have elapsed ..
If you want either of these classes I can give them to you.
http://www.boost.org/libs/timer/timer.htm
It's cross platform. I can't recall if this particular boost lib will be in the next C++ standard but its probably a good shot. It's resolution depends on OS's but windows and *nix are both millisecond tickers IIRC.
from the site:
| 1 | Synopsis |
| 2 | |
| 3 | #include <boost/timer.hpp> |
| 4 | namespace boost { |
| 5 | class timer { |
| 6 | public: |
| 7 | timer(); // postcondition: elapsed()==0 |
| 8 | // compiler generated copy constructor, copy assignment, and dtor apply |
| 9 | void restart(); // post: elapsed()==0 |
| 10 | double elapsed() const; // return elapsed time in seconds |
| 11 | |
| 12 | double elapsed_max() const; // return estimated maximum value for elapsed() |
| 13 | // Portability warning: elapsed_max() may return too high a value on systems |
| 14 | // where std::clock_t overflows or resets at surprising values. |
| 15 | |
| 16 | double elapsed_min() const; // return minimum value for elapsed() |
| 17 | }; // timer |
| 18 | } // namespace boost |