Revert b3Clock changes and use reset method instead.
This commit is contained in:
@@ -160,7 +160,8 @@ public:
|
||||
m_filterCallback(NULL)
|
||||
{
|
||||
b3Clock clock;
|
||||
srand(clock.getSystemTimeMilliseconds()); // Set random milliseconds based on system time
|
||||
srand(clock.getTimeMilliseconds()); // Set random milliseconds based on system time
|
||||
clock.reset(true); // Reset clock to zero to get new random seed
|
||||
}
|
||||
|
||||
virtual ~NN3DWalkersExample()
|
||||
|
||||
@@ -46,7 +46,6 @@ struct b3ClockData
|
||||
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
LARGE_INTEGER mClockFrequency;
|
||||
DWORD mStartTick;
|
||||
LARGE_INTEGER mStartTime;
|
||||
#else
|
||||
#ifdef __CELLOS_LV2__
|
||||
@@ -88,11 +87,24 @@ b3Clock& b3Clock::operator=(const b3Clock& other)
|
||||
|
||||
|
||||
/// Resets the initial reference time.
|
||||
void b3Clock::reset()
|
||||
void b3Clock::reset(bool zeroReference)
|
||||
{
|
||||
if (zeroReference)
|
||||
{
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
m_data->mStartTime.QuadPart = 0;
|
||||
#else
|
||||
#ifdef __CELLOS_LV2__
|
||||
m_data->mStartTime = 0;
|
||||
#else
|
||||
m_data->mStartTime = (struct timeval){0};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} else
|
||||
{
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
QueryPerformanceCounter(&m_data->mStartTime);
|
||||
m_data->mStartTick = GetTickCount();
|
||||
#else
|
||||
#ifdef __CELLOS_LV2__
|
||||
|
||||
@@ -106,20 +118,23 @@ void b3Clock::reset()
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// the b3Clock was created.
|
||||
unsigned long int b3Clock::getTimeMilliseconds()
|
||||
{
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
LARGE_INTEGER currentTime, elapsedTime;
|
||||
LARGE_INTEGER currentTime;
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
elapsedTime.QuadPart = currentTime.QuadPart -
|
||||
LONGLONG elapsedTime = currentTime.QuadPart -
|
||||
m_data->mStartTime.QuadPart;
|
||||
elapsedTime.QuadPart *= 1000;
|
||||
elapsedTime.QuadPart /= m_data->mClockFrequency.QuadPart;
|
||||
// Compute the number of millisecond ticks elapsed.
|
||||
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
|
||||
m_data->mClockFrequency.QuadPart);
|
||||
|
||||
return (unsigned long long) elapsedTime.QuadPart;
|
||||
|
||||
return msecTicks;
|
||||
#else
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
@@ -141,39 +156,6 @@ unsigned long int b3Clock::getTimeMilliseconds()
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Gets the system time in milliseconds
|
||||
unsigned long int b3Clock::getSystemTimeMilliseconds() {
|
||||
|
||||
#ifdef B3_USE_WINDOWS_TIMERS
|
||||
LARGE_INTEGER currentTime, elapsedTime;
|
||||
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
elapsedTime.QuadPart = currentTime.QuadPart;
|
||||
elapsedTime.QuadPart *= 1000;
|
||||
elapsedTime.QuadPart /= m_data->mClockFrequency.QuadPart;
|
||||
|
||||
return (unsigned long long) elapsedTime.QuadPart;
|
||||
#else
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
uint64_t freq = sys_time_get_timebase_frequency();
|
||||
double dFreq = ((double)freq) / 1000.0;
|
||||
typedef uint64_t ClockSize;
|
||||
ClockSize newTime;
|
||||
SYS_TIMEBASE_GET(newTime);
|
||||
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
|
||||
|
||||
return (unsigned long int)((double(newTime)) / dFreq);
|
||||
#else
|
||||
|
||||
struct timeval currentTime;
|
||||
gettimeofday(¤tTime, 0);
|
||||
return (currentTime.tv_sec) * 1000 +
|
||||
(currentTime.tv_usec) / 1000;
|
||||
#endif //__CELLOS_LV2__
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Returns the time in us since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
unsigned long long int b3Clock::getTimeMicroseconds()
|
||||
|
||||
@@ -13,16 +13,13 @@ public:
|
||||
|
||||
~b3Clock();
|
||||
|
||||
/// Resets the initial reference time.
|
||||
void reset();
|
||||
/// Resets the initial reference time. If zeroReference is true, will set reference to absolute 0.
|
||||
void reset(bool zeroReference=false);
|
||||
|
||||
/// Returns the time in ms since the last call to reset or since
|
||||
/// the b3Clock was created.
|
||||
unsigned long int getTimeMilliseconds();
|
||||
|
||||
/// Gets the system time in milliseconds
|
||||
unsigned long int getSystemTimeMilliseconds();
|
||||
|
||||
/// Returns the time in us since the last call to reset or since
|
||||
/// the Clock was created.
|
||||
unsigned long long int getTimeMicroseconds();
|
||||
|
||||
Reference in New Issue
Block a user