00001 /* 00002 Copyright (C) 2001-2006, William Joseph. 00003 All Rights Reserved. 00004 00005 This file is part of GtkRadiant. 00006 00007 GtkRadiant is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 GtkRadiant is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GtkRadiant; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #if !defined (INCLUDED_TIMER_H) 00023 #define INCLUDED_TIMER_H 00024 00025 const int msec_per_sec = 1000; 00026 00027 class MillisecondTime 00028 { 00029 unsigned int m_milliseconds; 00030 public: 00031 MillisecondTime (unsigned int milliseconds) : 00032 m_milliseconds(milliseconds) 00033 { 00034 } 00035 MillisecondTime () 00036 { 00037 } 00038 static MillisecondTime current (); 00039 00040 unsigned int milliseconds_since (const MillisecondTime& other) const 00041 { 00042 return m_milliseconds - other.m_milliseconds; 00043 } 00044 }; 00045 00046 template<typename tick_type> 00047 inline MillisecondTime time_from_ticks (tick_type tick_count, tick_type ticks_per_sec) 00048 { 00049 return MillisecondTime(static_cast<unsigned int> (tick_count / static_cast<double> (ticks_per_sec / msec_per_sec))); 00050 } 00051 00052 class Timer 00053 { 00054 MillisecondTime m_start; 00055 00056 public: 00057 void start () 00058 { 00059 m_start = MillisecondTime::current(); 00060 } 00061 unsigned int elapsed_msec () 00062 { 00063 return MillisecondTime::current().milliseconds_since(m_start); 00064 } 00065 }; 00066 00067 #endif