Skip to content

Commit

Permalink
timer show start speed
Browse files Browse the repository at this point in the history
  • Loading branch information
videoP committed Oct 11, 2018
1 parent d5b9594 commit 5975ed5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
63 changes: 38 additions & 25 deletions codemp/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -11169,42 +11169,55 @@ static void CG_CalculateSpeed(centity_t *cent) {

static void CG_RaceTimer(void)
{
char timerStr[32] = { 0 };
int time, minutes, seconds, milliseconds;

if (!cg.predictedPlayerState.stats[STAT_RACEMODE])
return;
if (!cg.predictedPlayerState.duelTime)
if (!cg.predictedPlayerState.stats[STAT_RACEMODE] || !cg.predictedPlayerState.duelTime) {
cg.startSpeed = 0;
cg.displacement = 0;
cg.maxSpeed = 0;
cg.displacementSamples = 0;
return;
}

time = (cg.time - cg.predictedPlayerState.duelTime);
minutes = (time / 1000) / 60;
seconds = (time / 1000) % 60;
milliseconds = (time % 1000);
{
char timerStr[48] = { 0 };
const int time = (cg.time - cg.predictedPlayerState.duelTime);
const int minutes = (time / 1000) / 60;
const int seconds = (time / 1000) % 60;
const int milliseconds = (time % 1000);

if (cg_raceTimer.integer > 1) {
if (time < 1000) {
if (time < cg.lastRaceTime) {
cg.startSpeed = 0;
cg.displacement = 0;
cg.maxSpeed = 0;
cg.displacementSamples = 0;
}
else {
if (cg.currentSpeed > cg.maxSpeed)
cg.maxSpeed = cg.currentSpeed;
cg.displacement += cg.currentSpeed;
cg.displacementSamples++;

if (cg_raceTimer.integer > 1) {
if (time > 0) {
if (!cg.startSpeed)
cg.startSpeed = (int)(cg.currentSpeed + 0.5f);

if (cg.currentSpeed > cg.maxSpeed)
cg.maxSpeed = (int)(cg.currentSpeed + 0.5f);
cg.displacement += cg.currentSpeed;
cg.displacementSamples++;
}
}
}

if (cg_raceTimer.integer < 3)
Com_sprintf(timerStr, sizeof(timerStr), "%i:%02i.%i\n", minutes, seconds, milliseconds / 100);
else
Com_sprintf(timerStr, sizeof(timerStr), "%i:%02i.%03i\n", minutes, seconds, milliseconds);
cg.lastRaceTime = time;

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

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);
if (cg_raceTimer.integer > 1 && cg.displacementSamples)
Q_strcat(timerStr, sizeof(timerStr), va("Max: %i\nAvg: %i", (int)(cg.maxSpeed + 0.5f), cg.displacement / cg.displacementSamples));

if (time < 3000)
Q_strcat(timerStr, sizeof(timerStr), va("\nStart: %i", cg.startSpeed));

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);
}
}

#define ACCEL_SAMPLES 16
Expand Down
4 changes: 3 additions & 1 deletion codemp/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,10 @@ Ghoul2 Insert End
qboolean recording;
unsigned int displacement;
unsigned int displacementSamples;
float maxSpeed;
int maxSpeed;
int lastRaceTime;
float currentSpeed;
int startSpeed;
float previousSpeed;
float lastJumpDistance;
int lastJumpDistanceTime;
Expand Down
2 changes: 1 addition & 1 deletion codemp/cgame/cg_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static void CheckTouchingCheckpoint(clientCheckpoint_t clientCheckpoint) {
time = 0.001f;

if (cg.displacementSamples)
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);
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);
else
CG_CenterPrint( va("^2%.3fs^4\n\n\n\n\n\n\n\n\n\n", time), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH );
cg.lastCheckPointPrintTime = cg.time;
Expand Down

0 comments on commit 5975ed5

Please sign in to comment.