From eee6a6ff457c823559c2f77f6fc3b38d69c644c2 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 11 Jul 2016 23:01:43 +0100 Subject: [PATCH] Optimisations to the character select screen. * If a character select character image is not set, don't iterate every tic - iterate on first image get and then save to the struct. * A character select screen with only two characters now has special case handling. * A memory leak in the making has been plugged. (specifically, picname not being Z_Free'd if the loop fails to do so) * Logic/operation simplification. Also, some typo corrections and clarity case movements of stuff in other files I've been looking at. --- src/dehacked.c | 2 +- src/m_menu.c | 122 +++++++++++++++++++++++++++---------------------- src/p_mobj.c | 13 +++--- 3 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 9134f54c1..7f53ec690 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -563,7 +563,7 @@ static void readPlayer(MYFILE *f, INT32 num) You MAY disable previous entries if you so desire... But try to enable something that's already enabled and you will be sent to a free slot. - Because of this, you are allowed to edit any previous entrys you like, but only if you + Because of this, you are allowed to edit any previous entries you like, but only if you signal that you are purposely doing so by disabling and then reenabling the slot. ... Or use MENUPOSITION first, that works too. Hell, you could edit multiple character diff --git a/src/m_menu.c b/src/m_menu.c index 9a08a5f80..08a21a4b2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4813,10 +4813,9 @@ static void M_DrawSetupChoosePlayerMenu(void) { o = (lastdirection) ? -1 : 1; char_scroll = (itemOn + o)*128*FRACUNIT; + i = -o*128; } - i = (itemOn*128 - char_scroll/FRACUNIT); - if (abs(i) > 1) char_scroll += i*FRACUNIT>>2; else // close enough. @@ -4840,7 +4839,7 @@ static void M_DrawSetupChoosePlayerMenu(void) } while (i != j && PlayerMenu[i].status == IT_DISABLED); // Skip over all disabled characters. } - // prev character + // Get prev character... prev = i; do { @@ -4849,74 +4848,85 @@ static void M_DrawSetupChoosePlayerMenu(void) prev = (currentMenu->numitems - 1); } while (prev != i && PlayerMenu[prev].status == IT_DISABLED); // Skip over all disabled characters. - if (prev != i - && o < 32) + if (prev != i) // If there's more than one character available... { - picname = description[prev].picname; - if (picname[0] == '\0') + // Let's get the next character now. + next = i; + do { - picname = strtok(Z_StrDup(description[prev].skinname), "&"); - for (j = 0; j < numskins; j++) - if (stricmp(skins[j].name, picname) == 0) + next++; + if (next >= currentMenu->numitems) + 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 + 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[j].charsel; - break; + picname = skins[0].charsel; } - if (j == numskins) // AAAAAAAAAA - picname = skins[0].charsel; + strncpy(description[prev].picname, picname, 8); // Only iterate once. + } + patch = W_CachePatchName(picname, PU_CACHE); + if (SHORT(patch->width) >= 256) + V_DrawCroppedPatch(8<height) - 64 + o*2, SHORT(patch->width), SHORT(patch->height)); + else + V_DrawCroppedPatch(8<height) - 32 + o, SHORT(patch->width), SHORT(patch->height)); + W_UnlockCachedPatch(patch); } - patch = W_CachePatchName(picname, PU_CACHE); - if (SHORT(patch->width) >= 256) - V_DrawCroppedPatch(8<height) - 64 + o*2, SHORT(patch->width), SHORT(patch->height)); - else - V_DrawCroppedPatch(8<height) - 32 + o, SHORT(patch->width), SHORT(patch->height)); - W_UnlockCachedPatch(patch); - } - // next character - next = i; - do - { - next++; - if (next >= currentMenu->numitems) - next = 0; - } while (next != i && PlayerMenu[next].status == IT_DISABLED); // Skip over all disabled characters. - - if (next != i - && o < 128) - { - picname = description[next].picname; - if (picname[0] == '\0') + // Draw next character if it's visible and its number isn't less than the current one + 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 = strtok(Z_StrDup(description[next].skinname), "&"); - for (j = 0; j < numskins; j++) - if (stricmp(skins[j].name, picname) == 0) + 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[j].charsel; - break; + picname = skins[0].charsel; } - if (j == numskins) // AAAAAAAAAA - picname = skins[0].charsel; + strncpy(description[next].picname, picname, 8); // Only iterate once. + } + patch = W_CachePatchName(picname, PU_CACHE); + if (SHORT(patch->width) >= 256) + V_DrawCroppedPatch(8<width), o*2); + else + V_DrawCroppedPatch(8<width), o); + W_UnlockCachedPatch(patch); } - patch = W_CachePatchName(picname, PU_CACHE); - if (SHORT(patch->width) >= 256) - V_DrawCroppedPatch(8<width), o*2); - else - V_DrawCroppedPatch(8<width), o); - W_UnlockCachedPatch(patch); - } - // current character - if (PlayerMenu[i].status == IT_DISABLED) // Prevent flickering. - i = (lastdirection) ? prev : next; // This actually causes duplication at slow scroll speeds (<16FU per tic), but thankfully we always go quickly. + // current character + if (PlayerMenu[i].status == IT_DISABLED) // Prevent flickering. + i = (lastdirection) ? prev : next; // This actually causes duplication at slow scroll speeds (<16FU per tic), but thankfully we always go quickly. + } if (PlayerMenu[i].status != IT_DISABLED) { picname = description[i].picname; if (picname[0] == '\0') - { + { picname = strtok(Z_StrDup(description[i].skinname), "&"); for (j = 0; j < numskins; j++) if (stricmp(skins[j].name, picname) == 0) @@ -4926,8 +4936,12 @@ static void M_DrawSetupChoosePlayerMenu(void) break; } if (j == numskins) // AAAAAAAAAA + { + Z_Free(picname); picname = skins[0].charsel; - } + } + strncpy(description[i].picname, picname, 8); // Only iterate once. + } patch = W_CachePatchName(picname, PU_CACHE); if (o >= 0 && o <= 32) { diff --git a/src/p_mobj.c b/src/p_mobj.c index 43ae0ecfc..653b6967e 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -355,7 +355,7 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) spr2 = SPR2_SPNG; break; case SPR2_JUMP: - spr2 = (skin->flags & SF_NOJUMPSPIN) ? SPR2_SPNG : SPR2_SPIN; + spr2 = (player->charflags & SF_NOJUMPSPIN) ? SPR2_SPNG : SPR2_SPIN; break; case SPR2_SPNG: // spring spr2 = SPR2_FALL; @@ -384,11 +384,6 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) spr2 = SPR2_CLMB; break; - case SPR2_SIGN: - case SPR2_LIFE: - noalt = true; - break; - // Super sprites fallback to regular sprites case SPR2_SWLK: spr2 = SPR2_WALK; @@ -433,6 +428,12 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) spr2 = SPR2_SWLK; break; + // Sprites for non-player objects? There's nothing we can do. + case SPR2_SIGN: + case SPR2_LIFE: + noalt = true; + break; + // Dunno? Just go to standing then. default: spr2 = SPR2_STND;