MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_Timer.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_Timer.h"
24
25 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
26 # include <windows.h>
27 # pragma comment(lib, "winmm.lib")
28 #else
29 # include <sys/time.h>
30 #endif
31
32 namespace MyGUI
33 {
34
35 Timer::Timer() :
36 mTimeStart(0)
37 {
38 }
39
40 void Timer::reset()
41 {
42 mTimeStart = getCurrentMilliseconds();
43 }
44
45 unsigned long Timer::getMilliseconds()
46 {
47 return getCurrentMilliseconds() - mTimeStart;
48 }
49
50 unsigned long Timer::getCurrentMilliseconds()
51 {
52 #if MYGUI_COMPILER == MYGUI_COMPILER_MSVC
53 /*
54 We do this because clock() is not affected by timeBeginPeriod on Win32.
55 QueryPerformanceCounter is a little overkill for the amount of precision that
56 I consider acceptable. If someone submits a patch that replaces this code
57 with QueryPerformanceCounter, I wouldn't complain. Until then, timeGetTime
58 gets the results I'm after. -EMS
59
60 See: http://www.geisswerks.com/ryan/FAQS/timing.html
61 And: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323&
62 */
63 return timeGetTime();
64 #else
65 struct timeval now;
66 gettimeofday(&now, NULL);
67 return (now.tv_sec) * 1000 + (now.tv_usec) / 1000;
68 //return ( unsigned long )(( double )( clock() ) / (( double )CLOCKS_PER_SEC / 1000.0 ) );
69 #endif
70 }
71
72 } // namespace MyGUI
MyGUI_Timer.h
MyGUI_Precompiled.h
MyGUI::Timer::getMilliseconds
unsigned long getMilliseconds()
Definition: MyGUI_Timer.cpp:45
MyGUI::Timer::Timer
Timer()
Definition: MyGUI_Timer.cpp:35
MyGUI::Timer::reset
void reset()
Definition: MyGUI_Timer.cpp:40