From 7aee50e5fd6147569f5979f03f6c1e23511a83d2 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 11 Jun 2004 01:01:31 +0000 Subject: [PATCH] make this static, so it can be used before main() --- stepmania/src/arch/ArchHooks/ArchHooks.h | 6 +++- .../src/arch/ArchHooks/ArchHooks_Win32.cpp | 29 ++++++++++++------- .../src/arch/ArchHooks/ArchHooks_Win32.h | 1 - 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/stepmania/src/arch/ArchHooks/ArchHooks.h b/stepmania/src/arch/ArchHooks/ArchHooks.h index 12ed6f4a4d..39d541768a 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks.h @@ -38,8 +38,12 @@ public: * * Note that bAccurate may change the result significantly; it may use a different * timer, and may have a different concept of when the program "started". + * + * This is a static function, implemented in whichever ArchHooks source is used, + * so it can be used at any time (such as in global constructors), before HOOKS + * is initialized. */ - virtual int64_t GetMicrosecondsSinceStart( bool bAccurate ) = 0; + static int64_t GetMicrosecondsSinceStart( bool bAccurate ); }; ArchHooks *MakeArchHooks(); diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp index 6dcd9c91ed..dce05e1d04 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.cpp @@ -185,18 +185,25 @@ void ArchHooks_Win32::SetTime( tm newtime ) SetLocalTime( &st ); } -int64_t ArchHooks_Win32::GetMicrosecondsSinceStart( bool bAccurate ) -{ - static bool bInitialized; - static DWORD iStartTime; - if( !bInitialized ) - { - timeBeginPeriod( 1 ); - bInitialized = true; - iStartTime = timeGetTime(); - } +static bool g_bTimerInitialized; +static DWORD g_iStartTime; - return (timeGetTime() - iStartTime) * 1000; +static void InitTimer() +{ + if( g_bTimerInitialized ) + return; + g_bTimerInitialized = true; + + timeBeginPeriod( 1 ); + g_iStartTime = timeGetTime(); +} + +int64_t ArchHooks::GetMicrosecondsSinceStart( bool bAccurate ) +{ + if( !g_bTimerInitialized ) + InitTimer(); + + return (timeGetTime() - g_iStartTime) * 1000; } /* diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h index cc21ee1ff1..c9a6b51f08 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h +++ b/stepmania/src/arch/ArchHooks/ArchHooks_Win32.h @@ -17,7 +17,6 @@ public: void EnterTimeCriticalSection(); void ExitTimeCriticalSection(); void SetTime( tm newtime ); - int64_t GetMicrosecondsSinceStart( bool bAccurate ); private: void CheckVideoDriver();