VCRA-SZCZERBACKI-PointBasedRendering/timer.cpp

00001 #include "timer.h"
00002 #include <windows.h>
00003 
00004 //=============================================================================
00005 //=============================================================================
00006 
00007 static FARPROC timeGetTimeImp = NULL;
00008 static HMODULE libraryInstance = NULL;
00009 
00010 SS::UINT32      Timer::m_startTime = 0;
00011 SS::UINT32      Timer::m_currentTime = 0;
00012 int             Timer::m_referenceCount = 0;
00013 
00014 //=============================================================================
00015 //=============================================================================
00016 
00017 Timer::Timer( )
00018 {
00019         if( m_referenceCount++ == 0 )
00020         {
00021                 libraryInstance = LoadLibrary("WINMM.DLL");
00022                 if( !libraryInstance ) svError("couldn't load WINMM.DLL");
00023                 timeGetTimeImp = GetProcAddress(libraryInstance,"timeGetTime");
00024                 if( !timeGetTimeImp ) svError("couldn't find function timeGetTime from WINMM.DLL");
00025 
00026                 m_startTime  = timeGetTimeImp();
00027                 m_currentTime = m_startTime;
00028         }
00029 
00030         m_initialAge = getAge( );
00031         m_newAge = 0.0f;
00032         m_prevAge = 0.0f;
00033 }
00034 
00035 //=============================================================================
00036 //=============================================================================
00037 
00038 Timer::~Timer( )
00039 {
00040         if( --m_referenceCount == 0 )
00041         {
00042                 if( libraryInstance ) FreeLibrary(libraryInstance);
00043                 libraryInstance = NULL;
00044         }
00045 }
00046 
00047 //=============================================================================
00048 //=============================================================================
00049 
00050 float Timer::getAge( )
00051 {
00052         m_currentTime = timeGetTimeImp( );
00053         return float( m_currentTime - m_startTime ) / 1000.0f;
00054 }
00055 
00056 //=============================================================================
00057 //=============================================================================
00058 
00059 // calculate delta from last call to sample
00060 float Timer::sample( )
00061 {
00062         m_prevAge = m_newAge;
00063         m_newAge = getAge( ) - m_initialAge;
00064         return m_newAge - m_prevAge;
00065 }
00066 
00067 //=============================================================================
00068 //=============================================================================
00069 
00070 // get the difference between the last two sample calls
00071 float Timer::getDelta( ) const
00072 {
00073         return m_newAge - m_prevAge;
00074 }
00075 
00076 //=============================================================================
00077 //=============================================================================

Generated on Thu Feb 15 09:09:20 2007 for Surface Splating by  doxygen 1.5.1-p1