X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Ftiming%2Ftimestamp.hxx;h=3a31ba58df9f89d7317999c3e6e32df500aa5450;hb=5bab565cfe4c30d6cf08ecaba50af74d5e4f0c98;hp=be74b53db0bb3331bd99fe4964962b225669fceb;hpb=baf25ca7a78bb282569da3404dd5efddd0a7613c;p=simgear.git diff --git a/simgear/timing/timestamp.hxx b/simgear/timing/timestamp.hxx index be74b53d..3a31ba58 100644 --- a/simgear/timing/timestamp.hxx +++ b/simgear/timing/timestamp.hxx @@ -1,5 +1,8 @@ -// timestamp.hxx -- class for managing a timestamp (seconds & milliseconds.) -// +/** + * \file timestamp.hxx + * Provides a class for managing a timestamp (seconds & milliseconds.) + */ + // Written by Curtis Olson, started December 1998. // // Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org @@ -30,52 +33,24 @@ #endif -#ifdef HAVE_CONFIG_H -# include -#endif - -#ifdef HAVE_WINDOWS_H -# include -#endif - #include -#ifdef SG_HAVE_STD_INCLUDES -# include -#else -# include -#endif - -#ifdef HAVE_SYS_TIMEB_H -# include // for ftime() and struct timeb -#endif -#ifdef HAVE_UNISTD_H -# include // for gettimeofday() -#endif -#ifdef HAVE_SYS_TIME_H -# include // for get/setitimer, gettimeofday, struct timeval -#endif - -// -dw- want to use metrowerks time.h -#ifdef macintosh -# include -# include -#endif - -#ifdef WIN32 -# include -# if defined( __CYGWIN__ ) || defined( __CYGWIN32__ ) -# define NEAR /* */ -# define FAR /* */ -# endif -# include -#endif // MSVC++ 6.0 kuldge - Need forward declaration of friends. class SGTimeStamp; SGTimeStamp operator + (const SGTimeStamp& t, const long& m); long operator - (const SGTimeStamp& a, const SGTimeStamp& b); +/** + * The SGTimeStamp class allows you to mark and compare time stamps + * with microsecond accuracy (if your system has support for this + * 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 + * motion across varying frame rates. + */ + class SGTimeStamp { private: @@ -85,20 +60,46 @@ private: public: + /** Default constructor */ SGTimeStamp(); + + /** + * This creates an instance of the SGTimeStamp object. When + * calling the constructor you may provide initial seconds an + * microseconds values. + * @param s initial seconds value + * @param m initial microseconds value + */ SGTimeStamp( const long s, const long m ); ~SGTimeStamp(); - // Set time to current time + /** Update stored time to current time (seconds and microseconds) */ void stamp(); + /** Compare two time stamps for equality */ SGTimeStamp& operator = ( const SGTimeStamp& t ); + /** + * Increment the saved time by the specified number of microseconds + * @param t time stamp + * @param m microseconds increment + * @return new time stamp + */ friend SGTimeStamp operator + (const SGTimeStamp& t, const long& m); + + /** + * Subtract two time stamps returning the difference in microseconds. + * @param a timestamp 1 + * @param b timestame 2 + * @return difference in microseconds + */ friend long operator - (const SGTimeStamp& a, const SGTimeStamp& b); + /** @return the saved seconds of this time stamp */ inline long get_seconds() const { return seconds; } - // inline long get_usec() const { return usec; } + + /** @return the saved microseconds of this time stamp */ + inline long get_usec() const { return usec; } }; inline SGTimeStamp::SGTimeStamp() { @@ -119,61 +120,6 @@ inline SGTimeStamp& SGTimeStamp::operator = (const SGTimeStamp& t) return *this; } -inline void SGTimeStamp::stamp() { -#if defined( WIN32 ) - unsigned int t; - t = timeGetTime(); - seconds = 0; - usec = t * 1000; -#elif defined( HAVE_GETTIMEOFDAY ) - struct timeval current; - struct timezone tz; - // sg_timestamp currtime; - gettimeofday(¤t, &tz); - seconds = current.tv_sec; - usec = current.tv_usec; -#elif defined( HAVE_GETLOCALTIME ) - SYSTEMTIME current; - GetLocalTime(¤t); - seconds = current.wSecond; - usec = current.wMilliseconds * 1000; -#elif defined( HAVE_FTIME ) - struct timeb current; - ftime(¤t); - seconds = current.time; - usec = current.millitm * 1000; -// -dw- uses time manager -#elif defined( macintosh ) - UnsignedWide ms; - Microseconds(&ms); - - seconds = ms.lo / 1000000; - usec = ms.lo - ( seconds * 1000000 ); -#else -# error Port me -#endif -} - -// increment the time stamp by the number of microseconds (usec) -inline SGTimeStamp operator + (const SGTimeStamp& t, const long& m) { -#ifdef WIN32 - return SGTimeStamp( 0, t.usec + m ); -#else - return SGTimeStamp( t.seconds + ( t.usec + m ) / 1000000, - ( t.usec + m ) % 1000000 ); -#endif -} - -// difference between time stamps in microseconds (usec) -inline long operator - (const SGTimeStamp& a, const SGTimeStamp& b) -{ -#if defined( WIN32 ) - return a.usec - b.usec; -#else - return 1000000 * (a.seconds - b.seconds) + (a.usec - b.usec); -#endif -} - #endif // _TIMESTAMP_HXX