MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #include "MyGUI_Precompiled.h" 00008 #include "MyGUI_Timer.h" 00009 00010 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC 00011 # include <windows.h> 00012 # pragma comment(lib, "winmm.lib") 00013 #else 00014 # include <sys/time.h> 00015 #endif 00016 00017 namespace MyGUI 00018 { 00019 00020 Timer::Timer() : 00021 mTimeStart(0) 00022 { 00023 } 00024 00025 void Timer::reset() 00026 { 00027 mTimeStart = getCurrentMilliseconds(); 00028 } 00029 00030 unsigned long Timer::getMilliseconds() 00031 { 00032 return getCurrentMilliseconds() - mTimeStart; 00033 } 00034 00035 unsigned long Timer::getCurrentMilliseconds() 00036 { 00037 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC 00038 /* 00039 We do this because clock() is not affected by timeBeginPeriod on Win32. 00040 QueryPerformanceCounter is a little overkill for the amount of precision that 00041 I consider acceptable. If someone submits a patch that replaces this code 00042 with QueryPerformanceCounter, I wouldn't complain. Until then, timeGetTime 00043 gets the results I'm after. -EMS 00044 00045 See: http://www.geisswerks.com/ryan/FAQS/timing.html 00046 And: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323& 00047 */ 00048 return timeGetTime(); 00049 #else 00050 struct timeval now; 00051 gettimeofday(&now, NULL); 00052 return (now.tv_sec) * 1000 + (now.tv_usec) / 1000; 00053 //return ( unsigned long )(( double )( clock() ) / (( double )CLOCKS_PER_SEC / 1000.0 ) ); 00054 #endif 00055 } 00056 00057 } // namespace MyGUI