mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Cache the result of M_UnlockableSkinNum/FollowerNum/MapNum/Cup
Improves performance on mapheader iteration for M_Map/CupLocked significantly.
This commit is contained in:
parent
20c754ca66
commit
fc6eff65c2
4 changed files with 78 additions and 28 deletions
|
|
@ -2278,11 +2278,13 @@ void readunlockable(MYFILE *f, INT32 num)
|
||||||
unlockables[num].type = SECRET_ITEMFINDER;
|
unlockables[num].type = SECRET_ITEMFINDER;
|
||||||
else
|
else
|
||||||
unlockables[num].type = (INT16)i;
|
unlockables[num].type = (INT16)i;
|
||||||
|
unlockables[num].stringVarCache = -1;
|
||||||
}
|
}
|
||||||
else if (fastcmp(word, "VAR"))
|
else if (fastcmp(word, "VAR"))
|
||||||
{
|
{
|
||||||
Z_Free(unlockables[num].stringVar);
|
Z_Free(unlockables[num].stringVar);
|
||||||
unlockables[num].stringVar = Z_StrDup(word2);
|
unlockables[num].stringVar = Z_StrDup(word2);
|
||||||
|
unlockables[num].stringVarCache = -1;
|
||||||
unlockables[num].variable = (INT16)i;
|
unlockables[num].variable = (INT16)i;
|
||||||
}
|
}
|
||||||
else if (fastcmp(word, "ICON"))
|
else if (fastcmp(word, "ICON"))
|
||||||
|
|
|
||||||
|
|
@ -4650,16 +4650,13 @@ static void M_DrawChallengePreview(INT32 x, INT32 y)
|
||||||
}
|
}
|
||||||
case SECRET_MAP:
|
case SECRET_MAP:
|
||||||
{
|
{
|
||||||
if (ref->stringVar && ref->stringVar[0])
|
UINT16 mapnum = M_UnlockableMapNum(ref);
|
||||||
{
|
K_DrawMapThumbnail(
|
||||||
UINT16 mapnum = G_MapNumber(ref->stringVar);
|
(x-30)<<FRACBITS, (y)<<FRACBITS,
|
||||||
K_DrawMapThumbnail(
|
60<<FRACBITS,
|
||||||
(x-30)<<FRACBITS, (y)<<FRACBITS,
|
0,
|
||||||
60<<FRACBITS,
|
mapnum,
|
||||||
0,
|
NULL);
|
||||||
mapnum,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
85
src/m_cond.c
85
src/m_cond.c
|
|
@ -1054,9 +1054,7 @@ boolean M_MapLocked(INT32 mapnum)
|
||||||
{
|
{
|
||||||
if (unlockables[i].type != SECRET_CUP)
|
if (unlockables[i].type != SECRET_CUP)
|
||||||
continue;
|
continue;
|
||||||
if (!unlockables[i].stringVar || !unlockables[i].stringVar[0])
|
if (M_UnlockableMapNum(&unlockables[i]) != mapnum-1)
|
||||||
continue;
|
|
||||||
if (G_MapNumber(unlockables[i].stringVar) != mapnum-1)
|
|
||||||
continue;
|
continue;
|
||||||
return !M_CheckNetUnlockByID(i);
|
return !M_CheckNetUnlockByID(i);
|
||||||
}
|
}
|
||||||
|
|
@ -1143,10 +1141,18 @@ INT32 M_UnlockableSkinNum(unlockable_t *unlock)
|
||||||
|
|
||||||
if (unlock->stringVar && unlock->stringVar[0])
|
if (unlock->stringVar && unlock->stringVar[0])
|
||||||
{
|
{
|
||||||
|
INT32 skinnum;
|
||||||
|
|
||||||
|
if (unlock->stringVarCache != -1)
|
||||||
|
{
|
||||||
|
return unlock->stringVarCache;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the skin from the string.
|
// Get the skin from the string.
|
||||||
INT32 skinnum = R_SkinAvailable(unlock->stringVar);
|
skinnum = R_SkinAvailable(unlock->stringVar);
|
||||||
if (skinnum != -1)
|
if (skinnum != -1)
|
||||||
{
|
{
|
||||||
|
unlock->stringVarCache = skinnum;
|
||||||
return skinnum;
|
return skinnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1172,10 +1178,18 @@ INT32 M_UnlockableFollowerNum(unlockable_t *unlock)
|
||||||
|
|
||||||
if (unlock->stringVar && unlock->stringVar[0])
|
if (unlock->stringVar && unlock->stringVar[0])
|
||||||
{
|
{
|
||||||
|
INT32 skinnum;
|
||||||
|
|
||||||
|
if (unlock->stringVarCache != -1)
|
||||||
|
{
|
||||||
|
return unlock->stringVarCache;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the skin from the string.
|
// Get the skin from the string.
|
||||||
INT32 skinnum = K_FollowerAvailable(unlock->stringVar);
|
skinnum = K_FollowerAvailable(unlock->stringVar);
|
||||||
if (skinnum != -1)
|
if (skinnum != -1)
|
||||||
{
|
{
|
||||||
|
unlock->stringVarCache = skinnum;
|
||||||
return skinnum;
|
return skinnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1193,6 +1207,7 @@ INT32 M_UnlockableFollowerNum(unlockable_t *unlock)
|
||||||
cupheader_t *M_UnlockableCup(unlockable_t *unlock)
|
cupheader_t *M_UnlockableCup(unlockable_t *unlock)
|
||||||
{
|
{
|
||||||
cupheader_t *cup = kartcupheaders;
|
cupheader_t *cup = kartcupheaders;
|
||||||
|
INT16 val = unlock->variable-1;
|
||||||
|
|
||||||
if (unlock->type != SECRET_CUP)
|
if (unlock->type != SECRET_CUP)
|
||||||
{
|
{
|
||||||
|
|
@ -1202,28 +1217,62 @@ cupheader_t *M_UnlockableCup(unlockable_t *unlock)
|
||||||
|
|
||||||
if (unlock->stringVar && unlock->stringVar[0])
|
if (unlock->stringVar && unlock->stringVar[0])
|
||||||
{
|
{
|
||||||
// Get the cup from the string.
|
if (unlock->stringVarCache == -1)
|
||||||
while (cup)
|
|
||||||
{
|
{
|
||||||
if (!strcmp(cup->name, unlock->stringVar))
|
// Get the cup from the string.
|
||||||
break;
|
while (cup)
|
||||||
cup = cup->next;
|
{
|
||||||
|
if (!strcmp(cup->name, unlock->stringVar))
|
||||||
|
break;
|
||||||
|
cup = cup->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cup)
|
||||||
|
{
|
||||||
|
unlock->stringVarCache = cup->id;
|
||||||
|
}
|
||||||
|
return cup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val = unlock->stringVarCache;
|
||||||
}
|
}
|
||||||
else
|
else if (val == -1)
|
||||||
{
|
{
|
||||||
// Use the number directly.
|
return NULL;
|
||||||
while (cup)
|
}
|
||||||
{
|
|
||||||
if (cup->id == unlock->variable)
|
// Use the number directly.
|
||||||
break;
|
while (cup)
|
||||||
cup = cup->next;
|
{
|
||||||
}
|
if (cup->id == val)
|
||||||
|
break;
|
||||||
|
cup = cup->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cup;
|
return cup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INT16 M_UnlockableMapNum(unlockable_t *unlock)
|
||||||
|
{
|
||||||
|
if (unlock->type != SECRET_MAP)
|
||||||
|
{
|
||||||
|
// This isn't a map unlockable...
|
||||||
|
return NEXTMAP_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlock->stringVar && unlock->stringVar[0])
|
||||||
|
{
|
||||||
|
if (unlock->stringVarCache == -1)
|
||||||
|
{
|
||||||
|
unlock->stringVarCache = G_MapNumber(unlock->stringVar);
|
||||||
|
}
|
||||||
|
|
||||||
|
return unlock->stringVarCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NEXTMAP_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------
|
// ----------------
|
||||||
// Misc Emblem shit
|
// Misc Emblem shit
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ struct unlockable_t
|
||||||
INT16 type;
|
INT16 type;
|
||||||
INT16 variable;
|
INT16 variable;
|
||||||
char *stringVar;
|
char *stringVar;
|
||||||
|
INT16 stringVarCache;
|
||||||
UINT8 majorunlock;
|
UINT8 majorunlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -225,6 +226,7 @@ UINT8 M_GotLowEnoughTime(INT32 tictime);
|
||||||
INT32 M_UnlockableSkinNum(unlockable_t *unlock);
|
INT32 M_UnlockableSkinNum(unlockable_t *unlock);
|
||||||
INT32 M_UnlockableFollowerNum(unlockable_t *unlock);
|
INT32 M_UnlockableFollowerNum(unlockable_t *unlock);
|
||||||
cupheader_t *M_UnlockableCup(unlockable_t *unlock);
|
cupheader_t *M_UnlockableCup(unlockable_t *unlock);
|
||||||
|
INT16 M_UnlockableMapNum(unlockable_t *unlock);
|
||||||
|
|
||||||
INT32 M_EmblemSkinNum(emblem_t *emblem);
|
INT32 M_EmblemSkinNum(emblem_t *emblem);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue