High Performance Timer for DirectX

Thomas_Szafran

Newcomer
Joined
Feb 16, 2003
Messages
2
Hi, I am creating a high performance timer for my DirectX game, it is roughly based off the DirectX timer in the DirectX9 SDK.

This is my function but unfortuneatly it returns a 0 everytime, any ideas?


Visual Basic:
Public Function GetFramesPerSecond() As Single
        Static m_FPS As Single
        Static m_Frames As Long
        Static m_LastTime As Long

        If m_bUsingQPF Then
            Dim qwTime As Long = 0

            ' Get either the current time or the stop time, depending
            ' on whether we're stopped and what command was sent
            If m_llStopTime <> 0 And isTimerInitialized Then
                qwTime = m_llStopTime
            Else
                QueryPerformanceCounter(qwTime)
            End If

            'Return frames per second.
            m_FPS += 1
            If qwTime - m_LastTime >= 1000 Then
                m_FPS = m_Frames
                m_LastTime = qwTime
                m_Frames = 0
            End If
            Return CSng(m_FPS)
        Else
            'Get the time using timeGetTime()
            Dim time As Double = timeGetTime() * 0.001

            'Return frames per second.
            m_FPS += 1
            If time - m_LastTime >= 1000 Then
                m_FPS = m_Frames
                m_LastTime = time
                m_Frames = 0
            End If
            Return CSng(m_FPS)
        End If
    End Function
 
Visual Basic:
Public Function GetFramesPerSecond() As Single
        Static m_FPS As Single 'Static Variables could be doggey, try Private
        Static m_LastTime As Long

        If m_bUsingQPF Then
            Dim qwTime As Long = 0

            ' Get either the current time or the stop time, depending
            ' on whether we're stopped and what command was sent
'WARNING: This will NOT work, if stoptime<>0 and timer=On Then qwTime = AlwaysTheSame
            If m_llStopTime <> 0 And isTimerInitialized Then
                qwTime = m_llStopTime
            Else
                QueryPerformanceCounter(qwTime)
            End If

            'Return frames per second.
            m_FPS += 1
            If qwTime - m_LastTime >= 1000 Then
                m_FPS = 0
                m_LastTime = qwTime
            End If
            Return CSng(m_FPS)
        Else
            'Get the time using timeGetTime()
            Dim time As Double = timeGetTime() * 0.001

            'Return frames per second.
            m_FPS += 1
            If time - m_LastTime >= 1000 Then
                m_FPS = 0
                m_LastTime = time
            End If
            Return CSng(m_FPS)
        End If
    End Function
Question: Are you calling this function every game loop?
 
Back
Top