From 1f1556998546e7cfe3b38fab00a70a948c35bcc0 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 15 Nov 2001 00:50:13 +0000 Subject: Added ElapsedTime. --- win32/PlatWin.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'win32') diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 666c962cf..d227aa7a1 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -10,6 +10,7 @@ #include #include #include +#include #define _WIN32_WINNT 0x0400 #include @@ -872,6 +873,46 @@ void Menu::Show(Point pt, Window &w) { Destroy(); } +static bool initialisedET = false; +static bool usePerformanceCounter = false; +static LARGE_INTEGER frequency; + +static double Now() { + if (usePerformanceCounter) { + LARGE_INTEGER timeVal; + ::QueryPerformanceCounter(&timeVal); + return *(reinterpret_cast(&timeVal)); + } else { + return clock(); + } +} + +ElapsedTime::ElapsedTime() { + if (!initialisedET) { + usePerformanceCounter = ::QueryPerformanceFrequency(&frequency); + initialisedET = true; + } + beginTime = Now(); +} + +double ElapsedTime::Duration(bool reset) { + double endTime = Now(); + double result; + if (usePerformanceCounter) { + LARGE_INTEGER lBegin = *(reinterpret_cast(&beginTime)); + LARGE_INTEGER lEnd = *(reinterpret_cast(&endTime)); + double elapsed = lEnd.QuadPart - lBegin.QuadPart; + result = elapsed / static_cast(frequency.QuadPart); + } else { + double elapsed = endTime - beginTime; + result = elapsed / CLOCKS_PER_SEC; + } + if (reset) { + beginTime = endTime; + } + return result; +} + ColourDesired Platform::Chrome() { return ::GetSysColor(COLOR_3DFACE); } -- cgit v1.2.3