Merge branch 'show-lap-time' into 'master'

Show last lap time on HUD

See merge request KartKrew/Kart!2267
This commit is contained in:
Oni 2024-04-12 03:40:38 +00:00
commit 47b44086e9
8 changed files with 90 additions and 38 deletions

View file

@ -578,6 +578,15 @@ struct altview_t
INT32 tics;
};
// enum for saved lap times
typedef enum
{
LAP_CUR,
LAP_BEST,
LAP_LAST,
LAP__MAX
} laptime_e;
extern altview_t titlemapcam;
// ========================================================================
@ -897,6 +906,7 @@ struct player_t
INT16 totalring; // Total number of rings obtained for GP
tic_t realtime; // integer replacement for leveltime
tic_t laptime[LAP__MAX];
UINT8 laps; // Number of laps (optional)
UINT8 latestlap;
UINT32 lapPoints; // Points given from laps

View file

@ -871,7 +871,6 @@ extern boolean inDuel;
extern tic_t bombflashtimer; // Used to avoid causing seizures if multiple mines explode close to you :)
extern boolean legitimateexit;
extern boolean comebackshowninfo;
extern tic_t curlap, bestlap;
#define VOTE_SPECIAL (MAXPLAYERS)
#define VOTE_TOTAL (MAXPLAYERS+1)

View file

@ -322,8 +322,6 @@ boolean inDuel; // Boolean, keeps track of if it is a 1v1
tic_t bombflashtimer = 0; // Cooldown before another FlashPal can be intialized by a bomb exploding near a displayplayer. Avoids seizures.
boolean legitimateexit; // Did this client actually finish the match?
boolean comebackshowninfo; // Have you already seen the "ATTACK OR PROTECT" message?
tic_t curlap; // Current lap time
tic_t bestlap; // Best lap time
boolean precache = true; // if true, load all graphics at start
@ -554,8 +552,8 @@ void G_UpdateRecords(void)
if (modeattacking & ATTACKING_LAP)
{
if ((record->lap == 0) || (bestlap < record->lap))
record->lap = bestlap;
if ((record->lap == 0) || (players[consoleplayer].laptime[LAP_BEST] < record->lap))
record->lap = players[consoleplayer].laptime[LAP_BEST];
}
// Check emblems when level data is updated
@ -599,7 +597,7 @@ static void G_UpdateRecordReplays(void)
// Save demo!
bestdemo[255] = '\0';
lastdemo[255] = '\0';
G_SetDemoTime(players[consoleplayer].realtime, bestlap);
G_SetDemoTime(players[consoleplayer].realtime, players[consoleplayer].laptime[LAP_BEST]);
G_CheckDemoStatus();
gpath = va("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s",
@ -2172,6 +2170,10 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
level_tally_t tally;
boolean tallyactive;
tic_t laptime[LAP__MAX];
INT32 i;
// This needs to be first, to permit it to wipe extra information
jointime = players[player].jointime;
if (jointime <= 1)
@ -2199,6 +2201,11 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
kartspeed = skins[players[player].skin].kartspeed;
kartweight = skins[players[player].skin].kartweight;
charflags = skins[players[player].skin].flags;
for (i = 0; i < LAP__MAX; i++)
{
laptime[i] = 0;
}
}
else
{
@ -2211,6 +2218,11 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
kartweight = players[player].kartweight;
charflags = (skinflags & SF_IRONMAN) ? skinflags : players[player].charflags;
for (i = 0; i < LAP__MAX; i++)
{
laptime[i] = players[player].laptime[i];
}
}
lastfakeskin = players[player].lastfakeskin;
@ -2449,6 +2461,11 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
p->lapPoints = lapPoints;
p->totalring = totalring;
for (i = 0; i < LAP__MAX; i++)
{
p->laptime[i] = laptime[i];
}
p->bot = bot;
p->botvars.difficulty = botdifficulty;
p->rings = rings;
@ -2512,8 +2529,6 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
// Check to make sure their color didn't change somehow...
if (G_GametypeHasTeams())
{
UINT8 i;
if (p->ctfteam == 1 && p->skincolor != skincolor_redteam)
{
for (i = 0; i <= splitscreen; i++)

View file

@ -1889,7 +1889,7 @@ tic_t K_TranslateTimer(tic_t drawtime, UINT8 mode, INT32 *return_jitter)
{
INT32 jitter = 0;
if (!mode)
if (!mode && drawtime != UINT32_MAX)
{
if (timelimitintics > 0)
{
@ -1948,7 +1948,6 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT32 splitflags, U
// TIME_X = BASEVIDWIDTH-124; // 196
// TIME_Y = 6; // 6
tic_t worktime;
INT32 jitter = 0;
drawtime = K_TranslateTimer(drawtime, mode, &jitter);
@ -1957,19 +1956,27 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT32 splitflags, U
TX += 33;
worktime = drawtime/(60*TICRATE);
if (worktime >= 100)
if (drawtime == UINT32_MAX)
;
else if (mode && !drawtime)
{
jitter = (drawtime & 1 ? 1 : -1);
worktime = 99;
drawtime = (100*(60*TICRATE))-1;
}
// apostrophe location _'__ __
V_DrawTimerString(TX+24, TY+3, splitflags, va("'"));
if (mode && !drawtime)
V_DrawTimerString(TX, TY+3, splitflags, "--'--\"--");
// quotation mark location _ __"__
V_DrawTimerString(TX+60, TY+3, splitflags, va("\""));
}
else
{
tic_t worktime = drawtime/(60*TICRATE);
if (worktime >= 100)
{
jitter = (drawtime & 1 ? 1 : -1);
worktime = 99;
drawtime = (100*(60*TICRATE))-1;
}
// minutes time 00 __ __
V_DrawTimerString(TX, TY+3+jitter, splitflags, va("%d", worktime/10));
V_DrawTimerString(TX+12, TY+3-jitter, splitflags, va("%d", worktime%10));
@ -6089,7 +6096,26 @@ void K_drawKartHUD(void)
{
bool ta = modeattacking && !demo.playback;
INT32 flags = V_HUDTRANS|V_SLIDEIN|V_SNAPTOTOP|V_SNAPTORIGHT;
K_drawKartTimestamp(stplyr->realtime, TIME_X, TIME_Y + (ta ? 2 : 0), flags, 0);
tic_t realtime = stplyr->realtime;
if (stplyr->karthud[khud_lapanimation]
&& !stplyr->exiting
&& stplyr->laptime[LAP_LAST] != 0
&& stplyr->laptime[LAP_LAST] != UINT32_MAX)
{
if ((stplyr->karthud[khud_lapanimation] / 5) & 1)
{
realtime = stplyr->laptime[LAP_LAST];
}
else
{
realtime = UINT32_MAX;
}
}
K_drawKartTimestamp(realtime, TIME_X, TIME_Y + (ta ? 2 : 0), flags, 0);
if (modeattacking)
{
if (ta)

View file

@ -274,6 +274,10 @@ static void P_NetArchivePlayers(savebuffer_t *save)
WRITEINT16(save->p, players[i].totalring);
WRITEUINT32(save->p, players[i].realtime);
for (j = 0; j < LAP__MAX; j++)
{
WRITEUINT32(save->p, players[i].laptime[j]);
}
WRITEUINT8(save->p, players[i].laps);
WRITEUINT8(save->p, players[i].latestlap);
WRITEUINT32(save->p, players[i].lapPoints);
@ -910,6 +914,10 @@ static void P_NetUnArchivePlayers(savebuffer_t *save)
players[i].totalring = READINT16(save->p); // Total number of rings obtained for GP
players[i].realtime = READUINT32(save->p); // integer replacement for leveltime
for (j = 0; j < LAP__MAX; j++)
{
players[i].laptime[j] = READUINT32(save->p);
}
players[i].laps = READUINT8(save->p); // Number of laps (optional)
players[i].latestlap = READUINT8(save->p);
players[i].lapPoints = READUINT32(save->p);

View file

@ -7675,7 +7675,6 @@ static void P_InitLevelSettings(void)
}
racecountdown = exitcountdown = musiccountdown = exitfadestarted = 0;
curlap = bestlap = 0; // SRB2Kart
g_exit.losing = false;
g_exit.retry = false;

View file

@ -2094,16 +2094,14 @@ static void K_HandleLapIncrement(player_t *player)
if (player->laps > 1)
{
// save best lap for record attack
if (modeattacking && player == &players[consoleplayer])
if (player->laptime[LAP_CUR] < player->laptime[LAP_BEST] || player->laptime[LAP_BEST] == 0)
{
if (curlap < bestlap || bestlap == 0)
{
bestlap = curlap;
}
curlap = 0;
player->laptime[LAP_BEST] = player->laptime[LAP_CUR];
}
player->laptime[LAP_LAST] = player->laptime[LAP_CUR];
player->laptime[LAP_CUR] = 0;
// Update power levels for this lap.
K_UpdatePowerLevels(player, player->laps, false);
@ -2223,7 +2221,7 @@ static void K_HandleLapDecrement(player_t *player)
player->cheatchecknum = numcheatchecks;
player->laps--;
K_UpdateAllPlayerPositions();
curlap = UINT32_MAX;
player->laptime[LAP_CUR] = UINT32_MAX;
}
}
}

View file

@ -4322,19 +4322,16 @@ void P_PlayerThink(player_t *player)
if (leveltime >= starttime)
{
player->realtime = leveltime - starttime;
if (player == &players[consoleplayer])
{
if (player->spectator)
curlap = 0;
else if (curlap != UINT32_MAX)
curlap++; // This is too complicated to sync to realtime, just sorta hope for the best :V
}
if (player->spectator)
player->laptime[LAP_CUR] = 0;
else if (player->laptime[LAP_CUR] != UINT32_MAX)
player->laptime[LAP_CUR]++; // This is too complicated to sync to realtime, just sorta hope for the best :V
}
else
{
player->realtime = 0;
if (player == &players[consoleplayer])
curlap = 0;
player->laptime[LAP_CUR] = 0;
}
}