chore: optimise the summary screen

It needed a bit of cleanup, why not?
This commit is contained in:
Skye Chappelle 2022-05-24 14:06:08 +00:00
parent 5408877964
commit d29b0f18df
3 changed files with 45 additions and 89 deletions

View File

@ -133,12 +133,9 @@ struct Pokemon
struct MonSpritesGfxManager
{
u32 numSprites:4;
u32 numSprites2:4; // Never read
u32 numFrames:8;
u32 active:8;
u32 dataSize:4;
u32 mode:4; // MON_SPR_GFX_MODE_*
u8 numSprites;
u8 numFrames;
bool16 active;
void *spriteBuffer;
u8 **spritePointers;
struct SpriteTemplate *templates;
@ -436,8 +433,8 @@ void HandleSetPokedexFlag(u16 nationalNum, u8 caseId, u32 personality);
const u8 *GetTrainerClassNameFromId(u16 trainerId);
const u8 *GetTrainerNameFromId(u16 trainerId);
bool8 HasTwoFramesAnimation(u16 species);
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode);
void DestroyMonSpritesGfxManager(u8 managerId);
u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum);
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(void);
void DestroyMonSpritesGfxManager(void);
u8 *MonSpritesGfxManager_GetSpritePtr(u8 spriteNum);
#endif // GUARD_POKEMON_H

View File

@ -69,7 +69,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0;
EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0};
EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0};
EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0};
EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManagers[MON_SPR_GFX_MANAGERS_COUNT] = {NULL};
EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManager = NULL;
#include "data/battle_moves.h"
@ -3468,12 +3468,8 @@ void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition)
{
if (gMonSpritesGfxPtr != NULL)
gMultiuseSpriteTemplate = gMonSpritesGfxPtr->templates[battlerPosition];
else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A])
gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_A]->templates[battlerPosition];
else if (sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B])
gMultiuseSpriteTemplate = sMonSpritesGfxManagers[MON_SPR_GFX_MANAGER_B]->templates[battlerPosition];
else
gMultiuseSpriteTemplate = gBattlerSpriteTemplates[battlerPosition];
else if (sMonSpritesGfxManager)
gMultiuseSpriteTemplate = sMonSpritesGfxManager->templates[battlerPosition];
gMultiuseSpriteTemplate.paletteTag = speciesTag;
if (battlerPosition == B_POSITION_PLAYER_LEFT || battlerPosition == B_POSITION_PLAYER_RIGHT)
@ -6882,11 +6878,11 @@ static bool8 ShouldSkipFriendshipChange(void)
#define ALLOC_FAIL_STRUCT (1 << 1)
#define GFX_MANAGER_ACTIVE 0xA3 // Arbitrary value
#define GFX_MANAGER_SPR_SIZE (MON_PIC_SIZE * 4) // Only Castform uses more than MON_PIC_SIZE, despite not displaying its forms.
#define GFX_MANAGER_NUM_FRAMES 4 // Only 2 frames are needed
#define GFX_MANAGER_NUM_FRAMES 2 // Only 2 frames are needed, so only 2 frames are used in tumbledemerald
static void InitMonSpritesGfx_Battle(struct MonSpritesGfxManager* gfx)
{
u16 i, j;
u32 i, j;
for (i = 0; i < gfx->numSprites; i++)
{
gfx->templates[i] = gBattlerSpriteTemplates[i];
@ -6912,41 +6908,21 @@ static void InitMonSpritesGfx_FullParty(struct MonSpritesGfxManager* gfx)
}
}
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
struct MonSpritesGfxManager *CreateMonSpritesGfxManager(void)
{
u8 i;
u32 i;
u8 failureFlags;
struct MonSpritesGfxManager *gfx;
failureFlags = 0;
managerId %= MON_SPR_GFX_MANAGERS_COUNT;
gfx = AllocZeroed(sizeof(*gfx));
if (gfx == NULL)
return NULL;
switch (mode)
{
case MON_SPR_GFX_MODE_FULL_PARTY:
gfx->numSprites = PARTY_SIZE + 1;
gfx->numSprites2 = PARTY_SIZE + 1;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->dataSize = 1;
gfx->mode = MON_SPR_GFX_MODE_FULL_PARTY;
break;
// case MON_SPR_GFX_MODE_BATTLE:
case MON_SPR_GFX_MODE_NORMAL:
default:
gfx->numSprites = MAX_BATTLERS_COUNT;
gfx->numSprites2 = MAX_BATTLERS_COUNT;
gfx->numFrames = GFX_MANAGER_NUM_FRAMES;
gfx->dataSize = 1;
gfx->mode = MON_SPR_GFX_MODE_NORMAL;
break;
}
// Set up sprite / sprite pointer buffers
gfx->spriteBuffer = AllocZeroed(gfx->dataSize * GFX_MANAGER_SPR_SIZE * gfx->numSprites);
gfx->spritePointers = AllocZeroed(gfx->numSprites * 32); // ? Only * 4 is necessary, perhaps they were thinking bits.
gfx->spriteBuffer = AllocZeroed(GFX_MANAGER_SPR_SIZE * gfx->numSprites);
gfx->spritePointers = AllocZeroed(gfx->numSprites * 4);
if (gfx->spriteBuffer == NULL || gfx->spritePointers == NULL)
{
failureFlags |= ALLOC_FAIL_BUFFER;
@ -6954,7 +6930,7 @@ struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
else
{
for (i = 0; i < gfx->numSprites; i++)
gfx->spritePointers[i] = gfx->spriteBuffer + (gfx->dataSize * GFX_MANAGER_SPR_SIZE * i);
gfx->spritePointers[i] = gfx->spriteBuffer + (GFX_MANAGER_SPR_SIZE * i);
}
// Set up sprite structs
@ -6968,18 +6944,7 @@ struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
{
for (i = 0; i < gfx->numFrames * gfx->numSprites; i++)
gfx->frameImages[i].size = MON_PIC_SIZE;
switch (gfx->mode)
{
case MON_SPR_GFX_MODE_FULL_PARTY:
InitMonSpritesGfx_FullParty(gfx);
break;
case MON_SPR_GFX_MODE_NORMAL:
case MON_SPR_GFX_MODE_BATTLE:
default:
InitMonSpritesGfx_Battle(gfx);
break;
}
}
// If either of the allocations failed free their respective members
@ -7002,27 +6967,21 @@ struct MonSpritesGfxManager *CreateMonSpritesGfxManager(u8 managerId, u8 mode)
}
else
{
gfx->active = GFX_MANAGER_ACTIVE;
sMonSpritesGfxManagers[managerId] = gfx;
gfx->active = TRUE;
sMonSpritesGfxManager = gfx;
}
return sMonSpritesGfxManagers[managerId];
return sMonSpritesGfxManager;
}
void DestroyMonSpritesGfxManager(u8 managerId)
void DestroyMonSpritesGfxManager(void)
{
struct MonSpritesGfxManager *gfx;
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManager;
managerId %= MON_SPR_GFX_MANAGERS_COUNT;
gfx = sMonSpritesGfxManagers[managerId];
if (gfx == NULL)
return;
if (gfx->active != GFX_MANAGER_ACTIVE)
{
memset(gfx, 0, sizeof(*gfx));
}
else
if (gfx->active)
{
TRY_FREE_AND_SET_NULL(gfx->frameImages);
TRY_FREE_AND_SET_NULL(gfx->templates);
@ -7031,20 +6990,20 @@ void DestroyMonSpritesGfxManager(u8 managerId)
memset(gfx, 0, sizeof(*gfx));
Free(gfx);
}
else
memset(gfx, 0, sizeof(*gfx));
}
u8 *MonSpritesGfxManager_GetSpritePtr(u8 managerId, u8 spriteNum)
u8 *MonSpritesGfxManager_GetSpritePtr(u8 spriteNum)
{
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManagers[managerId % MON_SPR_GFX_MANAGERS_COUNT];
if (gfx->active != GFX_MANAGER_ACTIVE)
{
return NULL;
}
else
struct MonSpritesGfxManager *gfx = sMonSpritesGfxManager;
if (gfx->active)
{
if (spriteNum >= gfx->numSprites)
spriteNum = 0;
return gfx->spritePointers[spriteNum];
}
return NULL;
}

View File

@ -1111,7 +1111,7 @@ void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex,
SummaryScreen_SetAnimDelayTaskId(TASK_NONE);
if (gMonSpritesGfxPtr == NULL)
CreateMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A, MON_SPR_GFX_MODE_NORMAL);
CreateMonSpritesGfxManager();
SetMainCallback2(CB2_InitSummaryScreen);
}
@ -1500,7 +1500,7 @@ static void CloseSummaryScreen(u8 taskId)
StopCryAndClearCrySongs();
m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 0x100);
if (gMonSpritesGfxPtr == NULL)
DestroyMonSpritesGfxManager(MON_SPR_GFX_MANAGER_A);
DestroyMonSpritesGfxManager();
FreeSummaryScreen();
DestroyTask(taskId);
}
@ -3902,12 +3902,12 @@ static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state)
{
if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == SUMMARY_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE)
HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2],
MonSpritesGfxManager_GetSpritePtr(MON_SPR_GFX_MANAGER_A, B_POSITION_OPPONENT_LEFT),
MonSpritesGfxManager_GetSpritePtr(B_POSITION_OPPONENT_LEFT),
summary->species2,
summary->pid);
else
HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2],
MonSpritesGfxManager_GetSpritePtr(MON_SPR_GFX_MANAGER_A, B_POSITION_OPPONENT_LEFT),
MonSpritesGfxManager_GetSpritePtr(B_POSITION_OPPONENT_LEFT),
summary->species2,
summary->pid);
}