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