Cache level ID for Emblems, too

This commit is contained in:
toaster 2022-12-14 17:50:00 +00:00
parent c7db580338
commit 2fbbe52ded
3 changed files with 29 additions and 6 deletions

View file

@ -2142,6 +2142,7 @@ void reademblemdata(MYFILE *f, INT32 num)
else if (fastcmp(word, "MAPNAME"))
{
emblemlocations[num-1].level = Z_StrDup(word2);
emblemlocations[num-1].levelCache = NEXTMAP_INVALID;
}
else if (fastcmp(word, "SPRITE"))
{

View file

@ -656,7 +656,7 @@ static const char *M_GetConditionString(condition_t *cn)
INT32 checkLevel;
i = cn->requirement-1;
checkLevel = G_MapNumber(emblemlocations[i].level);
checkLevel = M_EmblemMapNum(&emblemlocations[i]);
if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel])
return va("INVALID MEDAL MAP \"%d:%d\"", cn->requirement, checkLevel);
@ -952,7 +952,7 @@ UINT8 M_CheckLevelEmblems(void)
if (emblemlocations[i].type < ET_TIME || gamedata->collected[i])
continue;
checkLevel = G_MapNumber(emblemlocations[i].level);
checkLevel = M_EmblemMapNum(&emblemlocations[i]);
if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel])
continue;
@ -992,7 +992,7 @@ UINT8 M_CompletionEmblems(void) // Bah! Duplication sucks, but it's for a separa
if (emblemlocations[i].type < ET_TIME || gamedata->collected[i])
continue;
checkLevel = G_MapNumber(emblemlocations[i].level);
checkLevel = M_EmblemMapNum(&emblemlocations[i]);
if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel])
continue;
@ -1339,7 +1339,12 @@ UINT16 M_UnlockableMapNum(unlockable_t *unlock)
{
if (unlock->stringVarCache == -1)
{
unlock->stringVarCache = G_MapNumber(unlock->stringVar);
INT32 result = G_MapNumber(unlock->stringVar);
if (result >= nummapheaders)
return result;
unlock->stringVarCache = result;
}
return unlock->stringVarCache;
@ -1352,6 +1357,21 @@ UINT16 M_UnlockableMapNum(unlockable_t *unlock)
// Misc Emblem shit
// ----------------
UINT16 M_EmblemMapNum(emblem_t *emblem)
{
if (emblem->levelCache == NEXTMAP_INVALID)
{
UINT16 result = G_MapNumber(emblem->level);
if (result >= nummapheaders)
return result;
emblem->levelCache = result;
}
return emblem->levelCache;
}
// Returns pointer to an emblem if an emblem exists for that level.
// Pass -1 mapnum to continue from last emblem.
// NULL if not found.
@ -1369,7 +1389,7 @@ emblem_t *M_GetLevelEmblems(INT32 mapnum)
while (--i >= 0)
{
INT32 checkLevel = G_MapNumber(emblemlocations[i].level);
INT32 checkLevel = M_EmblemMapNum(&emblemlocations[i]);
if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel])
continue;

View file

@ -71,7 +71,8 @@ struct emblem_t
{
UINT8 type; ///< Emblem type
INT16 tag; ///< Tag of emblem mapthing
char * level; ///< Level on which this emblem can be found.
char *level; ///< Level on which this emblem can be found.
INT16 levelCache; ///< Stored G_MapNumber()+1 result
UINT8 sprite; ///< emblem sprite to use, 0 - 25
UINT16 color; ///< skincolor to use
INT32 flags; ///< GE or ME constants
@ -229,5 +230,6 @@ cupheader_t *M_UnlockableCup(unlockable_t *unlock);
UINT16 M_UnlockableMapNum(unlockable_t *unlock);
INT32 M_EmblemSkinNum(emblem_t *emblem);
UINT16 M_EmblemMapNum(emblem_t *emblem);
#define M_Achieved(a) ((a) >= MAXCONDITIONSETS || gamedata->achieved[a])