diff --git a/Makefile b/Makefile index 375d0014..17cfc002 100644 --- a/Makefile +++ b/Makefile @@ -892,7 +892,6 @@ $(INSTALLDIR)/radiant.$(EXE): \ radiant/texmanip.o \ radiant/textures.o \ radiant/texwindow.o \ - radiant/timer.o \ radiant/treemodel.o \ radiant/undo.o \ radiant/url.o \ diff --git a/radiant/timer.h b/libs/timer.h similarity index 66% rename from radiant/timer.h rename to libs/timer.h index e4631ad8..45964b56 100644 --- a/radiant/timer.h +++ b/libs/timer.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2001-2006, William Joseph. + Copyright (C) 2001-2006, William Joseph. All Rights Reserved. This file is part of GtkRadiant. @@ -21,19 +21,25 @@ #pragma once -#include +#include class Timer { - std::intmax_t m_start; + std::chrono::time_point m_start; public: Timer(){ start(); } - void start(); - int elapsed_msec() const; + void start(){ + m_start = std::chrono::steady_clock::now(); + } + int elapsed_msec() const { + return std::chrono::duration_cast( std::chrono::steady_clock::now() - m_start ).count(); + } double elapsed_sec() const { - return elapsed_msec() / 1000.0; + return std::chrono::duration( std::chrono::steady_clock::now() - m_start ).count(); } }; + + diff --git a/radiant/timer.cpp b/radiant/timer.cpp deleted file mode 100644 index dc34de6b..00000000 --- a/radiant/timer.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (C) 2001-2006, William Joseph. - All Rights Reserved. - - 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 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 - */ - -#include "timer.h" -#include - - -void Timer::start(){ - m_start = std::chrono::steady_clock::now().time_since_epoch().count(); -} - -int Timer::elapsed_msec() const { - return ( std::chrono::steady_clock::now().time_since_epoch().count() - m_start ) - * std::chrono::steady_clock::period::num - / ( std::chrono::steady_clock::period::den / 1000 ); -} diff --git a/tools/quake3/common/cmdlib.cpp b/tools/quake3/common/cmdlib.cpp index db18eecf..f291a773 100644 --- a/tools/quake3/common/cmdlib.cpp +++ b/tools/quake3/common/cmdlib.cpp @@ -34,9 +34,6 @@ #include "qpathops.h" #include "stream/stringstream.h" #include "stream/textstream.h" -#include -#include -#include #include #include @@ -83,34 +80,6 @@ char *ExpandArg( const char *path ){ -/* - ================ - I_FloatTime - ================ - */ -double I_FloatTime(){ - time_t t; - - time( &t ); - - return t; -#if 0 -// more precise, less portable - struct timeval tp; - struct timezone tzp; - static int secbase; - - gettimeofday( &tp, &tzp ); - - if ( !secbase ) { - secbase = tp.tv_sec; - return tp.tv_usec / 1000000.0; - } - - return ( tp.tv_sec - secbase ) + tp.tv_usec / 1000000.0; -#endif -} - void Q_getwd( char *out ){ #ifdef WIN32 _getcwd( out, 256 ); diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index 082f5640..e724c96b 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -89,8 +89,6 @@ void Q_mkdir( const char *path ); char *ExpandArg( const char *path ); // from cmd line -double I_FloatTime(); - FILE *SafeOpenWrite( const char *filename, const char *mode = "wb" ); FILE *SafeOpenRead( const char *filename, const char *mode = "rb" ); void SafeRead( FILE *f, MemBuffer& buffer ); diff --git a/tools/quake3/common/threads.cpp b/tools/quake3/common/threads.cpp index 73f9e5fa..eebad5f4 100644 --- a/tools/quake3/common/threads.cpp +++ b/tools/quake3/common/threads.cpp @@ -29,6 +29,7 @@ #include "cmdlib.h" #include "inout.h" #include "qthreads.h" +#include "timer.h" #define MAX_THREADS 64 @@ -170,9 +171,8 @@ void ThreadUnlock(){ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ HANDLE threadhandle[MAX_THREADS]; int i; - int start, end; + Timer timer; - start = I_FloatTime(); dispatch = 0; workcount = workcnt; oldf = -1; @@ -210,9 +210,8 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ DeleteCriticalSection( &crit ); threaded = false; - end = I_FloatTime(); if ( pacifier ) { - Sys_Printf( " (%i)\n", end - start ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); } } @@ -267,9 +266,8 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ pthread_addr_t status; pthread_attr_t attrib; pthread_mutexattr_t mattrib; - int start, end; + Timer timer; - start = I_FloatTime(); dispatch = 0; workcount = workcnt; oldf = -1; @@ -317,9 +315,8 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ threaded = false; - end = I_FloatTime(); if ( pacifier ) { - Sys_Printf( " (%i)\n", end - start ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); } } @@ -372,9 +369,8 @@ void ThreadUnlock(){ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ int i; int pid[MAX_THREADS]; - int start, end; + Timer timer; - start = I_FloatTime(); dispatch = 0; workcount = workcnt; oldf = -1; @@ -404,9 +400,8 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ threaded = false; - end = I_FloatTime(); if ( pacifier ) { - Sys_Printf( " (%i)\n", end - start ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); } } @@ -535,10 +530,9 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ pthread_t work_threads[MAX_THREADS]; size_t stacksize; - int start, end; + Timer timer; int i = 0; - start = I_FloatTime(); pacifier = showpacifier; dispatch = 0; @@ -588,9 +582,8 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ threaded = false; } - end = I_FloatTime(); if ( pacifier ) { - Sys_Printf( " (%i)\n", end - start ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); } } #endif // ifdef __linux__ @@ -625,18 +618,16 @@ void ThreadUnlock(){ */ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){ int i; - int start, end; + Timer timer; dispatch = 0; workcount = workcnt; oldf = -1; pacifier = showpacifier; - start = I_FloatTime(); func( 0 ); - end = I_FloatTime(); if ( pacifier ) { - Sys_Printf( " (%i)\n", end - start ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); } } diff --git a/tools/quake3/q3map2/decals.cpp b/tools/quake3/q3map2/decals.cpp index 5a984936..ffd8982a 100644 --- a/tools/quake3/q3map2/decals.cpp +++ b/tools/quake3/q3map2/decals.cpp @@ -30,6 +30,7 @@ /* dependencies */ #include "q3map2.h" +#include "timer.h" @@ -713,7 +714,7 @@ static void ProjectDecalOntoTriangles( decalProjector_t *dp, mapDrawSurface_t *d */ void MakeEntityDecals( entity_t *e ){ - int i, j, f, fOld, start; + int i, j, fOld; decalProjector_t dp; mapDrawSurface_t *ds; @@ -726,14 +727,13 @@ void MakeEntityDecals( entity_t *e ){ /* init pacifier */ fOld = -1; - start = I_FloatTime(); + Timer timer; /* walk the list of decal projectors */ for ( i = 0; i < numProjectors; i++ ) { /* print pacifier */ - f = 10 * i / numProjectors; - if ( f != fOld ) { + if ( const int f = 10 * i / numProjectors; f != fOld ) { fOld = f; Sys_FPrintf( SYS_VRB, "%d...", f ); } @@ -784,7 +784,7 @@ void MakeEntityDecals( entity_t *e ){ } /* print time */ - Sys_FPrintf( SYS_VRB, " (%d)\n", (int) ( I_FloatTime() - start ) ); + Sys_FPrintf( SYS_VRB, " (%d)\n", int( timer.elapsed_sec() ) ); /* emit some stats */ Sys_FPrintf( SYS_VRB, "%9d decal surfaces\n", numDecalSurfaces ); diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index 46d67519..60fedaa1 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -30,6 +30,7 @@ /* dependencies */ #include "q3map2.h" +#include "timer.h" // http://www.graficaobscura.com/matrix/index.html @@ -157,7 +158,7 @@ Vector3b ColorToBytes( const Vector3& color, float scale ){ #define EQUAL_NORMAL_EPSILON 0.01f void SmoothNormals(){ - int fOld, start; + int fOld; float shadeAngle, defaultShadeAngle, maxShadeAngle; int indexes[ MAX_SAMPLES ]; Vector3 votes[ MAX_SAMPLES ]; @@ -215,7 +216,7 @@ void SmoothNormals(){ /* init pacifier */ fOld = -1; - start = I_FloatTime(); + Timer timer; /* go through the list of vertexes */ for ( int i = 0; i < numBSPDrawVerts; i++ ) @@ -297,7 +298,7 @@ void SmoothNormals(){ } /* print time */ - Sys_Printf( " (%i)\n", (int) ( I_FloatTime() - start ) ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); } diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index 7f8a3632..28d1cb42 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -32,6 +32,7 @@ #include "q3map2.h" #include "bspfile_rbsp.h" #include "surface_extra.h" +#include "timer.h" @@ -1190,7 +1191,7 @@ void SetupSurfaceLightmaps(){ void StitchSurfaceLightmaps(){ int i, j, x, y, x2, y2, - numStitched, numCandidates, numLuxels, f, fOld, start; + numStitched, numCandidates, numLuxels, fOld; rawLightmap_t *lm, *a, *b, *c[ MAX_STITCH_CANDIDATES ]; float sampleSize, totalColor; @@ -1203,15 +1204,14 @@ void StitchSurfaceLightmaps(){ /* init pacifier */ fOld = -1; - start = I_FloatTime(); + Timer timer; /* walk the list of raw lightmaps */ numStitched = 0; for ( i = 0; i < numRawLightmaps; i++ ) { /* print pacifier */ - f = 10 * i / numRawLightmaps; - if ( f != fOld ) { + if ( const int f = 10 * i / numRawLightmaps; f != fOld ) { fOld = f; Sys_Printf( "%i...", f ); } @@ -1328,7 +1328,7 @@ void StitchSurfaceLightmaps(){ } /* emit statistics */ - Sys_Printf( " (%i)\n", (int) ( I_FloatTime() - start ) ); + Sys_Printf( " (%i)\n", int( timer.elapsed_sec() ) ); Sys_FPrintf( SYS_VRB, "%9d luxels stitched\n", numStitched ); } @@ -2337,7 +2337,7 @@ static void FillOutLightmap( outLightmap_t *olm ){ */ void StoreSurfaceLightmaps( bool fastAllocate ){ - int i, j, k, x, y, lx, ly, sx, sy, mappedSamples, timer_start; + int i, j, k, x, y, lx, ly, sx, sy, mappedSamples; int style, lightmapNum, lightmapNum2; float samples, occludedSamples; Vector3 sample, occludedSample, dirSample; @@ -2376,7 +2376,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ Sys_Printf( "Subsampling..." ); - timer_start = I_FloatTime(); + Timer timer; /* walk the list of raw lightmaps */ numUsed = 0; @@ -2693,7 +2693,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ } } - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); /* ----------------------------------------------------------------- convert modelspace deluxemaps to tangentspace @@ -2701,7 +2701,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ if ( !bouncing ) { if ( deluxemap && deluxemode == 1 ) { - timer_start = I_FloatTime(); + timer.start(); Sys_Printf( "converting..." ); @@ -2763,7 +2763,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ } } - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); } } @@ -2820,7 +2820,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ Sys_Printf( "collapsing..." ); - timer_start = I_FloatTime(); + timer.start(); /* set all twin refs to null */ for ( i = 0; i < numRawLightmaps; i++ ) @@ -2883,7 +2883,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ } } - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); } /* ----------------------------------------------------------------- @@ -2893,7 +2893,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ Sys_Printf( "sorting..." ); - timer_start = I_FloatTime(); + timer.start(); /* allocate a new sorted list */ if ( sortLightmaps == NULL ) { @@ -2905,7 +2905,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ sortLightmaps[ i ] = i; std::sort( sortLightmaps, sortLightmaps + numRawLightmaps, CompareRawLightmap() ); - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); /* ----------------------------------------------------------------- allocate output lightmaps @@ -2914,7 +2914,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ Sys_Printf( "allocating..." ); - timer_start = I_FloatTime(); + timer.start(); /* kill all existing output lightmaps */ if ( outLightmaps != NULL ) { @@ -2962,7 +2962,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ } } - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); /* ----------------------------------------------------------------- store output lightmaps @@ -2971,7 +2971,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ Sys_Printf( "storing..." ); - timer_start = I_FloatTime(); + timer.start(); /* count the bsp lightmaps and allocate space */ const size_t gameLmSize = g_game->lightmapSize * g_game->lightmapSize * sizeof( Vector3b ); @@ -3059,7 +3059,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ remove( filename ); } - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); /* ----------------------------------------------------------------- project the lightmaps onto the bsp surfaces @@ -3068,7 +3068,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ /* note it */ Sys_Printf( "projecting..." ); - timer_start = I_FloatTime(); + timer.start(); /* walk the list of surfaces */ for ( size_t i = 0; i < bspDrawSurfaces.size(); ++i ) @@ -3343,7 +3343,7 @@ void StoreSurfaceLightmaps( bool fastAllocate ){ } } - Sys_Printf( "%d.", (int) ( I_FloatTime() - timer_start ) ); + Sys_Printf( "%d.", int( timer.elapsed_sec() ) ); /* finish */ Sys_Printf( "done.\n" ); diff --git a/tools/quake3/q3map2/main.cpp b/tools/quake3/q3map2/main.cpp index b8e97215..e1274711 100644 --- a/tools/quake3/q3map2/main.cpp +++ b/tools/quake3/q3map2/main.cpp @@ -31,6 +31,7 @@ /* dependencies */ #include "q3map2.h" #include "autopk3.h" +#include "timer.h" @@ -67,7 +68,7 @@ int main( int argc, char **argv ){ srand( 0 ); /* start timer */ - const double start = I_FloatTime(); + Timer timer; /* this was changed to emit version number over the network */ printf( Q3MAP_VERSION "\n" ); @@ -228,7 +229,7 @@ int main( int argc, char **argv ){ } /* emit time */ - Sys_Printf( "%9.0f seconds elapsed\n", I_FloatTime() - start ); + Sys_Printf( "%9.0f seconds elapsed\n", timer.elapsed_sec() ); /* return any error code */ return r; diff --git a/tools/quake3/q3map2/surface_meta.cpp b/tools/quake3/q3map2/surface_meta.cpp index 115bacee..448dc6ec 100644 --- a/tools/quake3/q3map2/surface_meta.cpp +++ b/tools/quake3/q3map2/surface_meta.cpp @@ -30,6 +30,7 @@ /* dependencies */ #include "q3map2.h" +#include "timer.h" #include #include @@ -860,7 +861,7 @@ void MakeEntityMetaTriangles( entity_t *e ){ /* init pacifier */ int fOld = -1; - const int start = I_FloatTime(); + Timer timer; /* walk the list of surfaces in the entity */ for ( int i = e->firstDrawSurf; i < numMapDrawSurfs; ++i ) @@ -920,7 +921,7 @@ void MakeEntityMetaTriangles( entity_t *e ){ /* print time */ if ( ( numMapDrawSurfs - e->firstDrawSurf ) ) { - Sys_FPrintf( SYS_VRB, " (%d)\n", (int) ( I_FloatTime() - start ) ); + Sys_FPrintf( SYS_VRB, " (%d)\n", int( timer.elapsed_sec() ) ); } /* emit some stats */ @@ -984,7 +985,7 @@ static void CreateEdge( const Plane3f& plane, const Vector3& a, const Vector3& b void FixMetaTJunctions(){ #if 0 - int i, j, k, f, fOld, start, vertIndex, triIndex, numTJuncs; + int i, j, k, fOld, vertIndex, triIndex, numTJuncs; metaTriangle_t *tri, *newTri; shaderInfo_t *si; bspDrawVert_t *a, *b, *c, junc; @@ -1001,7 +1002,7 @@ void FixMetaTJunctions(){ /* init pacifier */ fOld = -1; - start = I_FloatTime(); + Timer timer; /* walk triangle list */ numTJuncs = 0; @@ -1011,8 +1012,7 @@ void FixMetaTJunctions(){ tri = &metaTriangles[ i ]; /* print pacifier */ - f = 10 * i / numMetaTriangles; - if ( f != fOld ) { + if ( const int f = 10 * i / numMetaTriangles; f != fOld ) { fOld = f; Sys_FPrintf( SYS_VRB, "%d...", f ); } @@ -1139,7 +1139,7 @@ void FixMetaTJunctions(){ } /* print time */ - Sys_FPrintf( SYS_VRB, " (%d)\n", (int) ( I_FloatTime() - start ) ); + Sys_FPrintf( SYS_VRB, " (%d)\n", int( timer.elapsed_sec() ) ); /* emit some stats */ Sys_FPrintf( SYS_VRB, "%9d T-junctions added\n", numTJuncs ); @@ -1157,7 +1157,7 @@ void FixMetaTJunctions(){ #define EQUAL_NORMAL_EPSILON 0.01f void SmoothMetaTriangles(){ - const double start = I_FloatTime(); + Timer timer; int numSmoothed = 0; /* note it */ @@ -1265,7 +1265,7 @@ void SmoothMetaTriangles(){ } /* print time */ - Sys_FPrintf( SYS_VRB, " (%d)\n", (int) ( I_FloatTime() - start ) ); + Sys_FPrintf( SYS_VRB, " (%d)\n", int( timer.elapsed_sec() ) ); /* emit some stats */ Sys_FPrintf( SYS_VRB, "%9d smoothed vertexes\n", numSmoothed ); @@ -1674,7 +1674,7 @@ void MergeMetaTriangles(){ /* init pacifier */ int fOld = -1; - int start = I_FloatTime(); + Timer timer; int numAdded = 0; #if 1 for( metaTriangle_t& tri : metaTriangles ){ @@ -1690,7 +1690,7 @@ void MergeMetaTriangles(){ ClearMetaTriangles(); /* print time */ - Sys_FPrintf( SYS_VRB, " (%d)\n", (int) ( I_FloatTime() - start ) ); + Sys_FPrintf( SYS_VRB, " (%d)\n", int( timer.elapsed_sec() ) ); /* emit some stats */ Sys_FPrintf( SYS_VRB, "%9d surfaces merged\n", numMergedSurfaces );