X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Ftiming%2Ftimestamp.hxx;h=ac9ca1423fe81b56041b4a49ce2e146b5d6cb662;hb=1f585d67199896749f5f532657d17afe586f6615;hp=7b417a84de27a7b389141f8c93a6c5c9296210bc;hpb=f1f0fa0aa95c2f1562fa9c09365baf8b2b55bfc7;p=simgear.git diff --git a/simgear/timing/timestamp.hxx b/simgear/timing/timestamp.hxx index 7b417a84..ac9ca142 100644 --- a/simgear/timing/timestamp.hxx +++ b/simgear/timing/timestamp.hxx @@ -44,7 +44,7 @@ * level of accuracy). * * The SGTimeStamp is useful for tracking the elapsed time of various - * events in your program. You can also use it to keep constistant + * events in your program. You can also use it to keep consistent * motion across varying frame rates. * * Note SGTimestamp does not deliver the time of day. The content of this @@ -59,8 +59,8 @@ public: /** Default constructor, initialize time to zero. */ SGTimeStamp() : - _sec(0), - _nsec(0) + _nsec(0), + _sec(0) { } /** Hmm, might reenable them at some time, but since it is not clear @@ -184,6 +184,8 @@ public: { SGTimeStamp ts; ts.setTime(sec); return ts; } static SGTimeStamp fromSec(const double& sec) { SGTimeStamp ts; ts.setTime(sec); return ts; } + static SGTimeStamp fromMSec(nsec_type msec) + { return SGTimeStamp(0, 1000*1000*msec); } static SGTimeStamp fromUSec(nsec_type usec) { return SGTimeStamp(0, 1000*usec); } static SGTimeStamp fromNSec(nsec_type nsec) @@ -195,6 +197,26 @@ public: static SGTimeStamp now() { SGTimeStamp ts; ts.stamp(); return ts; } + /** + * Sleep until the time of abstime is passed. + */ + static bool sleepUntil(const SGTimeStamp& abstime); + + /** + * Sleep for reltime. + */ + static bool sleepFor(const SGTimeStamp& reltime); + + /** + * Alias for the most common use case with milliseconds. + */ + static bool sleepForMSec(unsigned msec) + { return sleepFor(fromMSec(msec)); } + + /** + * elapsed time since the stamp was taken, in msec + */ + int elapsedMSec() const; private: SGTimeStamp(sec_type sec, nsec_type nsec) { setTime(sec, nsec); }