prime/include/Kyoto/Basics/CStopwatch.hpp

46 lines
1.1 KiB
C++
Raw Normal View History

#ifndef _CSTOPWATCH_HPP
#define _CSTOPWATCH_HPP
#include "types.h"
#include "Dolphin/os.h"
class CStopwatch {
public:
class CSWData {
public:
bool Initialize();
2022-07-15 00:48:18 +00:00
void Wait(f32) const;
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(); }
private:
s64 x0_timerFreq;
s64 x8_timerFreqO1M;
f32 x10_timerPeriod;
};
2022-04-11 22:42:08 +00:00
CStopwatch() : x0_startTime(mData.GetCPUCycles()) {}
// static inline void InitGlobalTimer() {}
// static inline CStopwatch& GetGlobalTimerObj() { return mGlobalTimer; }
inline void Reset() {
if (mData.GetTimerFreq() == 0) {
mData.Initialize();
}
2022-04-11 22:42:08 +00:00
x0_startTime = mData.GetCPUCycles();
}
2022-07-15 00:48:18 +00:00
inline f32 GetElapsedTime() const { return (mData.GetCPUCycles() - x0_startTime) * mData.GetTimerPeriod(); }
2022-04-11 22:42:08 +00:00
inline s64 GetElapsedMicros() const { return (mData.GetCPUCycles() - x0_startTime) / mData.GetTimerFreqO1M(); }
private:
static CSWData mData;
static CStopwatch mGlobalTimer;
s64 x0_startTime;
};
#endif