mirror of
https://github.com/dhewm/dhewm3-sdk.git
synced 2024-11-24 21:41:23 +00:00
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.
This commit is contained in:
parent
d26cf44a29
commit
79ad74d779
12 changed files with 34 additions and 81 deletions
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue