From ee92e043b98fe4b8d487bba0a4e60e494c71bffb Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 11 Jul 2016 23:40:31 +0100 Subject: [PATCH] Preparation for hidden characters, making sure R_SkinAvailable was being used where appropriate. Also, bugfix for something my optimisation introduced. --- src/dehacked.c | 2 ++ src/m_menu.c | 53 +++++++++++++++----------------------------------- src/r_things.c | 13 +++++-------- 3 files changed, 23 insertions(+), 45 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 7f53ec690..518e1c85c 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -584,6 +584,8 @@ static void readPlayer(MYFILE *f, INT32 num) strlcpy(description[num].skinname, word2, sizeof description[num].skinname); strlwr(description[num].skinname); + + description[num].picname[0] = '\0'; // Redesign your logo. (See M_DrawSetupChoosePlayerMenu in m_menu.c...) } else deh_warning("readPlayer %d: unknown word '%s'", num, word); diff --git a/src/m_menu.c b/src/m_menu.c index 08a21a4b2..f64fa2fc7 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4859,25 +4859,18 @@ static void M_DrawSetupChoosePlayerMenu(void) next = 0; } while (next != i && PlayerMenu[next].status == IT_DISABLED); // Skip over all disabled characters. - // Draw prev character if it's visible and its number isn't greater than the current one + // Draw prev character if it's visible and its number isn't greater than the current one or there's more than two if ((o < 32) && !((prev == next) && prev > i)) // (prev != i) was previously a part of this, but we don't need to check again after above. { picname = description[prev].picname; if (picname[0] == '\0') { picname = strtok(Z_StrDup(description[prev].skinname), "&"); - for (j = 0; j < numskins; j++) - if (stricmp(skins[j].name, picname) == 0) - { - Z_Free(picname); - picname = skins[j].charsel; - break; - } - if (j == numskins) // AAAAAAAAAA - { - Z_Free(picname); - picname = skins[0].charsel; - } + j = R_SkinAvailable(picname); + Z_Free(picname); + if (j == -1) + j = 0; + picname = skins[j].charsel; strncpy(description[prev].picname, picname, 8); // Only iterate once. } patch = W_CachePatchName(picname, PU_CACHE); @@ -4888,25 +4881,18 @@ static void M_DrawSetupChoosePlayerMenu(void) W_UnlockCachedPatch(patch); } - // Draw next character if it's visible and its number isn't less than the current one + // Draw next character if it's visible and its number isn't less than the current one or there's more than two if ((o < 128) && !((prev == next) && next < i)) // (next != i) was previously a part of this, but it's implicitly true if (prev != i) is true. { picname = description[next].picname; if (picname[0] == '\0') { picname = strtok(Z_StrDup(description[next].skinname), "&"); - for (j = 0; j < numskins; j++) - if (stricmp(skins[j].name, picname) == 0) - { - Z_Free(picname); - picname = skins[j].charsel; - break; - } - if (j == numskins) // AAAAAAAAAA - { - Z_Free(picname); - picname = skins[0].charsel; - } + j = R_SkinAvailable(picname); + Z_Free(picname); + if (j == -1) + j = 0; + picname = skins[j].charsel; strncpy(description[next].picname, picname, 8); // Only iterate once. } patch = W_CachePatchName(picname, PU_CACHE); @@ -4928,18 +4914,11 @@ static void M_DrawSetupChoosePlayerMenu(void) if (picname[0] == '\0') { picname = strtok(Z_StrDup(description[i].skinname), "&"); - for (j = 0; j < numskins; j++) - if (stricmp(skins[j].name, picname) == 0) - { - Z_Free(picname); - picname = skins[j].charsel; - break; - } - if (j == numskins) // AAAAAAAAAA - { + j = R_SkinAvailable(picname); Z_Free(picname); - picname = skins[0].charsel; - } + if (j == -1) + j = 0; + picname = skins[j].charsel; strncpy(description[i].picname, picname, 8); // Only iterate once. } patch = W_CachePatchName(picname, PU_CACHE); diff --git a/src/r_things.c b/src/r_things.c index 97e4d0696..83b4a8118 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2337,6 +2337,7 @@ INT32 R_SkinAvailable(const char *name) for (i = 0; i < numskins; i++) { + // search in the skin list if (stricmp(skins[i].name,name)==0) return i; } @@ -2346,17 +2347,13 @@ INT32 R_SkinAvailable(const char *name) // network code calls this when a 'skin change' is received void SetPlayerSkin(INT32 playernum, const char *skinname) { - INT32 i; + INT32 i = R_SkinAvailable(skinname); player_t *player = &players[playernum]; - for (i = 0; i < numskins; i++) + if (i != -1) { - // search in the skin list - if (stricmp(skins[i].name, skinname) == 0) - { - SetPlayerSkinByNum(playernum, i); - return; - } + SetPlayerSkinByNum(playernum, i); + return; } if (P_IsLocalPlayer(player))