fix: make LoadSheetGraphicsInfo load, then free, tiles

Fixes follower pokeball gfx showing garbage for 1 frame when emerging
This commit is contained in:
Ariel A 2024-05-27 18:09:12 -04:00
parent a49d908254
commit 0630acce44

View file

@ -1587,10 +1587,12 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid,
u32 sheetSpan = GetSpanPerImage(info->oam->shape, info->oam->size);
u16 oldTiles = 0;
u16 tileStart;
bool32 oldInvisible;
if (tag == TAG_NONE)
tag = COMP_OW_TILE_TAG_BASE + uuid;
if (sprite) {
oldInvisible = sprite->invisible;
oldTiles = sprite->sheetTileStart;
sprite->sheetTileStart = 0; // mark unused
// Note: If sprite was not allocated to use a sheet,
@ -1604,9 +1606,19 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid,
if (tileStart == TAG_NONE) {
struct SpriteFrameImage image = {.size = info->size, .data = info->images->data};
struct SpriteTemplate template = {.tileTag = tag, .images = &image};
if (oldTiles)
FieldEffectFreeTilesIfUnused(oldTiles);
// Load, then free, in order to avoid displaying garbage data
// before sprite's `sheetTileStart` is repointed
tileStart = LoadCompressedSpriteSheetByTemplate(&template, TILE_SIZE_4BPP << sheetSpan);
if (oldTiles) {
FieldEffectFreeTilesIfUnused(oldTiles);
// We weren't able to load the sheet;
// retry (after having freed), and set sprite to invisible until done
if (tileStart <= 0) {
if (sprite)
sprite->invisible = TRUE;
tileStart = LoadCompressedSpriteSheetByTemplate(&template, TILE_SIZE_4BPP << sheetSpan);
}
}
// sheet loaded; unload any *other* sheet for sprite
} else if (oldTiles && oldTiles != tileStart) {
FieldEffectFreeTilesIfUnused(oldTiles);
@ -1616,6 +1628,7 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid,
sprite->sheetTileStart = tileStart;
sprite->sheetSpan = sheetSpan;
sprite->usingSheet = TRUE;
sprite->invisible = oldInvisible;
}
// Going from sheet -> !sheet, reset tile number
// (sheet stays loaded)