Fixed warp arrow palette bug. Optimized weather palette loading.

This commit is contained in:
Ariel A 2021-11-26 03:58:06 -05:00
parent 1834e487b9
commit bd3c9ed3b9
4 changed files with 18 additions and 11 deletions

View file

@ -106,6 +106,7 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l
u8 SpawnSpecialObjectEvent(struct ObjectEventTemplate *);
void SetSpritePosToMapCoords(s16, s16, s16 *, s16 *);
void CameraObjectReset1(void);
u8 LoadObjectEventPalette(u16);
u8 UpdateSpritePaletteByTemplate(const struct SpriteTemplate *, struct Sprite *);
void ObjectEventSetGraphicsId(struct ObjectEvent *, u8 graphicsId);
void ObjectEventTurn(struct ObjectEvent *, u8);

View file

@ -130,7 +130,6 @@ static void UpdateObjectEventVisibility(struct ObjectEvent *, struct Sprite *);
static void MakeObjectTemplateFromObjectEventTemplate(struct ObjectEventTemplate *, struct SpriteTemplate *, const struct SubspriteTable **);
static void GetObjectEventMovingCameraOffset(s16 *, s16 *);
static struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u8, u8, u8);
static void LoadObjectEventPalette(u16);
static void RemoveObjectEventIfOutsideView(struct ObjectEvent *);
static void SpawnObjectEventOnReturnToField(u8, s16, s16);
static void SetPlayerAvatarObjectEventIdAndObjectId(u8, u8);
@ -2431,12 +2430,12 @@ void FreeAndReserveObjectSpritePalettes(void)
gReservedSpritePaletteCount = 12;
}
static void LoadObjectEventPalette(u16 paletteTag)
u8 LoadObjectEventPalette(u16 paletteTag)
{
u16 i = FindObjectEventPaletteIndexByTag(paletteTag);
if (i != OBJ_EVENT_PAL_TAG_NONE) // always true
LoadSpritePaletteIfTagExists(&sObjectEventSpritePalettes[i]);
if (i == 0xFF)
return i;
return LoadSpritePaletteIfTagExists(&sObjectEventSpritePalettes[i]);
}
// Unused
@ -2448,12 +2447,14 @@ static void LoadObjectEventPaletteSet(u16 *paletteTags)
LoadObjectEventPalette(paletteTags[i]);
}
// Really just loads the palette and applies weather fade
static u8 LoadSpritePaletteIfTagExists(const struct SpritePalette *spritePalette)
{
u8 paletteNum;
if (IndexOfSpritePaletteTag(spritePalette->tag) != 0xFF)
return 0xFF;
u8 paletteNum = IndexOfSpritePaletteTag(spritePalette->tag);
if (paletteNum != 0xFF) // don't load twice; return
return paletteNum;
paletteNum = LoadSpritePalette(spritePalette);
if (paletteNum != 0xFF)
UpdateSpritePaletteWithWeather(paletteNum, FALSE);
return paletteNum;
}

View file

@ -255,6 +255,8 @@ u8 CreateWarpArrowSprite(void)
if (spriteId != MAX_SPRITES)
{
sprite = &gSprites[spriteId];
// OBJ_EVENT_PAL_TAG_MAY : OBJ_EVENT_PAL_TAG_BRENDAN
sprite->oam.paletteNum = LoadObjectEventPalette(gSaveBlock2Ptr->playerGender ? 0x1110 : 0x1100);
sprite->oam.priority = 1;
sprite->coordOffsetEnabled = TRUE;
sprite->invisible = TRUE;
@ -1421,7 +1423,7 @@ static u32 ShowDisguiseFieldEffect(u8 fldEff, u8 fldEffObj, u8 paletteNum)
if (spriteId != MAX_SPRITES)
{
sprite = &gSprites[spriteId];
UpdateSpritePaletteByTemplate(gFieldEffectObjectTemplatePointers[fldEffObj], sprite);
sprite->oam.paletteNum = LoadObjectEventPalette(gFieldEffectObjectTemplatePointers[fldEffObj]->paletteTag);
sprite->coordOffsetEnabled ++;
sprite->sFldEff = fldEff;
sprite->sLocalId = gFieldEffectArguments[0];

View file

@ -165,7 +165,7 @@ void StartWeather(void)
CpuCopy32(gFogPalette, &gPlttBufferUnfaded[0x100 + index * 16], 32);
BuildGammaShiftTables();
gWeatherPtr->altGammaSpritePalIndex = index;
gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2);
gWeatherPtr->weatherPicSpritePalIndex = 0xFF; // defer allocation until needed
gWeatherPtr->rainSpriteCount = 0;
gWeatherPtr->curRainSpriteIndex = 0;
gWeatherPtr->cloudSpritesCreated = 0;
@ -899,6 +899,9 @@ static bool8 IsFirstFrameOfWeatherFadeIn(void)
void LoadCustomWeatherSpritePalette(const u16 *palette)
{
if (gWeatherPtr->weatherPicSpritePalIndex > 16) // haven't allocated palette yet
if ((gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2)) > 16)
return;
LoadPalette(palette, 0x100 + gWeatherPtr->weatherPicSpritePalIndex * 16, 32);
UpdateSpritePaletteWithWeather(gWeatherPtr->weatherPicSpritePalIndex, TRUE);
}