From 79ad74d779561764e942ebe35569da0c56426f25 Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 21 Dec 2011 16:51:54 +0100 Subject: [PATCH] Use idSys::GetMilliseconds() for idTimer The class is only used for debugging and statistical purposes. The precision is now reduced to milliseconds, but that's only relevant for fine grained debug timings - where the old code was inaccurate at anyway. --- d3xp/Game_local.cpp | 4 +-- d3xp/Pvs.cpp | 2 +- d3xp/physics/Physics_AF.cpp | 4 +-- d3xp/physics/Physics_RigidBody.cpp | 4 +-- d3xp/script/Script_Compiler.cpp | 2 +- game/Game_local.cpp | 2 +- game/Pvs.cpp | 2 +- game/physics/Physics_AF.cpp | 4 +-- game/physics/Physics_RigidBody.cpp | 4 +-- game/script/Script_Compiler.cpp | 2 +- idlib/Timer.cpp | 33 ++----------------- idlib/Timer.h | 52 +++++++++--------------------- 12 files changed, 34 insertions(+), 81 deletions(-) diff --git a/d3xp/Game_local.cpp b/d3xp/Game_local.cpp index 0ad8441..091d128 100644 --- a/d3xp/Game_local.cpp +++ b/d3xp/Game_local.cpp @@ -2521,7 +2521,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) { timer_singlethink.Stop(); ms = timer_singlethink.Milliseconds(); if ( ms >= g_timeentities.GetFloat() ) { - Printf( "%d: entity '%s': %.1f ms\n", time, ent->name.c_str(), ms ); + Printf( "%d: entity '%s': %f ms\n", time, ent->name.c_str(), ms ); } num++; } @@ -2595,7 +2595,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) { // display how long it took to calculate the current game frame if ( g_frametime.GetBool() ) { - Printf( "game %d: all:%.1f th:%.1f ev:%.1f %d ents \n", + Printf( "game %d: all:%u th:%u ev:%u %d ents \n", time, timer_think.Milliseconds() + timer_events.Milliseconds(), timer_think.Milliseconds(), timer_events.Milliseconds(), num ); } diff --git a/d3xp/Pvs.cpp b/d3xp/Pvs.cpp index 7aabc78..61e1fa1 100644 --- a/d3xp/Pvs.cpp +++ b/d3xp/Pvs.cpp @@ -842,7 +842,7 @@ void idPVS::Init( void ) { timer.Stop(); - gameLocal.Printf( "%5.0f msec to calculate PVS\n", timer.Milliseconds() ); + gameLocal.Printf( "%5u msec to calculate PVS\n", timer.Milliseconds() ); gameLocal.Printf( "%5d areas\n", numAreas ); gameLocal.Printf( "%5d portals\n", numPortals ); gameLocal.Printf( "%5d areas visible on average\n", totalVisibleAreas / numAreas ); diff --git a/d3xp/physics/Physics_AF.cpp b/d3xp/physics/Physics_AF.cpp index 965d95e..23e8c46 100644 --- a/d3xp/physics/Physics_AF.cpp +++ b/d3xp/physics/Physics_AF.cpp @@ -6382,7 +6382,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) { timer_total.Stop(); if ( af_showTimings.GetInteger() == 1 ) { - gameLocal.Printf( "%12s: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", + gameLocal.Printf( "%12s: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n", self->name.c_str(), timer_total.Milliseconds(), numPrimary, timer_pc.Milliseconds(), @@ -6392,7 +6392,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) { else if ( af_showTimings.GetInteger() == 2 ) { numArticulatedFigures++; if ( endTimeMSec > lastTimerReset ) { - gameLocal.Printf( "af %d: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", + gameLocal.Printf( "af %d: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n", numArticulatedFigures, timer_total.Milliseconds(), numPrimary, timer_pc.Milliseconds(), diff --git a/d3xp/physics/Physics_RigidBody.cpp b/d3xp/physics/Physics_RigidBody.cpp index 8d0436f..2bd77cc 100644 --- a/d3xp/physics/Physics_RigidBody.cpp +++ b/d3xp/physics/Physics_RigidBody.cpp @@ -977,7 +977,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) { timer_total.Stop(); if ( rb_showTimings->integer == 1 ) { - gameLocal.Printf( "%12s: t %1.4f cd %1.4f\n", + gameLocal.Printf( "%12s: t %u cd %u\n", self->name.c_str(), timer_total.Milliseconds(), timer_collision.Milliseconds() ); lastTimerReset = 0; @@ -985,7 +985,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) { else if ( rb_showTimings->integer == 2 ) { numRigidBodies++; if ( endTimeMSec > lastTimerReset ) { - gameLocal.Printf( "rb %d: t %1.4f cd %1.4f\n", + gameLocal.Printf( "rb %d: t %u cd %u\n", numRigidBodies, timer_total.Milliseconds(), timer_collision.Milliseconds() ); } diff --git a/d3xp/script/Script_Compiler.cpp b/d3xp/script/Script_Compiler.cpp index abb35e3..7620c60 100644 --- a/d3xp/script/Script_Compiler.cpp +++ b/d3xp/script/Script_Compiler.cpp @@ -2644,6 +2644,6 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon compile_time.Stop(); if ( !toConsole ) { - gameLocal.Printf( "Compiled '%s': %.1f ms\n", filename, compile_time.Milliseconds() ); + gameLocal.Printf( "Compiled '%s': %u ms\n", filename, compile_time.Milliseconds() ); } } diff --git a/game/Game_local.cpp b/game/Game_local.cpp index 011d06c..2a67abc 100644 --- a/game/Game_local.cpp +++ b/game/Game_local.cpp @@ -2330,7 +2330,7 @@ gameReturn_t idGameLocal::RunFrame( const usercmd_t *clientCmds ) { // display how long it took to calculate the current game frame if ( g_frametime.GetBool() ) { - Printf( "game %d: all:%.1f th:%.1f ev:%.1f %d ents \n", + Printf( "game %d: all:%u th:%u ev:%u %d ents \n", time, timer_think.Milliseconds() + timer_events.Milliseconds(), timer_think.Milliseconds(), timer_events.Milliseconds(), num ); } diff --git a/game/Pvs.cpp b/game/Pvs.cpp index e76c86d..c86fe87 100644 --- a/game/Pvs.cpp +++ b/game/Pvs.cpp @@ -842,7 +842,7 @@ void idPVS::Init( void ) { timer.Stop(); - gameLocal.Printf( "%5.0f msec to calculate PVS\n", timer.Milliseconds() ); + gameLocal.Printf( "%5u msec to calculate PVS\n", timer.Milliseconds() ); gameLocal.Printf( "%5d areas\n", numAreas ); gameLocal.Printf( "%5d portals\n", numPortals ); gameLocal.Printf( "%5d areas visible on average\n", totalVisibleAreas / numAreas ); diff --git a/game/physics/Physics_AF.cpp b/game/physics/Physics_AF.cpp index 4c1a559..e416a58 100644 --- a/game/physics/Physics_AF.cpp +++ b/game/physics/Physics_AF.cpp @@ -6381,7 +6381,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) { timer_total.Stop(); if ( af_showTimings.GetInteger() == 1 ) { - gameLocal.Printf( "%12s: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", + gameLocal.Printf( "%12s: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n", self->name.c_str(), timer_total.Milliseconds(), numPrimary, timer_pc.Milliseconds(), @@ -6391,7 +6391,7 @@ bool idPhysics_AF::Evaluate( int timeStepMSec, int endTimeMSec ) { else if ( af_showTimings.GetInteger() == 2 ) { numArticulatedFigures++; if ( endTimeMSec > lastTimerReset ) { - gameLocal.Printf( "af %d: t %1.4f pc %2d, %1.4f ac %2d %1.4f lcp %1.4f cd %1.4f\n", + gameLocal.Printf( "af %d: t %u pc %2d, %u ac %2d %u lcp %u cd %u\n", numArticulatedFigures, timer_total.Milliseconds(), numPrimary, timer_pc.Milliseconds(), diff --git a/game/physics/Physics_RigidBody.cpp b/game/physics/Physics_RigidBody.cpp index 8d0436f..2bd77cc 100644 --- a/game/physics/Physics_RigidBody.cpp +++ b/game/physics/Physics_RigidBody.cpp @@ -977,7 +977,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) { timer_total.Stop(); if ( rb_showTimings->integer == 1 ) { - gameLocal.Printf( "%12s: t %1.4f cd %1.4f\n", + gameLocal.Printf( "%12s: t %u cd %u\n", self->name.c_str(), timer_total.Milliseconds(), timer_collision.Milliseconds() ); lastTimerReset = 0; @@ -985,7 +985,7 @@ bool idPhysics_RigidBody::Evaluate( int timeStepMSec, int endTimeMSec ) { else if ( rb_showTimings->integer == 2 ) { numRigidBodies++; if ( endTimeMSec > lastTimerReset ) { - gameLocal.Printf( "rb %d: t %1.4f cd %1.4f\n", + gameLocal.Printf( "rb %d: t %u cd %u\n", numRigidBodies, timer_total.Milliseconds(), timer_collision.Milliseconds() ); } diff --git a/game/script/Script_Compiler.cpp b/game/script/Script_Compiler.cpp index d698be2..1757233 100644 --- a/game/script/Script_Compiler.cpp +++ b/game/script/Script_Compiler.cpp @@ -2644,6 +2644,6 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon compile_time.Stop(); if ( !toConsole ) { - gameLocal.Printf( "Compiled '%s': %.1f ms\n", filename, compile_time.Milliseconds() ); + gameLocal.Printf( "Compiled '%s': %u ms\n", filename, compile_time.Milliseconds() ); } } diff --git a/idlib/Timer.cpp b/idlib/Timer.cpp index 55bc298..47fa407 100644 --- a/idlib/Timer.cpp +++ b/idlib/Timer.cpp @@ -32,33 +32,6 @@ If you have questions concerning this license or the applicable additional terms #include "idlib/Timer.h" -double idTimer::base = -1.0; - -/* -================= -idTimer::InitBaseClockTicks -================= -*/ -void idTimer::InitBaseClockTicks( void ) const { - idTimer timer; - double ct, b; - int i; - - base = 0.0; - b = -1.0; - for ( i = 0; i < 1000; i++ ) { - timer.Clear(); - timer.Start(); - timer.Stop(); - ct = timer.ClockTicks(); - if ( b < 0.0 || ct < b ) { - b = ct; - } - } - base = b; -} - - /* ================= idTimerReport::idTimerReport @@ -153,10 +126,10 @@ void idTimerReport::PrintReport() { assert( timers.Num() == names.Num() ); idLib::common->Printf( "Timing Report for %s\n", reportName.c_str() ); idLib::common->Printf( "-------------------------------\n" ); - float total = 0.0f; + unsigned int total = 0; for ( int i = 0; i < names.Num(); i++ ) { - idLib::common->Printf( "%s consumed %5.2f seconds\n", names[i].c_str(), timers[i]->Milliseconds() * 0.001f ); + idLib::common->Printf( "%s consumed %5.2f seconds\n", names[i].c_str(), 0.001f * timers[i]->Milliseconds() ); total += timers[i]->Milliseconds(); } - idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), total * 0.001f ); + idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), 0.001f * total ); } diff --git a/idlib/Timer.h b/idlib/Timer.h index 24c5b1c..8bae274 100644 --- a/idlib/Timer.h +++ b/idlib/Timer.h @@ -44,7 +44,7 @@ If you have questions concerning this license or the applicable additional terms class idTimer { public: idTimer( void ); - idTimer( double clockTicks ); + idTimer( unsigned int ms ); ~idTimer( void ); idTimer operator+( const idTimer &t ) const; @@ -55,19 +55,15 @@ public: void Start( void ); void Stop( void ); void Clear( void ); - double ClockTicks( void ) const; - double Milliseconds( void ) const; + unsigned int Milliseconds( void ) const; private: - static double base; enum { TS_STARTED, TS_STOPPED } state; - double start; - double clockTicks; - - void InitBaseClockTicks( void ) const; + unsigned int start; + unsigned int ms; }; /* @@ -77,7 +73,7 @@ idTimer::idTimer */ ID_INLINE idTimer::idTimer( void ) { state = TS_STOPPED; - clockTicks = 0.0; + ms = 0; } /* @@ -85,9 +81,9 @@ ID_INLINE idTimer::idTimer( void ) { idTimer::idTimer ================= */ -ID_INLINE idTimer::idTimer( double _clockTicks ) { +ID_INLINE idTimer::idTimer( unsigned int _ms ) { state = TS_STOPPED; - clockTicks = _clockTicks; + ms = _ms; } /* @@ -105,7 +101,7 @@ idTimer::operator+ */ ID_INLINE idTimer idTimer::operator+( const idTimer &t ) const { assert( state == TS_STOPPED && t.state == TS_STOPPED ); - return idTimer( clockTicks + t.clockTicks ); + return idTimer( ms + t.ms ); } /* @@ -115,7 +111,7 @@ idTimer::operator- */ ID_INLINE idTimer idTimer::operator-( const idTimer &t ) const { assert( state == TS_STOPPED && t.state == TS_STOPPED ); - return idTimer( clockTicks - t.clockTicks ); + return idTimer( ms - t.ms ); } /* @@ -125,7 +121,7 @@ idTimer::operator+= */ ID_INLINE idTimer &idTimer::operator+=( const idTimer &t ) { assert( state == TS_STOPPED && t.state == TS_STOPPED ); - clockTicks += t.clockTicks; + ms += t.ms; return *this; } @@ -136,7 +132,7 @@ idTimer::operator-= */ ID_INLINE idTimer &idTimer::operator-=( const idTimer &t ) { assert( state == TS_STOPPED && t.state == TS_STOPPED ); - clockTicks -= t.clockTicks; + ms -= t.ms; return *this; } @@ -148,7 +144,7 @@ idTimer::Start ID_INLINE void idTimer::Start( void ) { assert( state == TS_STOPPED ); state = TS_STARTED; - start = idLib::sys->GetClockTicks(); + start = idLib::sys->GetMilliseconds(); } /* @@ -158,13 +154,7 @@ idTimer::Stop */ ID_INLINE void idTimer::Stop( void ) { assert( state == TS_STARTED ); - clockTicks += idLib::sys->GetClockTicks() - start; - if ( base < 0.0 ) { - InitBaseClockTicks(); - } - if ( clockTicks > base ) { - clockTicks -= base; - } + ms += idLib::sys->GetMilliseconds() - start; state = TS_STOPPED; } @@ -174,17 +164,7 @@ idTimer::Clear ================= */ ID_INLINE void idTimer::Clear( void ) { - clockTicks = 0.0; -} - -/* -================= -idTimer::ClockTicks -================= -*/ -ID_INLINE double idTimer::ClockTicks( void ) const { - assert( state == TS_STOPPED ); - return clockTicks; + ms = 0; } /* @@ -192,9 +172,9 @@ ID_INLINE double idTimer::ClockTicks( void ) const { idTimer::Milliseconds ================= */ -ID_INLINE double idTimer::Milliseconds( void ) const { +ID_INLINE unsigned int idTimer::Milliseconds( void ) const { assert( state == TS_STOPPED ); - return clockTicks / ( idLib::sys->ClockTicksPerSecond() * 0.001 ); + return ms; }