From 7d8e63a44b8a7654055cf564971fd744b5e87d7d Mon Sep 17 00:00:00 2001 From: Ariel Antonitis Date: Sun, 25 Apr 2021 23:50:29 -0400 Subject: [PATCH] Reverted 42d5fe07f and fixed rain/thunder gamma. --- src/field_weather.c | 24 ++++++++++++++---------- src/field_weather_effect.c | 8 +++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/field_weather.c b/src/field_weather.c index 1f275a3df6..205b4f7f22 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -468,19 +468,23 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex) { gammaIndex--; palOffset = startPalIndex * 16; + CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 32 * numPalettes); numPalettes += startPalIndex; + // Thunder gamma-shift looks bad on night-blended palettes, so ignore time blending in some situations + if (!(gammaIndex > 3 && gWeatherPtr->currWeather == WEATHER_RAIN_THUNDERSTORM)) { + // Create the palette mask + u32 palettes = PALETTES_ALL; + palettes = (palettes >> startPalIndex) << startPalIndex; + palettes = (palettes << (32-numPalettes)) >> (32-numPalettes); + UpdatePalettesWithTime(palettes); + } curPalIndex = startPalIndex; - // Loop through the speficied palette range and apply necessary gamma shifts to the colors. - // TODO: Optimize this to work with time blending while (curPalIndex < numPalettes) { - CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); - UpdatePalettesWithTime(1 << (palOffset >> 4)); if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { // No palette change. - // CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); palOffset += 16; } else @@ -537,11 +541,11 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex) else { if (MapHasNaturalLight(gMapHeader.mapType)) { // Time-blend - u32 palettes = 0; - u32 mask = 1 << startPalIndex; - u8 i; - for (i = 0; i < numPalettes; i++, mask <<= 1) - palettes |= mask; + // Create the palette mask + u32 palettes = PALETTES_ALL; + numPalettes += startPalIndex; + palettes = (palettes >> startPalIndex) << startPalIndex; + palettes = (palettes << (32-numPalettes)) >> (32-numPalettes); UpdatePalettesWithTime(palettes); } else { // copy CpuFastCopy(gPlttBufferUnfaded + startPalIndex * 16, gPlttBufferFaded + startPalIndex * 16, numPalettes * 16 * sizeof(u16)); diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index e22f04b741..dad6490317 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -483,7 +483,7 @@ void Rain_InitVars(void) gWeatherPtr->rainSpriteVisibleDelay = 8; gWeatherPtr->isDownpour = FALSE; gWeatherPtr->targetRainSpriteCount = 10; - gWeatherPtr->gammaTargetIndex = gTimeOfDay == TIME_OF_DAY_DAY ? 3 : 0; + gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->gammaStepDelay = 20; SetRainStrengthFromSoundEffect(SE_RAIN); Weather_SetBlendCoeffs(8, 12); // preserve shadow darkness @@ -1053,7 +1053,7 @@ void Thunderstorm_InitVars(void) gWeatherPtr->rainSpriteVisibleDelay = 4; gWeatherPtr->isDownpour = FALSE; gWeatherPtr->targetRainSpriteCount = 16; - gWeatherPtr->gammaTargetIndex = gTimeOfDay == TIME_OF_DAY_DAY ? 3 : 0; + gWeatherPtr->gammaTargetIndex = 3; gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment gWeatherPtr->thunderTriggered = FALSE; @@ -1154,8 +1154,6 @@ void Thunderstorm_Main(void) if (--gWeatherPtr->thunderDelay == 0) { ApplyWeatherGammaShiftIfIdle(3); - if (gTimeOfDay != TIME_OF_DAY_DAY) - UpdatePalettesWithTime(0xFFFFFFFF); gWeatherPtr->thunderAllowEnd = TRUE; if (--gWeatherPtr->thunderShortRetries != 0) { @@ -1196,7 +1194,7 @@ void Thunderstorm_Main(void) case TSTORM_STATE_FADE_THUNDER_LONG: if (--gWeatherPtr->thunderDelay == 0) { - gTimeOfDay == TIME_OF_DAY_DAY ? sub_80ABC7C(19, 3, 5) : UpdatePalettesWithTime(0xFFFFFFFF); + sub_80ABC7C(19, 3, 5); gWeatherPtr->initStep++; } break;