diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cgame/cg_draw.c | 60 | ||||
-rw-r--r-- | src/cgame/cg_local.h | 1 | ||||
-rw-r--r-- | src/cgame/cg_main.c | 2 |
3 files changed, 46 insertions, 17 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 690df742..5f966f0f 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -2268,14 +2268,17 @@ static void CG_DrawLagometer( rectDef_t *rect, float text_x, float text_y, CG_DrawDisconnect( ); } -#define SPEEDOMETER_NUM_SAMPLES 160 +#define SPEEDOMETER_NUM_SAMPLES 4096 +#define SPEEDOMETER_NUM_DISPLAYED_SAMPLES 160 #define SPEEDOMETER_DRAW_TEXT 0x1 #define SPEEDOMETER_DRAW_GRAPH 0x2 #define SPEEDOMETER_IGNORE_Z 0x4 float speedSamples[ SPEEDOMETER_NUM_SAMPLES ]; +int speedSampleTimes[ SPEEDOMETER_NUM_SAMPLES ]; // array indices int oldestSpeedSample = 0; int maxSpeedSample = 0; +int maxSpeedSampleInWindow = 0; /* =================== @@ -2288,6 +2291,8 @@ void CG_AddSpeed( void ) { float speed; vec3_t vel; + int windowTime; + qboolean newSpeedGteMaxSpeed, newSpeedGteMaxSpeedInWindow; VectorCopy( cg.snap->ps.velocity, vel ); @@ -2296,16 +2301,22 @@ void CG_AddSpeed( void ) speed = VectorLength( vel ); - if( speed > speedSamples[ maxSpeedSample ] ) - { + windowTime = cg_maxSpeedTimeWindow.integer; + if( windowTime < 0 ) + windowTime = 0; + else if( windowTime > SPEEDOMETER_NUM_SAMPLES * 1000 ) + windowTime = SPEEDOMETER_NUM_SAMPLES * 1000; + + if( ( newSpeedGteMaxSpeed = ( speed >= speedSamples[ maxSpeedSample ] ) ) ) maxSpeedSample = oldestSpeedSample; - speedSamples[ oldestSpeedSample++ ] = speed; - oldestSpeedSample %= SPEEDOMETER_NUM_SAMPLES; - return; - } + + if( ( newSpeedGteMaxSpeedInWindow = ( speed >= speedSamples[ maxSpeedSampleInWindow ] ) ) ) + maxSpeedSampleInWindow = oldestSpeedSample; speedSamples[ oldestSpeedSample ] = speed; - if( maxSpeedSample == oldestSpeedSample++ ) + speedSampleTimes[ oldestSpeedSample ] = cg.time; + + if( !newSpeedGteMaxSpeed && maxSpeedSample == oldestSpeedSample ) { // if old max was overwritten find a new one int i; @@ -2316,7 +2327,23 @@ void CG_AddSpeed( void ) } } - oldestSpeedSample %= SPEEDOMETER_NUM_SAMPLES; + if( !newSpeedGteMaxSpeedInWindow && ( maxSpeedSampleInWindow == oldestSpeedSample || + cg.time - speedSampleTimes[ maxSpeedSampleInWindow ] > windowTime ) ) + { + int i; + do { + maxSpeedSampleInWindow = ( maxSpeedSampleInWindow + 1 ) % SPEEDOMETER_NUM_SAMPLES; + } while( cg.time - speedSampleTimes[ maxSpeedSampleInWindow ] > windowTime ); + for( i = maxSpeedSampleInWindow; ; i = ( i + 1 ) % SPEEDOMETER_NUM_SAMPLES ) + { + if( speedSamples[ i ] > speedSamples[ maxSpeedSampleInWindow ] ) + maxSpeedSampleInWindow = i; + if( i == oldestSpeedSample ) + break; + } + } + + oldestSpeedSample = ( oldestSpeedSample + 1 ) % SPEEDOMETER_NUM_SAMPLES; } #define SPEEDOMETER_MIN_RANGE 900 @@ -2348,9 +2375,10 @@ static void CG_DrawSpeedGraph( rectDef_t *rect, vec4_t foreColor, Vector4Copy( foreColor, color ); - for( i = 1; i < SPEEDOMETER_NUM_SAMPLES; i++ ) + for( i = 1; i < SPEEDOMETER_NUM_DISPLAYED_SAMPLES; i++ ) { - val = speedSamples[ ( oldestSpeedSample + i ) % SPEEDOMETER_NUM_SAMPLES ]; + val = speedSamples[ ( oldestSpeedSample + i + SPEEDOMETER_NUM_SAMPLES - + SPEEDOMETER_NUM_DISPLAYED_SAMPLES ) % SPEEDOMETER_NUM_SAMPLES ]; if( val < SPEED_MED ) VectorLerp2( val / SPEED_MED, slow, medium, color ); else if( val < SPEED_FAST ) @@ -2360,8 +2388,8 @@ static void CG_DrawSpeedGraph( rectDef_t *rect, vec4_t foreColor, VectorCopy( fast, color ); trap_R_SetColor( color ); top = rect->y + ( 1 - val / max ) * rect->h; - CG_DrawPic( rect->x + ( i / (float)SPEEDOMETER_NUM_SAMPLES ) * rect->w, top, - rect->w / (float)SPEEDOMETER_NUM_SAMPLES, val * rect->h / max, + CG_DrawPic( rect->x + ( i / (float)SPEEDOMETER_NUM_DISPLAYED_SAMPLES ) * rect->w, top, + rect->w / (float)SPEEDOMETER_NUM_DISPLAYED_SAMPLES, val * rect->h / max, cgs.media.whiteShader ); } trap_R_SetColor( NULL ); @@ -2389,12 +2417,10 @@ static void CG_DrawSpeedText( rectDef_t *rect, float text_x, float text_y, vel[ 2 ] = 0; val = VectorLength( vel ); } - else if( oldestSpeedSample == 0 ) - val = speedSamples[ SPEEDOMETER_NUM_SAMPLES - 1 ]; else - val = speedSamples[ oldestSpeedSample - 1 ]; + val = speedSamples[ ( oldestSpeedSample - 1 + SPEEDOMETER_NUM_SAMPLES ) % SPEEDOMETER_NUM_SAMPLES ]; - Com_sprintf( speedstr, sizeof( speedstr ), "%d", (int)val ); + Com_sprintf( speedstr, sizeof( speedstr ), "%d / %d", (int)val, (int)speedSamples[ maxSpeedSampleInWindow ] ); UI_Text_Paint( rect->x + ( rect->w - UI_Text_Width( speedstr, scale ) ) / 2.0f, diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 5e4fde09..ab160784 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -1523,6 +1523,7 @@ extern vmCvar_t cg_thirdPersonRange; extern vmCvar_t cg_stereoSeparation; extern vmCvar_t cg_lagometer; extern vmCvar_t cg_drawSpeed; +extern vmCvar_t cg_maxSpeedTimeWindow; extern vmCvar_t cg_synchronousClients; extern vmCvar_t cg_stats; extern vmCvar_t cg_paused; diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 99d267ee..0adcb549 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -151,6 +151,7 @@ vmCvar_t cg_thirdPersonRange; vmCvar_t cg_stereoSeparation; vmCvar_t cg_lagometer; vmCvar_t cg_drawSpeed; +vmCvar_t cg_maxSpeedTimeWindow; vmCvar_t cg_synchronousClients; vmCvar_t cg_stats; vmCvar_t cg_paused; @@ -259,6 +260,7 @@ static cvarTable_t cvarTable[ ] = { &cg_addMarks, "cg_marks", "1", CVAR_ARCHIVE }, { &cg_lagometer, "cg_lagometer", "0", CVAR_ARCHIVE }, { &cg_drawSpeed, "cg_drawSpeed", "0", CVAR_ARCHIVE }, + { &cg_maxSpeedTimeWindow, "cg_maxSpeedTimeWindow", "2000", CVAR_ARCHIVE }, { &cg_teslaTrailTime, "cg_teslaTrailTime", "250", CVAR_ARCHIVE }, { &cg_gun_x, "cg_gunX", "0", CVAR_CHEAT }, { &cg_gun_y, "cg_gunY", "0", CVAR_CHEAT }, |