Tri map records pt.1

This commit is contained in:
NepDisk 2025-04-12 09:13:52 -04:00
parent 14b1f52573
commit 0ab033c497
7 changed files with 108 additions and 71 deletions

View file

@ -158,7 +158,8 @@ void clear_levels(void)
P_DeleteFlickies(nummapheaders);
Z_Free(mapheaderinfo[nummapheaders]->mainrecord);
for (SINT8 k = 0; k < MAXMAPRECORDS; k++)
Z_Free(mapheaderinfo[nummapheaders]->mainrecord[k]);
Patch_Free(mapheaderinfo[nummapheaders]->thumbnailPic);
Patch_Free(mapheaderinfo[nummapheaders]->minimapPic);

View file

@ -376,7 +376,7 @@ struct mapheader_t
void *minimapPic; ///< Lump data for the minimap graphic.
UINT8 mapvisited; ///< A set of flags that says what we've done in the map.
recorddata_t *mainrecord; ///< Stores best time attack data
recorddata_t *mainrecord[3]; ///< Stores best time attack data
cupheader_t *cup; ///< Cached cup

View file

@ -453,57 +453,72 @@ consvar_t cv_deadzone[MAXSPLITSCREENPLAYERS] = {
char player_names[MAXPLAYERS][MAXPLAYERNAME+1];
INT32 player_name_changes[MAXPLAYERS];
// What record should preset should we use?
SINT8 G_RecordPresetIndex(void)
{
boolean rings = cv_dummyattackingrings.value;
boolean stacking = cv_dummyattackingstacking.value;
boolean chaining = cv_dummyattackingchaining.value;
boolean slipdash = cv_dummyattackingslipdash.value;
boolean purpledrift = cv_dummyattackingpurpledrift.value;
if (!rings && !stacking && !chaining && !slipdash && !purpledrift)
return 0;
if (stacking && chaining && !rings && !slipdash && !purpledrift)
return 1;
if (rings && stacking && chaining && slipdash && purpledrift)
return 2;
return -1;
}
// Allocation for time and nights data
void G_AllocMainRecordData(INT16 i)
{
SINT8 preset = G_RecordPresetIndex();
if (preset == -1)
return;
if (i > nummapheaders || !mapheaderinfo[i])
I_Error("G_AllocMainRecordData: Internal map ID %d not found (nummapheaders = %d)\n", i, nummapheaders);
if (!mapheaderinfo[i]->mainrecord)
mapheaderinfo[i]->mainrecord = Z_Malloc(sizeof(recorddata_t), PU_STATIC, NULL);
memset(mapheaderinfo[i]->mainrecord, 0, sizeof(recorddata_t));
if (!mapheaderinfo[i]->mainrecord[preset])
mapheaderinfo[i]->mainrecord[preset] = Z_Malloc(sizeof(recorddata_t), PU_STATIC, NULL);
memset(mapheaderinfo[i]->mainrecord[preset], 0, sizeof(recorddata_t));
}
// MAKE SURE YOU SAVE DATA BEFORE CALLING THIS
void G_ClearRecords(void)
{
INT16 i;
SINT8 preset = G_RecordPresetIndex();
if (preset == -1)
return;
for (i = 0; i < nummapheaders; ++i)
{
if (mapheaderinfo[i]->mainrecord)
if (mapheaderinfo[i]->mainrecord[preset])
{
Z_Free(mapheaderinfo[i]->mainrecord);
mapheaderinfo[i]->mainrecord = NULL;
Z_Free(mapheaderinfo[i]->mainrecord[preset]);
mapheaderinfo[i]->mainrecord[preset] = NULL;
}
/*if (nightsrecords[i])
{
Z_Free(nightsrecords[i]);
nightsrecords[i] = NULL;
}*/
}
}
// For easy retrieval of records
tic_t G_GetBestTime(INT16 map)
{
if (!mapheaderinfo[map] || !mapheaderinfo[map]->mainrecord || mapheaderinfo[map]->mainrecord->time <= 0)
SINT8 preset = G_RecordPresetIndex();
if (!mapheaderinfo[map] || preset == -1 || !mapheaderinfo[map]->mainrecord[preset] || mapheaderinfo[map]->mainrecord[preset]->time <= 0)
return (tic_t)UINT32_MAX;
return mapheaderinfo[map]->mainrecord->time;
return mapheaderinfo[map]->mainrecord[preset]->time;
}
// BE RIGHT BACK
// Not needed
/*
tic_t G_GetBestLap(INT16 map)
{
if (!mapheaderinfo[map] || !mapheaderinfo[map]->mainrecord || mapheaderinfo[map]->mainrecord->lap <= 0)
return (tic_t)UINT32_MAX;
return mapheaderinfo[map]->mainrecord->lap;
}
*/
boolean K_EmblemsEnabled(void)
{
if (cv_dummyattackingrings.value)
@ -535,9 +550,13 @@ static void G_UpdateRecordReplays(void)
char lastdemo[256], bestdemo[256];
UINT8 earnedEmblems;
int parts;
SINT8 preset = G_RecordPresetIndex();
if (preset == -1)
return;
// Record new best time
if (!mapheaderinfo[gamemap-1]->mainrecord)
if (!mapheaderinfo[gamemap-1]->mainrecord[preset])
G_AllocMainRecordData(gamemap-1);
if (players[consoleplayer].pflags & PF_NOCONTEST)
@ -545,20 +564,20 @@ static void G_UpdateRecordReplays(void)
players[consoleplayer].realtime = UINT32_MAX;
}
if (((mapheaderinfo[gamemap-1]->mainrecord->time == 0) || (players[consoleplayer].realtime < mapheaderinfo[gamemap-1]->mainrecord->time))
if (((mapheaderinfo[gamemap-1]->mainrecord[preset]->time == 0) || (players[consoleplayer].realtime < mapheaderinfo[gamemap-1]->mainrecord[preset]->time))
&& (players[consoleplayer].realtime < UINT32_MAX)) // DNF
{
mapheaderinfo[gamemap-1]->mainrecord->time = players[consoleplayer].realtime;
mapheaderinfo[gamemap-1]->mainrecord[preset]->time = players[consoleplayer].realtime;
}
if (modeattacking == ATTACKING_TIME)
{
if ((mapheaderinfo[gamemap-1]->mainrecord->lap == 0) || (bestlap < mapheaderinfo[gamemap-1]->mainrecord->lap))
mapheaderinfo[gamemap-1]->mainrecord->lap = bestlap;
if ((mapheaderinfo[gamemap-1]->mainrecord[preset]->lap == 0) || (bestlap < mapheaderinfo[gamemap-1]->mainrecord[preset]->lap))
mapheaderinfo[gamemap-1]->mainrecord[preset]->lap = bestlap;
}
else
{
mapheaderinfo[gamemap-1]->mainrecord->lap = 0;
mapheaderinfo[gamemap-1]->mainrecord[preset]->lap = 0;
}
// Save demo!
@ -4530,29 +4549,33 @@ void G_LoadGameData(void)
mapnum = G_MapNumber(mapname);
rtemp = READUINT8(save.p);
rectime = (tic_t)READUINT32(save.p);
reclap = (tic_t)READUINT32(save.p);
if (mapnum < nummapheaders && mapheaderinfo[mapnum])
for (SINT8 k = 0; k < MAXMAPRECORDS; k++)
{
// Valid mapheader, time to populate with record data.
rectime = (tic_t)READUINT32(save.p);
reclap = (tic_t)READUINT32(save.p);
if ((mapheaderinfo[mapnum]->mapvisited = rtemp) & ~MV_MAX)
goto datacorrupt;
if (rectime || reclap)
if (mapnum < nummapheaders && mapheaderinfo[mapnum])
{
G_AllocMainRecordData((INT16)i);
mapheaderinfo[i]->mainrecord->time = rectime;
mapheaderinfo[i]->mainrecord->lap = reclap;
CONS_Printf("ID %d, Time = %d, Lap = %d\n", i, rectime/35, reclap/35);
// Valid mapheader, time to populate with record data.
if ((mapheaderinfo[mapnum]->mapvisited = rtemp) & ~MV_MAX)
goto datacorrupt;
if (rectime || reclap)
{
G_AllocMainRecordData((INT16)i);
mapheaderinfo[i]->mainrecord[k]->time = rectime;
mapheaderinfo[i]->mainrecord[k]->lap = reclap;
CONS_Printf("Map Record %d, ID %d, Time = %d, Lap = %d\n", k, i, rectime/35, reclap/35);
}
}
else
{
// Since it's not worth declaring the entire gamedata
// corrupt over extra maps, we report and move on.
//CONS_Alert(CONS_WARNING, "Map with lumpname %s does not exist, time record data will be discarded\n", mapname);
}
}
else
{
// Since it's not worth declaring the entire gamedata
// corrupt over extra maps, we report and move on.
//CONS_Alert(CONS_WARNING, "Map with lumpname %s does not exist, time record data will be discarded\n", mapname);
}
}
@ -4658,15 +4681,18 @@ void G_SaveGameData(void)
WRITEUINT8(save.p, (mapheaderinfo[i]->mapvisited & MV_MAX));
if (mapheaderinfo[i]->mainrecord)
for (SINT8 k = 0; k < MAXMAPRECORDS; k++)
{
WRITEUINT32(save.p, mapheaderinfo[i]->mainrecord->time);
WRITEUINT32(save.p, mapheaderinfo[i]->mainrecord->lap);
}
else
{
WRITEUINT32(save.p, 0);
WRITEUINT32(save.p, 0);
if (mapheaderinfo[i]->mainrecord[k])
{
WRITEUINT32(save.p, mapheaderinfo[i]->mainrecord[k]->time);
WRITEUINT32(save.p, mapheaderinfo[i]->mainrecord[k]->lap);
}
else
{
WRITEUINT32(save.p, 0);
WRITEUINT32(save.p, 0);
}
}
}

View file

@ -249,7 +249,8 @@ void G_SetGamestate(gamestate_t newstate);
boolean G_GamestateUsesLevel(void);
// Gamedata record shit
#define MAXMAPRECORDS 25
#define MAXMAPRECORDS 3
SINT8 G_RecordPresetIndex(void);
void G_AllocMainRecordData(INT16 i);
void G_ClearRecords(void);

View file

@ -538,12 +538,13 @@ UINT8 M_GotLowEnoughTime(INT32 tictime)
for (i = 0; i < nummapheaders; ++i)
{
SINT8 preset = G_RecordPresetIndex();
if (!mapheaderinfo[i] || (mapheaderinfo[i]->menuflags & LF2_NOTIMEATTACK))
continue;
if (!mapheaderinfo[i]->mainrecord || !mapheaderinfo[i]->mainrecord->time)
if (!mapheaderinfo[i]->mainrecord[preset] || !mapheaderinfo[i]->mainrecord[preset]->time)
return false;
else if ((curtics += mapheaderinfo[i]->mainrecord->time) > tictime)
else if ((curtics += mapheaderinfo[i]->mainrecord[preset]->time) > tictime)
return false;
}
return true;

View file

@ -5211,19 +5211,20 @@ static void M_DrawStatsMaps(void)
INT16 mnum;
extraemblem_t *exemblem;
boolean dotopname = true, dobottomarrow = (location < statsMax);
SINT8 preset = G_RecordPresetIndex();
for (j = 0; j < nummapheaders; j++)
{
if (!mapheaderinfo[j] || (mapheaderinfo[j]->menuflags & LF2_NOTIMEATTACK))
continue;
if (!mapheaderinfo[j]->mainrecord || mapheaderinfo[j]->mainrecord->time <= 0)
if (!mapheaderinfo[j]->mainrecord[preset] || mapheaderinfo[j]->mainrecord[preset]->time <= 0)
{
mapsunfinished++;
continue;
}
besttime += mapheaderinfo[j]->mainrecord->time;
besttime += mapheaderinfo[j]->mainrecord[preset]->time;
}
V_DrawString(20, 42, highlightflags, "Combined time records:");
@ -5575,6 +5576,7 @@ void M_DrawTimeAttackMenu(void)
{
INT32 i, x, y, cursory = 0;
UINT16 dispstatus;
SINT8 preset = G_RecordPresetIndex();
//S_ChangeMusicInternal("racent", true); // Eww, but needed for when user hits escape during demo playback
@ -5663,10 +5665,10 @@ void M_DrawTimeAttackMenu(void)
{
INT32 dupadjust = (vid.width/vid.dupx);
tic_t lap = 0, time = 0;
if (mapheaderinfo[cv_nextmap.value-1]->mainrecord)
if (mapheaderinfo[cv_nextmap.value-1]->mainrecord[preset])
{
lap = mapheaderinfo[cv_nextmap.value-1]->mainrecord->lap;
time = mapheaderinfo[cv_nextmap.value-1]->mainrecord->time;
lap = mapheaderinfo[cv_nextmap.value-1]->mainrecord[preset]->lap;
time = mapheaderinfo[cv_nextmap.value-1]->mainrecord[preset]->time;
}
V_DrawFill((BASEVIDWIDTH - dupadjust)>>1, 78, dupadjust, 36, 159);

View file

@ -448,8 +448,11 @@ static void P_ClearSingleMapHeaderInfo(INT16 num)
#endif
mapheaderinfo[num]->mapvisited = 0;
Z_Free(mapheaderinfo[num]->mainrecord);
mapheaderinfo[num]->mainrecord = NULL;
for (int j = 0; j < MAXMAPRECORDS; j++)
{
Z_Free(mapheaderinfo[num]->mainrecord[j]);
mapheaderinfo[num]->mainrecord[j] = NULL;
}
mapheaderinfo[num]->customopts = NULL;
mapheaderinfo[num]->numCustomOptions = 0;
@ -503,7 +506,10 @@ void P_AllocMapHeader(INT16 i)
mapheaderinfo[i]->thumbnailPic = NULL;
mapheaderinfo[i]->minimapPic = NULL;
mapheaderinfo[i]->cup = NULL;
mapheaderinfo[i]->mainrecord = NULL;
for (int j = 0; j < MAXMAPRECORDS; j++)
{
mapheaderinfo[i]->mainrecord[j] = NULL;
}
mapheaderinfo[i]->flickies = NULL;
nummapheaders++;
}