From dc009d2c6c3d9d54cdc2ea07e5231ac5251bc60d Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:08:33 +0100 Subject: [PATCH] renamed to sync with emerald --- include/field_weather.h | 6 +-- include/graphics.h | 2 +- src/battle_anim_ice.c | 4 +- src/field_weather.c | 99 +++++++++++++++++-------------------- src/field_weather_effects.c | 14 +++++- src/fldeff_sweetscent.c | 2 +- 6 files changed, 66 insertions(+), 61 deletions(-) diff --git a/include/field_weather.h b/include/field_weather.h index 22b517543..47be57327 100644 --- a/include/field_weather.h +++ b/include/field_weather.h @@ -49,8 +49,8 @@ struct Weather u8 fadeScreenCounter; bool8 readyForInit; u8 taskId; - u8 fadeInActive; - u8 fadeInCounter; + u8 fadeInFirstFrame; + u8 fadeInTimer; u16 initStep; u16 finishStep; u8 currWeather; @@ -146,7 +146,7 @@ void SlightlyDarkenPalsInWeather(u16 *, u16 *, u32); void PlayRainStoppingSoundEffect(void); bool8 IsWeatherNotFadingIn(void); void SetWeatherScreenFadeOut(void); -void WeatherProcessingIdle(void); +void SetWeatherPalStateIdle(void); u8 GetCurrentWeather(void); void delay(u8, u8, u32); void UpdateSpritePaletteWithWeather(u8 palIdx, bool32 allowFog); diff --git a/include/graphics.h b/include/graphics.h index d7653eb60..f59e18db6 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4909,7 +4909,7 @@ extern const u32 gSubstituteDollPal[]; // ice extern const u8 gWeatherFogHorizontalTiles[]; extern const u32 gBattleAnimFogTilemap[]; -extern const u16 gDefaultWeatherSpritePalette[]; +extern const u16 gFogPalette[]; // party_menu extern const u32 gPartyMenuPokeball_Gfx[]; diff --git a/src/battle_anim_ice.c b/src/battle_anim_ice.c index be4993b60..ce283f383 100644 --- a/src/battle_anim_ice.c +++ b/src/battle_anim_ice.c @@ -1043,7 +1043,7 @@ void AnimTask_HazeScrollingFog(u8 taskId) GetBattleAnimBg1Data(&animBg); LoadBgTiles(animBg.bgId, gWeatherFogHorizontalTiles, 0x800, animBg.tilesOffset); AnimLoadCompressedBgTilemap(animBg.bgId, gBattleAnimFogTilemap); - LoadPalette(&gDefaultWeatherSpritePalette, BG_PLTT_ID(animBg.paletteId), PLTT_SIZE_4BPP); + LoadPalette(&gFogPalette, BG_PLTT_ID(animBg.paletteId), PLTT_SIZE_4BPP); if (IsContest()) RelocateBattleBgPal(animBg.paletteId, animBg.bgTilemap, 0, 0); gTasks[taskId].func = AnimTask_HazeScrollingFog_Step; @@ -1140,7 +1140,7 @@ void AnimTask_MistBallFog(u8 taskId) GetBattleAnimBg1Data(&animBg); LoadBgTiles(animBg.bgId, gWeatherFogHorizontalTiles, 0x800, animBg.tilesOffset); AnimLoadCompressedBgTilemap(animBg.bgId, gBattleAnimFogTilemap); - LoadPalette(&gDefaultWeatherSpritePalette, BG_PLTT_ID(animBg.paletteId), PLTT_SIZE_4BPP); + LoadPalette(&gFogPalette, BG_PLTT_ID(animBg.paletteId), PLTT_SIZE_4BPP); if (IsContest()) RelocateBattleBgPal(animBg.paletteId, animBg.bgTilemap, 0, 0); gTasks[taskId].data[15] = -1; diff --git a/src/field_weather.c b/src/field_weather.c index 816160a58..13e63aac5 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -1,6 +1,7 @@ #include "global.h" #include "gflib.h" #include "blend_palette.h" +#include "field_camera.h" #include "field_effect.h" #include "field_weather.h" #include "field_weather_util.h" @@ -39,11 +40,6 @@ struct WeatherCallbacks bool8 (*finish)(void); }; -static EWRAM_DATA struct Weather gWeather = {}; -static EWRAM_DATA u8 sFieldEffectPaletteColorMapTypes[32] = {}; -static EWRAM_DATA const u8 *sPaletteColorMapTypes = NULL; -static EWRAM_DATA u16 sDroughtFrameDelay = 0; - static void Task_WeatherMain(u8 taskId); static void Task_WeatherInit(u8 taskId); static void None_Init(void); @@ -61,6 +57,11 @@ static void DoNothing(void); static void ApplyFogBlend(u8 blendCoeff, u32 blendColor); static bool8 LightenSpritePaletteInFog(u8 paletteIndex); +EWRAM_DATA struct Weather gWeather = {0}; +EWRAM_DATA static u8 ALIGNED(2) sFieldEffectPaletteColorMapTypes[32] = {0}; + +static const u8 *sPaletteColorMapTypes; + static const u8 sDarkenedContrastColorMaps[NUM_WEATHER_COLOR_MAPS][32] = { {0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, @@ -139,14 +140,14 @@ static const struct WeatherCallbacks sWeatherFuncs[] = [WEATHER_UNDERWATER_BUBBLES] = {Bubbles_InitVars, Bubbles_Main, Bubbles_InitAll, Bubbles_Finish}, }; -static void (*const sWeatherPalStateFuncs[])(void) = { +void (*const gWeatherPalStateFuncs[])(void) = { [WEATHER_PAL_STATE_CHANGING_WEATHER] = UpdateWeatherColorMap, [WEATHER_PAL_STATE_SCREEN_FADING_IN] = FadeInScreenWithWeather, [WEATHER_PAL_STATE_SCREEN_FADING_OUT] = DoNothing, [WEATHER_PAL_STATE_IDLE] = DoNothing, }; -static const u8 sBasePaletteColorMapTypes[32] = { +static const u8 ALIGNED(2) sBasePaletteColorMapTypes[32] = { // background palettes COLOR_MAP_DARK_CONTRAST, COLOR_MAP_DARK_CONTRAST, @@ -183,18 +184,7 @@ static const u8 sBasePaletteColorMapTypes[32] = { COLOR_MAP_DARK_CONTRAST, }; -const u16 gDefaultWeatherSpritePalette[] = INCBIN_U16("graphics/weather/default.gbapal"); -const u16 gCloudsWeatherPalette[] = INCBIN_U16("graphics/weather/cloud.gbapal"); -const u16 gSandstormWeatherPalette[] = INCBIN_U16("graphics/weather/sandstorm.gbapal"); -const u8 gWeatherFogDiagonalTiles[] = INCBIN_U8("graphics/weather/fog_diagonal.4bpp"); -const u8 gWeatherFogHorizontalTiles[] = INCBIN_U8("graphics/weather/fog_horizontal.4bpp"); -const u8 gWeatherCloudTiles[] = INCBIN_U8("graphics/weather/cloud.4bpp"); -const u8 gWeatherSnow1Tiles[] = INCBIN_U8("graphics/weather/snow0.4bpp"); -const u8 gWeatherSnow2Tiles[] = INCBIN_U8("graphics/weather/snow1.4bpp"); -const u8 gWeatherBubbleTiles[] = INCBIN_U8("graphics/weather/bubble.4bpp"); -const u8 gWeatherAshTiles[] = INCBIN_U8("graphics/weather/ash.4bpp"); -const u8 gWeatherRainTiles[] = INCBIN_U8("graphics/weather/rain.4bpp"); -const u8 gWeatherSandstormTiles[] = INCBIN_U8("graphics/weather/sandstorm.4bpp"); +const u16 ALIGNED(4) gFogPalette[] = INCBIN_U16("graphics/weather/default.gbapal"); // code void StartWeather(void) @@ -202,7 +192,7 @@ void StartWeather(void) if (!FuncIsActiveTask(Task_WeatherMain)) { u8 index = AllocSpritePalette(PALTAG_WEATHER); - CpuCopy32(gDefaultWeatherSpritePalette, &gPlttBufferUnfaded[OBJ_PLTT_ID(index)], PLTT_SIZE_4BPP); + CpuCopy32(gFogPalette, &gPlttBufferUnfaded[OBJ_PLTT_ID(index)], PLTT_SIZE_4BPP); ApplyGlobalFieldPaletteTint(index); sPaletteColorMapTypes = sBasePaletteColorMapTypes; @@ -269,6 +259,7 @@ static void Task_WeatherInit(u8 taskId) // When the screen fades in, this is set to TRUE. if (gWeatherPtr->readyForInit) { + UpdateCameraPanning(); sWeatherFuncs[gWeatherPtr->currWeather].initAll(); gTasks[taskId].func = Task_WeatherMain; } @@ -279,7 +270,7 @@ static void Task_WeatherMain(u8 taskId) if (gWeatherPtr->currWeather != gWeatherPtr->nextWeather) { if (!sWeatherFuncs[gWeatherPtr->currWeather].finish() - /*&& gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT*/) + && gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT) { // Finished cleaning up previous weather. Now transition to next weather. sWeatherFuncs[gWeatherPtr->nextWeather].initVars(); @@ -294,12 +285,13 @@ static void Task_WeatherMain(u8 taskId) sWeatherFuncs[gWeatherPtr->currWeather].main(); } - sWeatherPalStateFuncs[gWeatherPtr->palProcessingState](); + gWeatherPalStateFuncs[gWeatherPtr->palProcessingState](); } static void None_Init(void) { + Weather_SetBlendCoeffs(8, 12); // Indoor shadows gWeatherPtr->targetColorMapIndex = 0; gWeatherPtr->colorMapStepDelay = 0; } @@ -317,36 +309,38 @@ static u8 None_Finish(void) // towards the desired color map. static void UpdateWeatherColorMap(void) { - if (gWeatherPtr->colorMapIndex == gWeatherPtr->targetColorMapIndex) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT) { - gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; - } - else - { - if (++gWeatherPtr->colorMapStepCounter >= gWeatherPtr->colorMapStepDelay) + if (gWeatherPtr->colorMapIndex == gWeatherPtr->targetColorMapIndex) { - gWeatherPtr->colorMapStepCounter = 0; - if (gWeatherPtr->colorMapIndex < gWeatherPtr->targetColorMapIndex) - gWeatherPtr->colorMapIndex++; - else - gWeatherPtr->colorMapIndex--; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; + } + else + { + if (++gWeatherPtr->colorMapStepCounter >= gWeatherPtr->colorMapStepDelay) + { + gWeatherPtr->colorMapStepCounter = 0; + if (gWeatherPtr->colorMapIndex < gWeatherPtr->targetColorMapIndex) + gWeatherPtr->colorMapIndex++; + else + gWeatherPtr->colorMapIndex--; - ApplyColorMap(0, 32, gWeatherPtr->colorMapIndex); + ApplyColorMap(0, 32, gWeatherPtr->colorMapIndex); + } } } } static void FadeInScreenWithWeather(void) { - if (++gWeatherPtr->fadeInCounter > 1) - gWeatherPtr->fadeInActive = 0; + if (++gWeatherPtr->fadeInTimer > 1) + gWeatherPtr->fadeInFirstFrame = FALSE; switch (gWeatherPtr->currWeather) { case WEATHER_RAIN: case WEATHER_RAIN_THUNDERSTORM: case WEATHER_DOWNPOUR: - case WEATHER_SNOW: case WEATHER_SHADE: if (FadeInScreen_RainShowShade() == FALSE) { @@ -368,6 +362,7 @@ static void FadeInScreenWithWeather(void) gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; + case WEATHER_SNOW: case WEATHER_VOLCANIC_ASH: case WEATHER_SANDSTORM: case WEATHER_FOG_DIAGONAL: @@ -537,7 +532,7 @@ static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMap { u16 palOffset; u16 curPalIndex; - u16 i; + u32 i; struct RGBColor color = *(struct RGBColor *)&blendColor; u8 rBlend = color.r; u8 gBlend = color.g; @@ -555,7 +550,7 @@ static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMap UpdatePalettesWithTime(1 << (palOffset >> 4)); // Apply TOD blend if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE) { - // No gamma shift. Simply blend the colors. + // No color map. Simply blend the colors. BlendPalette(palOffset, 16, blendCoeff, blendColor); palOffset += 16; } @@ -575,11 +570,11 @@ static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMap u8 g = colorMap[baseColor.g]; u8 b = colorMap[baseColor.b]; - // Apply gamma shift and target blend color to the original color. + // Apply color map and target blend color to the original color. r += ((rBlend - r) * blendCoeff) >> 4; g += ((gBlend - g) * blendCoeff) >> 4; b += ((bBlend - b) * blendCoeff) >> 4; - gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; + gPlttBufferFaded[palOffset++] = RGB2(r, g, b); } } @@ -741,7 +736,6 @@ void FadeScreen(u8 mode, s8 delay) case WEATHER_RAIN: case WEATHER_RAIN_THUNDERSTORM: case WEATHER_DOWNPOUR: - case WEATHER_SNOW: case WEATHER_FOG_HORIZONTAL: case WEATHER_SHADE: case WEATHER_DROUGHT: @@ -780,8 +774,8 @@ void FadeScreen(u8 mode, s8 delay) BeginNormalPaletteFade(PALETTES_ALL, delay, 16, 0, fadeColor); gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_IN; - gWeatherPtr->fadeInActive = 1; - gWeatherPtr->fadeInCounter = 0; + gWeatherPtr->fadeInFirstFrame = TRUE; + gWeatherPtr->fadeInTimer = 0; Weather_SetBlendCoeffs(gWeatherPtr->currBlendEVA, gWeatherPtr->currBlendEVB); gWeatherPtr->readyForInit = TRUE; } @@ -848,8 +842,8 @@ void FadeSelectedPals(u8 mode, s8 delay, u32 selectedPalettes) BeginNormalPaletteFade(selectedPalettes, delay, 16, 0, fadeColor); gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_IN; - gWeatherPtr->fadeInActive = 1; - gWeatherPtr->fadeInCounter = 0; + gWeatherPtr->fadeInFirstFrame = TRUE; + gWeatherPtr->fadeInTimer = 0; Weather_SetBlendCoeffs(gWeatherPtr->currBlendEVA, gWeatherPtr->currBlendEVB); gWeatherPtr->readyForInit = TRUE; } @@ -869,7 +863,7 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex, bool32 allowFog) switch (gWeatherPtr->palProcessingState) { case WEATHER_PAL_STATE_SCREEN_FADING_IN: - if (gWeatherPtr->fadeInActive != 0) + if (gWeatherPtr->fadeInFirstFrame) { if (gWeatherPtr->currWeather == WEATHER_FOG_HORIZONTAL) MarkFogSpritePalToLighten(paletteIndex); @@ -961,7 +955,6 @@ void DroughtStateInit(void) gWeatherPtr->droughtTimer = 0; gWeatherPtr->droughtState = 0; gWeatherPtr->droughtLastBrightnessStage = 0; - sDroughtFrameDelay = 5; } void DroughtStateRun(void) @@ -970,7 +963,7 @@ void DroughtStateRun(void) { case 0: // Ramp up - if (++gWeatherPtr->droughtTimer > sDroughtFrameDelay) + if (++gWeatherPtr->droughtTimer > 5) { gWeatherPtr->droughtTimer = 0; SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage++); @@ -992,7 +985,7 @@ void DroughtStateRun(void) break; case 2: // Ramp down - if (++gWeatherPtr->droughtTimer > sDroughtFrameDelay) + if (++gWeatherPtr->droughtTimer > 5) { gWeatherPtr->droughtTimer = 0; SetDroughtColorMap(--gWeatherPtr->droughtBrightnessStage); @@ -1024,7 +1017,7 @@ void Weather_SetTargetBlendCoeffs(u8 eva, u8 evb, int delay) bool8 Weather_UpdateBlend(void) { if (gWeatherPtr->currBlendEVA == gWeatherPtr->targetBlendEVA - && gWeatherPtr->currBlendEVB == gWeatherPtr->targetBlendEVB) + && gWeatherPtr->currBlendEVB == gWeatherPtr->targetBlendEVB) return TRUE; if (++gWeatherPtr->blendFrameCounter > gWeatherPtr->blendDelay) @@ -1052,7 +1045,7 @@ bool8 Weather_UpdateBlend(void) SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(gWeatherPtr->currBlendEVA, gWeatherPtr->currBlendEVB)); if (gWeatherPtr->currBlendEVA == gWeatherPtr->targetBlendEVA - && gWeatherPtr->currBlendEVB == gWeatherPtr->targetBlendEVB) + && gWeatherPtr->currBlendEVB == gWeatherPtr->targetBlendEVB) return TRUE; return FALSE; @@ -1116,7 +1109,7 @@ void SetWeatherScreenFadeOut(void) gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_OUT; } -void WeatherProcessingIdle(void) +void SetWeatherPalStateIdle(void) { gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } diff --git a/src/field_weather_effects.c b/src/field_weather_effects.c index d18668545..20cf8d1e1 100644 --- a/src/field_weather_effects.c +++ b/src/field_weather_effects.c @@ -11,6 +11,18 @@ #include "task.h" #include "trig.h" +const u16 gCloudsWeatherPalette[] = INCBIN_U16("graphics/weather/cloud.gbapal"); +const u16 gSandstormWeatherPalette[] = INCBIN_U16("graphics/weather/sandstorm.gbapal"); +const u8 gWeatherFogDiagonalTiles[] = INCBIN_U8("graphics/weather/fog_diagonal.4bpp"); +const u8 gWeatherFogHorizontalTiles[] = INCBIN_U8("graphics/weather/fog_horizontal.4bpp"); +const u8 gWeatherCloudTiles[] = INCBIN_U8("graphics/weather/cloud.4bpp"); +const u8 gWeatherSnow1Tiles[] = INCBIN_U8("graphics/weather/snow0.4bpp"); +const u8 gWeatherSnow2Tiles[] = INCBIN_U8("graphics/weather/snow1.4bpp"); +const u8 gWeatherBubbleTiles[] = INCBIN_U8("graphics/weather/bubble.4bpp"); +const u8 gWeatherAshTiles[] = INCBIN_U8("graphics/weather/ash.4bpp"); +const u8 gWeatherRainTiles[] = INCBIN_U8("graphics/weather/rain.4bpp"); +const u8 gWeatherSandstormTiles[] = INCBIN_U8("graphics/weather/sandstorm.4bpp"); + //------------------------------------------------------------------------------ // WEATHER_SUNNY_CLOUDS //------------------------------------------------------------------------------ @@ -734,7 +746,7 @@ void Snow_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->targetColorMapIndex = 3; + gWeatherPtr->targetColorMapIndex = 0; gWeatherPtr->colorMapStepDelay = 20; gWeatherPtr->targetSnowflakeSpriteCount = NUM_SNOWFLAKE_SPRITES; gWeatherPtr->snowflakeVisibleCounter = 0; diff --git a/src/fldeff_sweetscent.c b/src/fldeff_sweetscent.c index c2615f47f..56296f3fa 100644 --- a/src/fldeff_sweetscent.c +++ b/src/fldeff_sweetscent.c @@ -85,7 +85,7 @@ static void FailSweetScentEncounter(u8 taskId) if (!gPaletteFade.active) { CpuFastCopy(sPlttBufferBak, gPlttBufferUnfaded, PLTT_SIZE); - WeatherProcessingIdle(); + SetWeatherPalStateIdle(); Free(sPlttBufferBak); ScriptContext_SetupScript(EventScript_FailSweetScent); DestroyTask(taskId);