Skip to content

Commit 5975ed5

Browse files
committed
timer show start speed
1 parent d5b9594 commit 5975ed5

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

codemp/cgame/cg_draw.c

+38-25
Original file line numberDiff line numberDiff line change
@@ -11169,42 +11169,55 @@ static void CG_CalculateSpeed(centity_t *cent) {
1116911169

1117011170
static void CG_RaceTimer(void)
1117111171
{
11172-
char timerStr[32] = { 0 };
11173-
int time, minutes, seconds, milliseconds;
11174-
11175-
if (!cg.predictedPlayerState.stats[STAT_RACEMODE])
11176-
return;
11177-
if (!cg.predictedPlayerState.duelTime)
11172+
if (!cg.predictedPlayerState.stats[STAT_RACEMODE] || !cg.predictedPlayerState.duelTime) {
11173+
cg.startSpeed = 0;
11174+
cg.displacement = 0;
11175+
cg.maxSpeed = 0;
11176+
cg.displacementSamples = 0;
1117811177
return;
11178+
}
1117911179

11180-
time = (cg.time - cg.predictedPlayerState.duelTime);
11181-
minutes = (time / 1000) / 60;
11182-
seconds = (time / 1000) % 60;
11183-
milliseconds = (time % 1000);
11180+
{
11181+
char timerStr[48] = { 0 };
11182+
const int time = (cg.time - cg.predictedPlayerState.duelTime);
11183+
const int minutes = (time / 1000) / 60;
11184+
const int seconds = (time / 1000) % 60;
11185+
const int milliseconds = (time % 1000);
1118411186

11185-
if (cg_raceTimer.integer > 1) {
11186-
if (time < 1000) {
11187+
if (time < cg.lastRaceTime) {
11188+
cg.startSpeed = 0;
1118711189
cg.displacement = 0;
1118811190
cg.maxSpeed = 0;
1118911191
cg.displacementSamples = 0;
1119011192
}
11191-
else {
11192-
if (cg.currentSpeed > cg.maxSpeed)
11193-
cg.maxSpeed = cg.currentSpeed;
11194-
cg.displacement += cg.currentSpeed;
11195-
cg.displacementSamples++;
11193+
11194+
if (cg_raceTimer.integer > 1) {
11195+
if (time > 0) {
11196+
if (!cg.startSpeed)
11197+
cg.startSpeed = (int)(cg.currentSpeed + 0.5f);
11198+
11199+
if (cg.currentSpeed > cg.maxSpeed)
11200+
cg.maxSpeed = (int)(cg.currentSpeed + 0.5f);
11201+
cg.displacement += cg.currentSpeed;
11202+
cg.displacementSamples++;
11203+
}
1119611204
}
11197-
}
1119811205

11199-
if (cg_raceTimer.integer < 3)
11200-
Com_sprintf(timerStr, sizeof(timerStr), "%i:%02i.%i\n", minutes, seconds, milliseconds / 100);
11201-
else
11202-
Com_sprintf(timerStr, sizeof(timerStr), "%i:%02i.%03i\n", minutes, seconds, milliseconds);
11206+
cg.lastRaceTime = time;
1120311207

11204-
if (cg_raceTimer.integer > 1 && cg.displacementSamples)
11205-
Q_strcat(timerStr, sizeof(timerStr), va("Max: %i\nAvg: %i", (int)floorf(cg.maxSpeed + 0.5f), cg.displacement / cg.displacementSamples));
11208+
if (cg_raceTimer.integer < 3)
11209+
Com_sprintf(timerStr, sizeof(timerStr), "%i:%02i.%i\n", minutes, seconds, milliseconds / 100);
11210+
else
11211+
Com_sprintf(timerStr, sizeof(timerStr), "%i:%02i.%03i\n", minutes, seconds, milliseconds);
1120611212

11207-
CG_Text_Paint(cg_raceTimerX.integer, cg_raceTimerY.integer, cg_raceTimerSize.value, colorTable[CT_WHITE], timerStr, 0.0f, 0, ITEM_ALIGN_RIGHT | ITEM_TEXTSTYLE_OUTLINED, FONT_NONE);
11213+
if (cg_raceTimer.integer > 1 && cg.displacementSamples)
11214+
Q_strcat(timerStr, sizeof(timerStr), va("Max: %i\nAvg: %i", (int)(cg.maxSpeed + 0.5f), cg.displacement / cg.displacementSamples));
11215+
11216+
if (time < 3000)
11217+
Q_strcat(timerStr, sizeof(timerStr), va("\nStart: %i", cg.startSpeed));
11218+
11219+
CG_Text_Paint(cg_raceTimerX.integer, cg_raceTimerY.integer, cg_raceTimerSize.value, colorTable[CT_WHITE], timerStr, 0.0f, 0, ITEM_ALIGN_RIGHT | ITEM_TEXTSTYLE_OUTLINED, FONT_NONE);
11220+
}
1120811221
}
1120911222

1121011223
#define ACCEL_SAMPLES 16

codemp/cgame/cg_local.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,10 @@ Ghoul2 Insert End
13451345
qboolean recording;
13461346
unsigned int displacement;
13471347
unsigned int displacementSamples;
1348-
float maxSpeed;
1348+
int maxSpeed;
1349+
int lastRaceTime;
13491350
float currentSpeed;
1351+
int startSpeed;
13501352
float previousSpeed;
13511353
float lastJumpDistance;
13521354
int lastJumpDistanceTime;

codemp/cgame/cg_snapshot.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static void CheckTouchingCheckpoint(clientCheckpoint_t clientCheckpoint) {
520520
time = 0.001f;
521521

522522
if (cg.displacementSamples)
523-
CG_CenterPrint(va("^2%.3fs^4, avg ^2%i^4u, max ^2%.0f^4u\n\n\n\n\n\n\n\n\n\n", time, cg.displacement/cg.displacementSamples, cg.maxSpeed), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH);
523+
CG_CenterPrint(va("^2%.3fs^4, avg ^2%i^4u, max ^2%i^4u\n\n\n\n\n\n\n\n\n\n", time, cg.displacement/cg.displacementSamples, cg.maxSpeed), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH);
524524
else
525525
CG_CenterPrint( va("^2%.3fs^4\n\n\n\n\n\n\n\n\n\n", time), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
526526
cg.lastCheckPointPrintTime = cg.time;

0 commit comments

Comments
 (0)