MyGUI 3.4.1
MyGUI_Timer.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_Timer.h"
9
10#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
11# include <windows.h>
12# pragma comment(lib, "winmm.lib")
13#else
14# include <sys/time.h>
15#endif
16
17namespace MyGUI
18{
19
21 mTimeStart(0)
22 {
23 }
24
26 {
27 mTimeStart = getCurrentMilliseconds();
28 }
29
30 unsigned long Timer::getMilliseconds() const
31 {
32 return getCurrentMilliseconds() - mTimeStart;
33 }
34
35 unsigned long Timer::getCurrentMilliseconds() const
36 {
37#if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
38 /*
39 We do this because clock() is not affected by timeBeginPeriod on Win32.
40 QueryPerformanceCounter is a little overkill for the amount of precision that
41 I consider acceptable. If someone submits a patch that replaces this code
42 with QueryPerformanceCounter, I wouldn't complain. Until then, timeGetTime
43 gets the results I'm after. -EMS
44
45 See: http://www.geisswerks.com/ryan/FAQS/timing.html
46 And: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323&
47 */
48 return timeGetTime();
49#else
50 struct timeval now;
51 gettimeofday(&now, nullptr);
52 return (now.tv_sec) * 1000 + (now.tv_usec) / 1000;
53 //return ( unsigned long )(( double )( clock() ) / (( double )CLOCKS_PER_SEC / 1000.0 ) );
54#endif
55 }
56
57} // namespace MyGUI
unsigned long getMilliseconds() const
Definition: MyGUI_Timer.cpp:30