X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Ftimer.h;h=53280a8ca81d17aadf2c34d5a31fab58cb92d204;hb=7b51c9cbca692b2da959845a246847cec35e3939;hp=a8945200dffe1dc615753f6f6d919edf888983df;hpb=107765f0e4b543dfc346851ee5b4605cc17eb1c6;p=xonotic%2Fnetradiant.git diff --git a/radiant/timer.h b/radiant/timer.h index a8945200..53280a8c 100644 --- a/radiant/timer.h +++ b/radiant/timer.h @@ -1,25 +1,25 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined (INCLUDED_TIMER_H) +#if !defined ( INCLUDED_TIMER_H ) #define INCLUDED_TIMER_H #if 1 @@ -28,27 +28,23 @@ const int msec_per_sec = 1000; class MillisecondTime { - unsigned int m_milliseconds; +unsigned int m_milliseconds; public: - MillisecondTime(unsigned int milliseconds) - : m_milliseconds(milliseconds) - { - } - MillisecondTime() - { - } - static MillisecondTime current(); - - unsigned int milliseconds_since(const MillisecondTime& other) const - { - return m_milliseconds - other.m_milliseconds; - } +MillisecondTime( unsigned int milliseconds ) + : m_milliseconds( milliseconds ){ +} +MillisecondTime(){ +} +static MillisecondTime current(); + +unsigned int milliseconds_since( const MillisecondTime& other ) const { + return m_milliseconds - other.m_milliseconds; +} }; template -inline MillisecondTime time_from_ticks(tick_type tick_count, tick_type ticks_per_sec) -{ - return MillisecondTime(static_cast(tick_count / static_cast(ticks_per_sec / msec_per_sec))); +inline MillisecondTime time_from_ticks( tick_type tick_count, tick_type ticks_per_sec ){ + return MillisecondTime( static_cast( tick_count / static_cast( ticks_per_sec / msec_per_sec ) ) ); } #else @@ -57,47 +53,41 @@ const unsigned int usec_per_sec = 1000000; class MillisecondTime { - unsigned int m_sec; - unsigned int m_usec; +unsigned int m_sec; +unsigned int m_usec; public: - MillisecondTime(unsigned int sec, unsigned int usec) - : m_sec(sec), m_usec(usec) - { - } - MillisecondTime() - { - } - staticMillisecondTime current(); - - unsigned int milliseconds_since(const MillisecondTime& other) const - { - return static_cast((m_sec * static_cast(usec_per_sec) + m_usec) - - (other.m_sec * static_cast(usec_per_sec) + other.m_usec)) / 1000; - } +MillisecondTime( unsigned int sec, unsigned int usec ) + : m_sec( sec ), m_usec( usec ){ +} +MillisecondTime(){ +} +staticMillisecondTime current(); + +unsigned int milliseconds_since( const MillisecondTime& other ) const { + return static_cast( ( m_sec * static_cast( usec_per_sec ) + m_usec ) + - ( other.m_sec * static_cast( usec_per_sec ) + other.m_usec ) ) / 1000; +} }; template -inline MillisecondTime time_from_ticks(tick_type tick_count, tick_type ticks_per_sec) -{ - return MillisecondTime(static_cast(tick_count / ticks_per_sec), - static_cast((tick_count % ticks_per_sec) * (usec_per_sec / static_cast(ticks_per_sec)))); +inline MillisecondTime time_from_ticks( tick_type tick_count, tick_type ticks_per_sec ){ + return MillisecondTime( static_cast( tick_count / ticks_per_sec ), + static_cast( ( tick_count % ticks_per_sec ) * ( usec_per_sec / static_cast( ticks_per_sec ) ) ) ); } #endif class Timer { - MillisecondTime m_start; +MillisecondTime m_start; public: - void start() - { - m_start = MillisecondTime::current(); - } - unsigned int elapsed_msec() - { - return MillisecondTime::current().milliseconds_since(m_start); - } +void start(){ + m_start = MillisecondTime::current(); +} +unsigned int elapsed_msec(){ + return MillisecondTime::current().milliseconds_since( m_start ); +} }; #endif