• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_Timer.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009     
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014     
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019     
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_Timer.h"
00025 
00026 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
00027 #   include <windows.h>
00028 #   ifndef __MINGW32__
00029 #       pragma comment(lib, "winmm.lib")
00030 #   else
00031 #       pragma comment(lib, "libwinmm.a")
00032 #   endif
00033 #endif
00034 
00035 namespace MyGUI
00036 {
00037 
00038     void Timer::reset()
00039     {
00040         mTimeStart = getCurrentMilliseconds();
00041     }
00042 
00043     unsigned long Timer::getMilliseconds()
00044     {
00045         return getCurrentMilliseconds() - mTimeStart;
00046     }
00047 
00048     unsigned long Timer::getCurrentMilliseconds()
00049     {
00050 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
00051         /*
00052         We do this because clock() is not affected by timeBeginPeriod on Win32.
00053         QueryPerformanceCounter is a little overkill for the amount of precision that
00054         I consider acceptable. If someone submits a patch that replaces this code
00055         with QueryPerformanceCounter, I wouldn't complain. Until then, timeGetTime
00056         gets the results I'm after. -EMS
00057 
00058         See: http://www.geisswerks.com/ryan/FAQS/timing.html
00059         And: http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323&
00060         */
00061         return timeGetTime();
00062 #else
00063         return ( unsigned long )(( float )( clock() ) / (( float )CLOCKS_PER_SEC / 1000.0 ) );
00064 #endif
00065     }
00066 
00067 
00068 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1