2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CSTOPWATCH
|
|
|
|
#define _CSTOPWATCH
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-09-13 04:26:54 +00:00
|
|
|
#include "dolphin/os.h"
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
class CStopwatch {
|
|
|
|
public:
|
|
|
|
class CSWData {
|
|
|
|
public:
|
2022-10-09 05:13:17 +00:00
|
|
|
CSWData() : x0_timerFreq(0), x8_timerFreqO1M(0), x10_timerPeriod(0.f) {}
|
2022-09-22 06:03:09 +00:00
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
bool Initialize();
|
2022-07-15 00:48:18 +00:00
|
|
|
void Wait(f32) const;
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
s64 GetTimerFreq() const { return x0_timerFreq; }
|
|
|
|
s64 GetTimerFreqO1M() const { return x8_timerFreqO1M; }
|
|
|
|
f32 GetTimerPeriod() const { return x10_timerPeriod; }
|
2022-04-11 22:42:08 +00:00
|
|
|
s64 GetCPUCycles() const { return OSGetTime(); }
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
s64 x0_timerFreq;
|
|
|
|
s64 x8_timerFreqO1M;
|
|
|
|
f32 x10_timerPeriod;
|
|
|
|
};
|
|
|
|
|
2022-04-11 22:42:08 +00:00
|
|
|
CStopwatch() : x0_startTime(mData.GetCPUCycles()) {}
|
2022-09-22 06:03:09 +00:00
|
|
|
static bool InitGlobalTimer();
|
|
|
|
static CStopwatch& GetGlobalTimerObj();
|
2022-04-10 00:17:06 +00:00
|
|
|
inline void Reset() {
|
|
|
|
if (mData.GetTimerFreq() == 0) {
|
|
|
|
mData.Initialize();
|
|
|
|
}
|
2022-04-11 22:42:08 +00:00
|
|
|
x0_startTime = mData.GetCPUCycles();
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
2022-09-18 06:05:46 +00:00
|
|
|
inline f32 GetElapsedTime() const {
|
|
|
|
return (mData.GetCPUCycles() - x0_startTime) * mData.GetTimerPeriod();
|
|
|
|
}
|
|
|
|
inline s64 GetElapsedMicros() const {
|
|
|
|
return (mData.GetCPUCycles() - x0_startTime) / mData.GetTimerFreqO1M();
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-09-20 04:35:24 +00:00
|
|
|
static void Wait(f32);
|
2022-10-09 05:13:17 +00:00
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
private:
|
|
|
|
static CSWData mData;
|
|
|
|
static CStopwatch mGlobalTimer;
|
|
|
|
|
|
|
|
s64 x0_startTime;
|
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CSTOPWATCH
|