add last backwards-compatible version
This commit is contained in:
28
pfc/timers.h
28
pfc/timers.h
@@ -42,9 +42,14 @@ namespace pfc {
|
||||
#ifdef _WIN32
|
||||
|
||||
namespace pfc {
|
||||
// ALWAYS define 64bit tickcount - don't cause mayhem if different modules are compiled for different Windows versions
|
||||
typedef uint64_t tickcount_t;
|
||||
inline tickcount_t getTickCount() { return GetTickCount64(); }
|
||||
#if _WIN32_WINNT >= 0x600
|
||||
typedef uint64_t tickcount_t;
|
||||
inline tickcount_t getTickCount() { return GetTickCount64(); }
|
||||
#else
|
||||
#define PFC_TICKCOUNT_32BIT
|
||||
typedef uint32_t tickcount_t;
|
||||
inline tickcount_t getTickCount() { return GetTickCount(); }
|
||||
#endif
|
||||
|
||||
class hires_timer {
|
||||
public:
|
||||
@@ -83,7 +88,7 @@ private:
|
||||
|
||||
class lores_timer {
|
||||
public:
|
||||
lores_timer() {}
|
||||
lores_timer() : m_start() {}
|
||||
void start() {
|
||||
_start(getTickCount());
|
||||
}
|
||||
@@ -102,12 +107,25 @@ public:
|
||||
}
|
||||
private:
|
||||
void _start(tickcount_t p_time) {
|
||||
#ifdef PFC_TICKCOUNT_32BIT
|
||||
m_last_seen = p_time;
|
||||
#endif
|
||||
m_start = p_time;
|
||||
}
|
||||
double _query(tickcount_t p_time) const {
|
||||
#ifdef PFC_TICKCOUNT_32BIT
|
||||
t_uint64 time = p_time;
|
||||
if (time < (m_last_seen & 0xFFFFFFFF)) time += 0x100000000;
|
||||
m_last_seen = (m_last_seen & 0xFFFFFFFF00000000) + time;
|
||||
return (double)(m_last_seen - m_start) / 1000.0;
|
||||
#else
|
||||
return (double)(p_time - m_start) / 1000.0;
|
||||
#endif
|
||||
}
|
||||
t_uint64 m_start = 0;
|
||||
t_uint64 m_start;
|
||||
#ifdef PFC_TICKCOUNT_32BIT
|
||||
mutable t_uint64 m_last_seen;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
#else // not _WIN32
|
||||
|
||||
Reference in New Issue
Block a user