1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Template-ize hsTimer return values.

This commit is contained in:
Darryl Pogue
2014-05-11 18:27:59 -07:00
parent 5b0652cb7e
commit a3ae4201a2
11 changed files with 91 additions and 94 deletions

View File

@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
class plTimerShare
{
private:
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::time_point<Clock> TimePoint;
typedef Clock::duration Duration;
@ -72,8 +73,39 @@ protected:
bool fClamping;
double GetSeconds() const;
double GetMilliSeconds() const;
template<typename T = double>
T GetSeconds() const
{
typedef std::chrono::duration<T> duration_type;
Duration d = GetRawTicks();
return std::chrono::duration_cast<duration_type>(d).count();
}
template<typename T = double>
T GetSeconds(uint64_t ticks) const
{
typedef std::chrono::duration<T> duration_type;
Duration d(ticks);
return std::chrono::duration_cast<duration_type>(d).count();
}
template<typename T = double>
T GetMilliSeconds() const
{
typedef std::chrono::duration<T, std::milli> duration_type;
Duration d = GetRawTicks();
return std::chrono::duration_cast<duration_type>(d).count();
}
template<typename T = double>
T GetMilliSeconds(uint64_t ticks) const
{
typedef std::chrono::duration<T, std::milli> duration_type;
Duration d(ticks);
return std::chrono::duration_cast<duration_type>(d).count();
}
uint64_t GetTicks() const;
float GetDelSysSeconds() const { return fDelSysSeconds; }
double GetSysSeconds() const { return fSysSeconds; }
@ -112,8 +144,19 @@ protected:
public:
static double GetSeconds() { return fTimer->GetSeconds(); }
static double GetMilliSeconds() { return fTimer->GetMilliSeconds(); }
template<typename T = double>
static T GetSeconds() { return fTimer->GetSeconds<T>(); }
template<typename T = double>
static T GetSeconds(uint64_t ticks) { return fTimer->GetSeconds<T>(ticks); }
template<typename T = double>
static T GetMilliSeconds() { return fTimer->GetMilliSeconds<T>(); }
template<typename T = double>
static T GetMilliSeconds(uint64_t ticks) { return fTimer->GetMilliSeconds<T>(ticks); }
static uint64_t GetTicks() { return fTimer->GetTicks(); }
static float GetDelSysSeconds() { return fTimer->GetDelSysSeconds(); }
static double GetSysSeconds() { return fTimer->GetSysSeconds(); }
@ -133,18 +176,6 @@ public:
static float GetTimeClamp() { return fTimer->GetTimeClamp(); }
static bool IsClamping() { return fTimer->IsClamping(); }
///////////////////////////
// Precision timer routines - these are stateless and implemented as statics.
///////////////////////////
static uint32_t GetPrecTickCount();
static double GetPrecTicksPerSec();
static double PrecTicksToSecs(uint32_t ticks);
// If you need to time something longer than 20 seconds, use this instead of
// the precision timer. It works the same, it just gives you full resolution.
static uint64_t GetFullTickCount();
static float FullTicksToMs(uint64_t ticks);
//
// Pass GetTheTimer() into other process space, and then call SetTheTimer() on it.
static void SetTheTimer(plTimerShare* timer);

View File

@ -153,7 +153,7 @@ public:
protected:
const char* fName; // Name of timer
uint32_t fValue;
uint64_t fValue;
uint32_t fAvgCount;
uint64_t fAvgTotal;
@ -168,7 +168,7 @@ protected:
void IAddAvg();
void IPrintValue(uint32_t value, char* buf, bool printType);
void IPrintValue(uint64_t value, char* buf, bool printType);
public:
plProfileBase();
@ -179,7 +179,7 @@ public:
void UpdateAvg();
uint32_t GetValue();
uint64_t GetValue();
void PrintValue(char* buf, bool printType=true);
void PrintAvg(char* buf, bool printType=true);
@ -230,7 +230,7 @@ public:
void Inc(int i = 1) { fValue += i;}
void Dec(int i = 1) { fValue -= i;}
void Set(uint32_t value) { fValue = value; }
void Set(uint64_t value) { fValue = value; }
//
// For multiple timings per frame of the same thing ie. Each particle system
@ -249,4 +249,4 @@ public:
void SetLapsActive(bool s) { fLapsActive = s; }
};
#endif // plProfile_h_inc
#endif // plProfile_h_inc

View File

@ -150,15 +150,15 @@ uint32_t GetProcSpeedAlt()
}
#define GetProfileTicks() GetPentiumCounter()
#define TicksToMSec(t) (float(t) / float(gCyclesPerMS))
#else
#define GetProfileTicks() hsTimer::GetPrecTickCount()
#define GetProfileTicks() hsTimer::GetTicks()
#define TicksToMSec(t) hsTimer::GetMilliSeconds<float>(t)
#endif // USE_FAST_TIMER
#define TicksToMSec(t) (float(t) / float(gCyclesPerMS))
#define MSecToTicks(t) (float(t) * float(gCyclesPerMS))
plProfileManager::plProfileManager() : fLastAvgTime(0), fProcessorSpeed(0)
{
@ -169,8 +169,6 @@ plProfileManager::plProfileManager() : fLastAvgTime(0), fProcessorSpeed(0)
fProcessorSpeed = GetProcSpeedAlt();
gCyclesPerMS = fProcessorSpeed / 1000;
#else
gCyclesPerMS = hsTimer::GetPrecTicksPerSec() / 1000;
#endif
}
@ -251,7 +249,7 @@ void plProfileManager::EndFrame()
}
}
uint32_t plProfileManager::GetTime()
uint64_t plProfileManager::GetTime()
{
return GetProfileTicks();
}
@ -300,10 +298,10 @@ void plProfileBase::UpdateAvg()
}
}
uint32_t plProfileBase::GetValue()
uint64_t plProfileBase::GetValue()
{
if (hsCheckBits(fDisplayFlags, kDisplayTime))
return (uint32_t)TicksToMSec(fValue);
return (uint64_t)TicksToMSec(fValue);
else
return fValue;
}
@ -334,7 +332,7 @@ static const char *insertCommas(unsigned int value)
return str;
}
void plProfileBase::IPrintValue(uint32_t value, char* buf, bool printType)
void plProfileBase::IPrintValue(uint64_t value, char* buf, bool printType)
{
if (hsCheckBits(fDisplayFlags, kDisplayCount))
{
@ -416,7 +414,7 @@ plProfileLaps::LapInfo* plProfileLaps::IFindLap(const char* lapName)
return nil;
}
void plProfileLaps::BeginLap(uint32_t curValue, const char* name)
void plProfileLaps::BeginLap(uint64_t curValue, const char* name)
{
LapInfo* lap = IFindLap(name);
if (!lap)
@ -432,7 +430,7 @@ void plProfileLaps::BeginLap(uint32_t curValue, const char* name)
lap->BeginTiming(curValue);
}
void plProfileLaps::EndLap(uint32_t curValue, const char* name)
void plProfileLaps::EndLap(uint64_t curValue, const char* name)
{
LapInfo* lap = IFindLap(name);

View File

@ -76,7 +76,7 @@ public:
uint32_t GetProcessorSpeed() { return fProcessorSpeed; }
// Backdoor for hack timers in calculated profiles
static uint32_t GetTime();
static uint64_t GetTime();
};
class plProfileLaps
@ -91,16 +91,16 @@ protected:
LapInfo(const char* name) { fName = name; fDisplayFlags = kDisplayTime; }
bool operator<(const LapInfo& rhs) const { return fLastAvg < rhs.fLastAvg; }
void BeginTiming(uint32_t value) { fValue -= value; }
void EndTiming(uint32_t value) { fValue += value; fTimerSamples++; }
void BeginTiming(uint64_t value) { fValue -= value; }
void EndTiming(uint64_t value) { fValue += value; fTimerSamples++; }
};
std::vector<LapInfo> fLapTimes;
LapInfo* IFindLap(const char* lapName);
public:
void BeginLap(uint32_t curValue, const char* name);
void EndLap(uint32_t curValue, const char* name);
void BeginLap(uint64_t curValue, const char* name);
void EndLap(uint64_t curValue, const char* name);
void BeginFrame();
void EndFrame();