From f926842b30c106b55a4c960424324fa2b4156bad Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 14 Oct 2022 13:19:20 +0100 Subject: [PATCH] Fix replacing cups' map lists not properly reassigning the cachedlevels --- src/deh_soc.c | 2 ++ src/p_setup.c | 64 ++++++++++++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 427493f28..28b190a67 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -3070,10 +3070,12 @@ void readcupheader(MYFILE *f, cupheader_t *cup) else if (fastcmp(word, "BONUSGAME")) { cup->levellist[CUPCACHE_BONUS] = Z_StrDup(word2); + cup->cachedlevels[CUPCACHE_BONUS] = NEXTMAP_INVALID; } else if (fastcmp(word, "SPECIALSTAGE")) { cup->levellist[CUPCACHE_SPECIAL] = Z_StrDup(word2); + cup->cachedlevels[CUPCACHE_SPECIAL] = NEXTMAP_INVALID; } else if (fastcmp(word, "EMERALDNUM")) { diff --git a/src/p_setup.c b/src/p_setup.c index 001bd404b..a8c35596f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4499,6 +4499,39 @@ UINT8 P_InitMapData(INT32 numexistingmapheaders) continue; } + // Always check for cup cache reassociations. + // (The core assumption is that cups < headers.) + { + cupheader_t *cup = kartcupheaders; + INT32 j; + + mapheaderinfo[i]->cup = NULL; + + while (cup) + { + for (j = 0; j < CUPCACHE_MAX; j++) + { + // Already discovered? + if (cup->cachedlevels[j] != NEXTMAP_INVALID) + continue; + + if (!cup->levellist[j] || strcasecmp(cup->levellist[j], name) != 0) + continue; + + // Only panic about back-reference for non-bonus material. + if (j < MAXLEVELLIST) + { + if (mapheaderinfo[i]->cup) + I_Error("P_InitMapData: Map %s cannot appear in cups multiple times! (First in %s, now in %s)", name, mapheaderinfo[i]->cup->name, cup->name); + mapheaderinfo[i]->cup = cup; + } + + cup->cachedlevels[j] = i; + } + cup = cup->next; + } + } + // No change? if (mapheaderinfo[i]->lumpnum == maplump) continue; @@ -4547,37 +4580,6 @@ UINT8 P_InitMapData(INT32 numexistingmapheaders) } vres_Free(virtmap); - - // Now associate it with a cup cache. - // (The core assumption is that cups < headers.) - if (i >= numexistingmapheaders) - { - cupheader_t *cup = kartcupheaders; - INT32 j; - while (cup) - { - for (j = 0; j < CUPCACHE_MAX; j++) - { - // Already discovered? - if (cup->cachedlevels[j] != NEXTMAP_INVALID) - continue; - - if (!cup->levellist[j] || strcasecmp(cup->levellist[j], name) != 0) - continue; - - // Only panic about back-reference for non-bonus material. - if (j < MAXLEVELLIST || j == CUPCACHE_SPECIAL) - { - if (mapheaderinfo[i]->cup) - I_Error("P_InitMapData: Map %s cannot appear in cups multiple times! (First in %s, now in %s)", name, mapheaderinfo[i]->cup->name, cup->name); - mapheaderinfo[i]->cup = cup; - } - - cup->cachedlevels[j] = i; - } - cup = cup->next; - } - } } }