From 93dbfa04b748e88da523afcff1a217abe8ddf525 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 26 Dec 2006 17:37:06 +0000 Subject: [PATCH] Aded new convinience methods to osg::Timer - s/getStartTick and time_s(), time_m() etc to help get time reletive the new start tick. --- include/osg/Timer | 34 +++++++++++++++++++++++++++++++--- src/osg/Timer.cpp | 6 +++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/osg/Timer b/include/osg/Timer index 74f75aa13..5255d710a 100644 --- a/include/osg/Timer +++ b/include/osg/Timer @@ -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; }; diff --git a/src/osg/Timer.cpp b/src/osg/Timer.cpp index fd5d28ca3..3a5c450c0 100644 --- a/src/osg/Timer.cpp +++ b/src/osg/Timer.cpp @@ -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, "<