Skip to content

Commit

Permalink
fixes #1685 where ofGetElapsedTimef() and ofGetElapsedTimeMicros() wr…
Browse files Browse the repository at this point in the history
…ap after ~71 minutes
  • Loading branch information
kylemcdonald committed Nov 8, 2012
1 parent 6f9c02f commit 4225e3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 12 additions & 8 deletions libs/openFrameworks/utils/ofUtils.cpp
Expand Up @@ -44,16 +44,16 @@
#endif #endif


static bool enableDataPath = true; static bool enableDataPath = true;
static unsigned long startTime = ofGetSystemTime(); // better at the first frame ?? (currently, there is some delay from static init, to running. static unsigned long long startTime = ofGetSystemTime(); // better at the first frame ?? (currently, there is some delay from static init, to running.
static unsigned long startTimeMicros = ofGetSystemTimeMicros(); static unsigned long long startTimeMicros = ofGetSystemTimeMicros();


//-------------------------------------- //--------------------------------------
unsigned long ofGetElapsedTimeMillis(){ unsigned long long ofGetElapsedTimeMillis(){
return ofGetSystemTime() - startTime; return ofGetSystemTime() - startTime;
} }


//-------------------------------------- //--------------------------------------
unsigned long ofGetElapsedTimeMicros(){ unsigned long long ofGetElapsedTimeMicros(){
return ofGetSystemTimeMicros() - startTimeMicros; return ofGetSystemTimeMicros() - startTimeMicros;
} }


Expand All @@ -75,11 +75,13 @@ void ofResetElapsedTimeCounter(){
* when subtracting an initial start time, unless the total time exceeds * when subtracting an initial start time, unless the total time exceeds
* 32-bit, where the GLUT API return value is also overflowed. * 32-bit, where the GLUT API return value is also overflowed.
*/ */
unsigned long ofGetSystemTime( ) { unsigned long long ofGetSystemTime( ) {
#ifndef TARGET_WIN32 #ifndef TARGET_WIN32
struct timeval now; struct timeval now;
gettimeofday( &now, NULL ); gettimeofday( &now, NULL );
return now.tv_usec/1000 + now.tv_sec*1000; return
(unsigned long long) now.tv_usec/1000 +
(unsigned long long) now.tv_sec*1000;
#else #else
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
return GetTickCount(); return GetTickCount();
Expand All @@ -89,11 +91,13 @@ unsigned long ofGetSystemTime( ) {
#endif #endif
} }


unsigned long ofGetSystemTimeMicros( ) { unsigned long long ofGetSystemTimeMicros( ) {
#ifndef TARGET_WIN32 #ifndef TARGET_WIN32
struct timeval now; struct timeval now;
gettimeofday( &now, NULL ); gettimeofday( &now, NULL );
return now.tv_usec + now.tv_sec*1000000; return
(unsigned long long) now.tv_usec +
(unsigned long long) now.tv_sec*1000000;
#else #else
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
return GetTickCount()*1000; return GetTickCount()*1000;
Expand Down
8 changes: 4 additions & 4 deletions libs/openFrameworks/utils/ofUtils.h
Expand Up @@ -14,8 +14,8 @@ int ofNextPow2(int input);


void ofResetElapsedTimeCounter(); // this happens on the first frame void ofResetElapsedTimeCounter(); // this happens on the first frame
float ofGetElapsedTimef(); float ofGetElapsedTimef();
unsigned long ofGetElapsedTimeMillis(); unsigned long long ofGetElapsedTimeMillis();
unsigned long ofGetElapsedTimeMicros(); unsigned long long ofGetElapsedTimeMicros();
int ofGetFrameNum(); int ofGetFrameNum();


int ofGetSeconds(); int ofGetSeconds();
Expand All @@ -25,8 +25,8 @@ int ofGetHours();
//number of seconds since 1970 //number of seconds since 1970
unsigned int ofGetUnixTime(); unsigned int ofGetUnixTime();


unsigned long ofGetSystemTime( ); // system time in milliseconds; unsigned long long ofGetSystemTime( ); // system time in milliseconds;
unsigned long ofGetSystemTimeMicros( ); // system time in microseconds; unsigned long long ofGetSystemTimeMicros( ); // system time in microseconds;


//returns //returns
string ofGetTimestampString(); string ofGetTimestampString();
Expand Down

0 comments on commit 4225e3e

Please sign in to comment.