DriverGame/DriverGame/Utility.cs
/// <summary>
/// Performs timer opertations. Use the following commands:
/// 
///          DirectXTimer.Reset - to reset the timer
///          DirectXTimer.Start - to start the timer
///          DirectXTimer.Stop - to stop (or pause) the timer
///          DirectXTimer.Advance - to advance the timer by 0.1 seconds
///          DirectXTimer.GetAbsoluteTime - to get the absolute system time
///          DirectXTimer.GetApplicationTime - to get the current time
///          DirectXTimer.GetElapsedTime - to get the time that elapsed between TIMER_GETELAPSEDTIME calls
///
/// </summary>
Performs timer opertations. Use the following commands.


Performs timer opertations . Use the following commands .
public static float Timer(DirectXTimer command)
        {
            if (!isTimerInitialized)
            {
                isTimerInitialized = true;
                long qwTicksPerSec = 0;
                m_bUsingQPF = QueryPerformanceFrequency(ref qwTicksPerSec);
                if (m_bUsingQPF)
                    m_llQPFTicksPerSec = qwTicksPerSec;
            }
            if (m_bUsingQPF)
            {
                double time;
                double fElapsedTime;
                long qwTime = 0;
                if (m_llStopTime != 0 && command != DirectXTimer.Start && command != DirectXTimer.GetAbsoluteTime)
                    qwTime = m_llStopTime;
                else
                    QueryPerformanceCounter(ref qwTime);
                if (command == DirectXTimer.GetElapsedTime)
                {
                    fElapsedTime = (double)(qwTime - m_llLastElapsedTime) / (double)m_llQPFTicksPerSec;
                    m_llLastElapsedTime = qwTime;
                    return (float)fElapsedTime;
                }
                if (command == DirectXTimer.GetApplicationTime)
                {
                    double fAppTime = (double)(qwTime - m_llBaseTime) / (double)m_llQPFTicksPerSec;
                    return (float)fAppTime;
                }
                if (command == DirectXTimer.Reset)
                {
                    m_llBaseTime = qwTime;
                    m_llLastElapsedTime = qwTime;
                    m_llStopTime = 0;
                    m_bTimerStopped = false;
                    return 0.0f;
                }
                if (command == DirectXTimer.Start)
                {
                    if (m_bTimerStopped)
                        m_llBaseTime += qwTime - m_llStopTime;
                    m_llStopTime = 0;
                    m_llLastElapsedTime = qwTime;
                    m_bTimerStopped = false;
                    return 0.0f;
                }
                if (command == DirectXTimer.Stop)
                {
                    if (!m_bTimerStopped)
                    {
                        m_llStopTime = qwTime;
                        m_llLastElapsedTime = qwTime;
                        m_bTimerStopped = true;
                    }
                    return 0.0f;
                }
                if (command == DirectXTimer.Advance)
                {
                    m_llStopTime += m_llQPFTicksPerSec / 10;
                    return 0.0f;
                }
                if (command == DirectXTimer.GetAbsoluteTime)
                {
                    time = qwTime / (double)m_llQPFTicksPerSec;
                    return (float)time;
                }
                return -1.0f; 
            }
            else
            {
                double time;
                double fElapsedTime;
                if (m_fStopTime != 0.0 && command != DirectXTimer.Start && command != DirectXTimer.GetAbsoluteTime)
                    time = m_fStopTime;
                else
                    time = timeGetTime() * 0.001;
                if (command == DirectXTimer.GetElapsedTime)
                {
                    fElapsedTime = (double)(time - m_fLastElapsedTime);
                    m_fLastElapsedTime = time;
                    return (float)fElapsedTime;
                }
                if (command == DirectXTimer.GetApplicationTime)
                {
                    return (float)(time - m_fBaseTime);
                }
                if (command == DirectXTimer.Reset)
                {
                    m_fBaseTime = time;
                    m_fLastElapsedTime = time;
                    m_fStopTime = 0;
                    m_bTimerStopped = false;
                    return 0.0f;
                }
                if (command == DirectXTimer.Start)
                {
                    if (m_bTimerStopped)
                        m_fBaseTime += time - m_fStopTime;
                    m_fStopTime = 0.0f;
                    m_fLastElapsedTime = time;
                    m_bTimerStopped = false;
                    return 0.0f;
                }
                if (command == DirectXTimer.Stop)
                {
                    if (!m_bTimerStopped)
                    {
                        m_fStopTime = time;
                        m_fLastElapsedTime = time;
                        m_bTimerStopped = true;
                    }
                    return 0.0f;
                }
                if (command == DirectXTimer.Advance)
                {
                    m_fStopTime += 0.1f;
                    return 0.0f;
                }
                if (command == DirectXTimer.GetAbsoluteTime)
                {
                    return (float)time;
                }
                return -1.0f; 
            }
        }
public static float Timer ( DirectXTimer command ) { if ( ! isTimerInitialized ) { isTimerInitialized = true ; long qwTicksPerSec = 0 ; m_bUsingQPF = QueryPerformanceFrequency ( ref qwTicksPerSec ) ; if ( m_bUsingQPF ) m_llQPFTicksPerSec = qwTicksPerSec ; } if ( m_bUsingQPF ) { double time ; double fElapsedTime ; long qwTime = 0 ; if ( m_llStopTime != 0 && command != DirectXTimer . Start && command != DirectXTimer . GetAbsoluteTime ) qwTime = m_llStopTime ; else QueryPerformanceCounter ( ref qwTime ) ; if ( command == DirectXTimer . GetElapsedTime ) { fElapsedTime = ( double ) ( qwTime - m_llLastElapsedTime ) / ( double ) m_llQPFTicksPerSec ; m_llLastElapsedTime = qwTime ; return ( float ) fElapsedTime ; } if ( command == DirectXTimer . GetApplicationTime ) { double fAppTime = ( double ) ( qwTime - m_llBaseTime ) / ( double ) m_llQPFTicksPerSec ; return ( float ) fAppTime ; } if ( command == DirectXTimer . Reset ) { m_llBaseTime = qwTime ; m_llLastElapsedTime = qwTime ; m_llStopTime = 0 ; m_bTimerStopped = false ; return 0.0f ; } if ( command == DirectXTimer . Start ) { if ( m_bTimerStopped ) m_llBaseTime += qwTime - m_llStopTime ; m_llStopTime = 0 ; m_llLastElapsedTime = qwTime ; m_bTimerStopped = false ; return 0.0f ; } if ( command == DirectXTimer . Stop ) { if ( ! m_bTimerStopped ) { m_llStopTime = qwTime ; m_llLastElapsedTime = qwTime ; m_bTimerStopped = true ; } return 0.0f ; } if ( command == DirectXTimer . Advance ) { m_llStopTime += m_llQPFTicksPerSec / 10 ; return 0.0f ; } if ( command == DirectXTimer . GetAbsoluteTime ) { time = qwTime / ( double ) m_llQPFTicksPerSec ; return ( float ) time ; } return - 1.0f ; } else { double time ; double fElapsedTime ; if ( m_fStopTime != 0.0 && command != DirectXTimer . Start && command != DirectXTimer . GetAbsoluteTime ) time = m_fStopTime ; else time = timeGetTime ( ) * 0.001 ; if ( command == DirectXTimer . GetElapsedTime ) { fElapsedTime = ( double ) ( time - m_fLastElapsedTime ) ; m_fLastElapsedTime = time ; return ( float ) fElapsedTime ; } if ( command == DirectXTimer . GetApplicationTime ) { return ( float ) ( time - m_fBaseTime ) ; } if ( command == DirectXTimer . Reset ) { m_fBaseTime = time ; m_fLastElapsedTime = time ; m_fStopTime = 0 ; m_bTimerStopped = false ; return 0.0f ; } if ( command == DirectXTimer . Start ) { if ( m_bTimerStopped ) m_fBaseTime += time - m_fStopTime ; m_fStopTime = 0.0f ; m_fLastElapsedTime = time ; m_bTimerStopped = false ; return 0.0f ; } if ( command == DirectXTimer . Stop ) { if ( ! m_bTimerStopped ) { m_fStopTime = time ; m_fLastElapsedTime = time ; m_bTimerStopped = true ; } return 0.0f ; } if ( command == DirectXTimer . Advance ) { m_fStopTime += 0.1f ; return 0.0f ; } if ( command == DirectXTimer . GetAbsoluteTime ) { return ( float ) time ; } return - 1.0f ; } }
Performs timer opertations.
Performs timer opertations .
// Use QueryPerformanceFrequency() to get frequency of timer.  If QPF is // not supported, we will timeGetTime() which returns milliseconds. // Get either the current time or the stop time, depending // on whether we're stopped and what command was sent // Return the elapsed time // Return the current time // Reset the timer // Start the timer // Stop the timer // Advance the timer by 1/10th second // Invalid command specified // Get the time using timeGetTime() // Get either the current time or the stop time, depending // on whether we're stopped and what command was sent // Return the elapsed time // Return the current time // Reset the timer // Start the timer // Stop the timer // Advance the timer by 1/10th second // Invalid command specified
command
DirectXTimer