Aded new convinience methods to osg::Timer - s/getStartTick and time_s(), time_m() etc

to help get time reletive the new start tick.
This commit is contained in:
Robert Osfield
2006-12-26 17:37:06 +00:00
parent 92291f29b7
commit 93dbfa04b7
2 changed files with 36 additions and 4 deletions

View File

@@ -24,7 +24,7 @@ namespace osg {
typedef unsigned long long Timer_t;
#endif
/** Time stamper. */
/** Timer class is used for measuring elapsed time or time between two points. */
class OSG_EXPORT Timer {
public:
@@ -32,20 +32,48 @@ class OSG_EXPORT Timer {
Timer();
~Timer() {}
static const Timer* instance();
static Timer* instance();
/** Get the timers tick value.*/
Timer_t tick() const;
/** Set the start.*/
void setStartTick() { _startTick = tick(); }
void setStartTick(Timer_t t) { _startTick = t; }
Timer_t getStartTick() const { return _startTick; }
/** Get elapsed time in seconds.*/
inline double time_s() const { return delta_s(_startTick, tick()); }
/** Get elapsed time in milliseconds.*/
inline double time_m() const { return delta_m(_startTick, tick()); }
/** Get elapsed time in micoseconds.*/
inline double time_u() const { return delta_u(_startTick, tick()); }
/** Get elapsed time in nanoseconds.*/
inline double time_n() const { return delta_n(_startTick, tick()); }
/** Get the time in seconds between timer ticks t1 and t2.*/
inline double delta_s( Timer_t t1, Timer_t t2 ) const { return (double)(t2 - t1)*_secsPerTick; }
/** Get the time in milliseconds between timer ticks t1 and t2.*/
inline double delta_m( Timer_t t1, Timer_t t2 ) const { return delta_s(t1,t2)*1e3; }
/** Get the time in microseconds between timer ticks t1 and t2.*/
inline double delta_u( Timer_t t1, Timer_t t2 ) const { return delta_s(t1,t2)*1e6; }
/** Get the time in nanoseconds between timer ticks t1 and t2.*/
inline double delta_n( Timer_t t1, Timer_t t2 ) const { return delta_s(t1,t2)*1e9; }
/** Get the the numer of ticks per second.*/
inline double getSecondsPerTick() const { return _secsPerTick; }
protected :
double _secsPerTick;
Timer_t _startTick;
double _secsPerTick;
};

View File

@@ -26,7 +26,7 @@ using namespace osg;
// all the rest of the timer methods are implemented within the header.
const Timer* Timer::instance()
Timer* Timer::instance()
{
static Timer s_timer;
return &s_timer;
@@ -51,6 +51,8 @@ const Timer* Timer::instance()
notify(NOTICE)<<"Error: Timer::Timer() unable to use QueryPerformanceFrequency, "<<std::endl;
notify(NOTICE)<<"timing code will be wrong, Windows error code: "<<GetLastError()<<std::endl;
}
setStartTick();
}
Timer_t Timer::tick() const
@@ -75,6 +77,8 @@ const Timer* Timer::instance()
Timer::Timer( void )
{
_secsPerTick = (1.0 / (double) 1000000);
setStartTick();
}
Timer_t Timer::tick() const