Fix weather color map documentation

This commit is contained in:
Marcus Huderle 2022-10-16 13:06:43 -05:00
parent 716025395c
commit 48ab684b48
4 changed files with 222 additions and 213 deletions

View file

@ -19,6 +19,8 @@ enum {
PALTAG_WEATHER_2
};
#define NUM_WEATHER_COLOR_MAPS 19
struct Weather
{
union
@ -39,12 +41,12 @@ struct Weather
struct Sprite *sandstormSprites2[NUM_SWIRL_SANDSTORM_SPRITES];
} s2;
} sprites;
u8 gammaShifts[19][32];
u8 altGammaShifts[19][32];
s8 gammaIndex;
s8 gammaTargetIndex;
u8 gammaStepDelay;
u8 gammaStepFrameCounter;
u8 darkenedContrastColorMaps[NUM_WEATHER_COLOR_MAPS][32];
u8 contrastColorMaps[NUM_WEATHER_COLOR_MAPS][32];
s8 colorMapIndex;
s8 targetColorMapIndex;
u8 colorMapStepDelay;
u8 colorMapStepCounter;
u16 fadeDestColor;
u8 palProcessingState;
u8 fadeScreenCounter;
@ -59,7 +61,7 @@ struct Weather
u8 weatherGfxLoaded;
bool8 weatherChangeComplete;
u8 weatherPicSpritePalIndex;
u8 altGammaSpritePalIndex;
u8 contrastColorMapSpritePalIndex;
// Rain
u16 rainSpriteVisibleCounter;
u8 curRainSpriteIndex;
@ -146,12 +148,12 @@ void StartWeather(void);
void SetNextWeather(u8 weather);
void SetCurrentAndNextWeather(u8 weather);
void SetCurrentAndNextWeatherNoDelay(u8 weather);
void ApplyWeatherGammaShiftIfIdle(s8 gammaIndex);
void ApplyWeatherGammaShiftIfIdle_Gradual(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay);
void ApplyWeatherColorMapIfIdle(s8 colorMapIndex);
void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay);
void FadeScreen(u8 mode, s8 delay);
bool8 IsWeatherNotFadingIn(void);
void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex);
void ApplyWeatherGammaShiftToPal(u8 paletteIndex);
void ApplyWeatherColorMapToPal(u8 paletteIndex);
void LoadCustomWeatherSpritePalette(const u16 *palette);
void ResetDroughtWeatherPaletteLoading(void);
bool8 LoadDroughtWeatherPalettes(void);

View file

@ -21,9 +21,9 @@
enum
{
GAMMA_NONE,
GAMMA_NORMAL,
GAMMA_ALT,
COLOR_MAP_NONE,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_CONTRAST,
};
struct RGBColor
@ -33,11 +33,6 @@ struct RGBColor
u16 b:5;
};
struct WeatherPaletteData
{
u16 gammaShiftColors[8][0x1000]; // 0x1000 is the number of bytes that make up all palettes.
};
struct WeatherCallbacks
{
void (*initVars)(void);
@ -48,11 +43,11 @@ struct WeatherCallbacks
// This file's functions.
static bool8 LightenSpritePaletteInFog(u8);
static void BuildGammaShiftTables(void);
static void UpdateWeatherGammaShift(void);
static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex);
static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor);
static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor);
static void BuildColorMaps(void);
static void UpdateWeatherColorMap(void);
static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex);
static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor);
static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor);
static void ApplyFogBlend(u8 blendCoeff, u16 blendColor);
static bool8 FadeInScreen_RainShowShade(void);
static bool8 FadeInScreen_Drought(void);
@ -66,9 +61,9 @@ static void None_Main(void);
static u8 None_Finish(void);
EWRAM_DATA struct Weather gWeather = {0};
EWRAM_DATA static u8 sFieldEffectPaletteGammaTypes[32] = {0};
EWRAM_DATA static u8 sFieldEffectPaletteColorMapTypes[32] = {0};
static const u8 *sPaletteGammaTypes;
static const u8 *sPaletteColorMapTypes;
// The drought weather effect uses a precalculated color lookup table. Presumably this
// is because the underlying color shift calculation is slow.
@ -108,50 +103,50 @@ static const struct WeatherCallbacks sWeatherFuncs[] =
void (*const gWeatherPalStateFuncs[])(void) =
{
[WEATHER_PAL_STATE_CHANGING_WEATHER] = UpdateWeatherGammaShift,
[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,
};
// This table specifies which of the gamma shift tables should be
// This table specifies which of the color maps should be
// applied to each of the background and sprite palettes.
static const u8 sBasePaletteGammaTypes[32] =
static const u8 sBasePaletteColorMapTypes[32] =
{
// background palettes
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NONE,
GAMMA_NONE,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_NONE,
COLOR_MAP_NONE,
// sprite palettes
GAMMA_ALT,
GAMMA_NORMAL,
GAMMA_ALT,
GAMMA_ALT,
GAMMA_ALT,
GAMMA_ALT,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_ALT,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
GAMMA_NORMAL,
COLOR_MAP_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_CONTRAST,
COLOR_MAP_CONTRAST,
COLOR_MAP_CONTRAST,
COLOR_MAP_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
COLOR_MAP_DARK_CONTRAST,
};
const u16 gFogPalette[] = INCBIN_U16("graphics/weather/fog.gbapal");
@ -160,10 +155,10 @@ void StartWeather(void)
{
if (!FuncIsActiveTask(Task_WeatherMain))
{
u8 index = AllocSpritePalette(TAG_WEATHER_START);
u8 index = AllocSpritePalette(PALTAG_WEATHER);
CpuCopy32(gFogPalette, &gPlttBufferUnfaded[0x100 + index * 16], 32);
BuildGammaShiftTables();
gWeatherPtr->altGammaSpritePalIndex = index;
BuildColorMaps();
gWeatherPtr->contrastColorMapSpritePalIndex = index;
gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(PALTAG_WEATHER_2);
gWeatherPtr->rainSpriteCount = 0;
gWeatherPtr->curRainSpriteIndex = 0;
@ -238,7 +233,7 @@ static void Task_WeatherMain(u8 taskId)
{
// Finished cleaning up previous weather. Now transition to next weather.
sWeatherFuncs[gWeatherPtr->nextWeather].initVars();
gWeatherPtr->gammaStepFrameCounter = 0;
gWeatherPtr->colorMapStepCounter = 0;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER;
gWeatherPtr->currWeather = gWeatherPtr->nextWeather;
gWeatherPtr->weatherChangeComplete = TRUE;
@ -254,8 +249,8 @@ static void Task_WeatherMain(u8 taskId)
static void None_Init(void)
{
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 0;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 0;
}
static void None_Main(void)
@ -267,70 +262,82 @@ static u8 None_Finish(void)
return 0;
}
// Builds two tables that contain gamma shifts for palette colors.
// Builds two tables that contain color maps, used for directly transforming
// palette colors in weather effects. The colors maps are a spectrum of
// brightness + contrast mappings. By transitioning between the maps, weather
// effects like lightning are created.
// It's unclear why the two tables aren't declared as const arrays, since
// this function always builds the same two tables.
static void BuildGammaShiftTables(void)
static void BuildColorMaps(void)
{
u16 v0;
u8 (*gammaTable)[32];
u16 v2;
u16 v4;
u16 v5;
u16 gammaIndex;
u16 v9;
u32 v10;
u16 v11;
s16 dunno;
u16 i;
u8 (*colorMaps)[32];
u16 colorVal;
u16 curBrightness;
u16 brightnessDelta;
u16 colorMapIndex;
u16 baseBrightness;
u32 remainingBrightness;
s16 diff;
sPaletteGammaTypes = sBasePaletteGammaTypes;
for (v0 = 0; v0 <= 1; v0++)
sPaletteColorMapTypes = sBasePaletteColorMapTypes;
for (i = 0; i < 2; i++)
{
if (v0 == 0)
gammaTable = gWeatherPtr->gammaShifts;
if (i == 0)
colorMaps = gWeatherPtr->darkenedContrastColorMaps;
else
gammaTable = gWeatherPtr->altGammaShifts;
colorMaps = gWeatherPtr->contrastColorMaps;
for (v2 = 0; v2 < 32; v2++)
for (colorVal = 0; colorVal < 32; colorVal++)
{
v4 = v2 << 8;
if (v0 == 0)
v5 = (v2 << 8) / 16;
curBrightness = colorVal << 8;
if (i == 0)
brightnessDelta = (colorVal << 8) / 16;
else
v5 = 0;
for (gammaIndex = 0; gammaIndex <= 2; gammaIndex++)
brightnessDelta = 0;
// First three color mappings are simple brightness modifiers which are
// progressively darker, according to brightnessDelta.
for (colorMapIndex = 0; colorMapIndex < 3; colorMapIndex++)
{
v4 = (v4 - v5);
gammaTable[gammaIndex][v2] = v4 >> 8;
curBrightness -= brightnessDelta;
colorMaps[colorMapIndex][colorVal] = curBrightness >> 8;
}
v9 = v4;
v10 = 0x1f00 - v4;
if ((0x1f00 - v4) < 0)
baseBrightness = curBrightness;
remainingBrightness = 0x1f00 - curBrightness;
if ((0x1f00 - curBrightness) < 0)
remainingBrightness += 0xf;
brightnessDelta = remainingBrightness / (NUM_WEATHER_COLOR_MAPS - 3);
if (colorVal < 12)
{
v10 += 0xf;
}
v11 = v10 >> 4;
if (v2 < 12)
{
for (; gammaIndex < 19; gammaIndex++)
// For shadows (color values < 12), the remaining color mappings are
// brightness modifiers, which are increased at a significantly lower rate
// than the midtones and highlights (color values >= 12). This creates a
// high contrast effect, used in the thunderstorm weather.
for (; colorMapIndex < NUM_WEATHER_COLOR_MAPS; colorMapIndex++)
{
v4 += v11;
dunno = v4 - v9;
if (dunno > 0)
v4 -= (dunno + ((u16)dunno >> 15)) >> 1;
gammaTable[gammaIndex][v2] = v4 >> 8;
if (gammaTable[gammaIndex][v2] > 0x1f)
gammaTable[gammaIndex][v2] = 0x1f;
curBrightness += brightnessDelta;
diff = curBrightness - baseBrightness;
if (diff > 0)
curBrightness -= diff / 2;
colorMaps[colorMapIndex][colorVal] = curBrightness >> 8;
if (colorMaps[colorMapIndex][colorVal] > 31)
colorMaps[colorMapIndex][colorVal] = 31;
}
}
else
{
for (; gammaIndex < 19; gammaIndex++)
// For midtones and highlights (color values >= 12), the remaining
// color mappings are simple brightness modifiers which are
// progressively brighter, hitting exactly 31 at the last mapping.
for (; colorMapIndex < NUM_WEATHER_COLOR_MAPS; colorMapIndex++)
{
v4 += v11;
gammaTable[gammaIndex][v2] = v4 >> 8;
if (gammaTable[gammaIndex][v2] > 0x1f)
gammaTable[gammaIndex][v2] = 0x1f;
curBrightness += brightnessDelta;
colorMaps[colorMapIndex][colorVal] = curBrightness >> 8;
if (colorMaps[colorMapIndex][colorVal] > 31)
colorMaps[colorMapIndex][colorVal] = 31;
}
}
}
@ -338,26 +345,26 @@ static void BuildGammaShiftTables(void)
}
// When the weather is changing, it gradually updates the palettes
// towards the desired gamma shift.
static void UpdateWeatherGammaShift(void)
// towards the desired color map.
static void UpdateWeatherColorMap(void)
{
if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT)
{
if (gWeatherPtr->gammaIndex == gWeatherPtr->gammaTargetIndex)
if (gWeatherPtr->colorMapIndex == gWeatherPtr->targetColorMapIndex)
{
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
else
{
if (++gWeatherPtr->gammaStepFrameCounter >= gWeatherPtr->gammaStepDelay)
if (++gWeatherPtr->colorMapStepCounter >= gWeatherPtr->colorMapStepDelay)
{
gWeatherPtr->gammaStepFrameCounter = 0;
if (gWeatherPtr->gammaIndex < gWeatherPtr->gammaTargetIndex)
gWeatherPtr->gammaIndex++;
gWeatherPtr->colorMapStepCounter = 0;
if (gWeatherPtr->colorMapIndex < gWeatherPtr->targetColorMapIndex)
gWeatherPtr->colorMapIndex++;
else
gWeatherPtr->gammaIndex--;
gWeatherPtr->colorMapIndex--;
ApplyGammaShift(0, 32, gWeatherPtr->gammaIndex);
ApplyColorMap(0, 32, gWeatherPtr->colorMapIndex);
}
}
}
@ -377,21 +384,21 @@ static void FadeInScreenWithWeather(void)
case WEATHER_SHADE:
if (FadeInScreen_RainShowShade() == FALSE)
{
gWeatherPtr->gammaIndex = 3;
gWeatherPtr->colorMapIndex = 3;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
case WEATHER_DROUGHT:
if (FadeInScreen_Drought() == FALSE)
{
gWeatherPtr->gammaIndex = -6;
gWeatherPtr->colorMapIndex = -6;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
case WEATHER_FOG_HORIZONTAL:
if (FadeInScreen_FogHorizontal() == FALSE)
{
gWeatherPtr->gammaIndex = 0;
gWeatherPtr->colorMapIndex = 0;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
@ -402,7 +409,7 @@ static void FadeInScreenWithWeather(void)
default:
if (!gPaletteFade.active)
{
gWeatherPtr->gammaIndex = gWeatherPtr->gammaTargetIndex;
gWeatherPtr->colorMapIndex = gWeatherPtr->targetColorMapIndex;
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE;
}
break;
@ -416,12 +423,12 @@ static bool8 FadeInScreen_RainShowShade(void)
if (++gWeatherPtr->fadeScreenCounter >= 16)
{
ApplyGammaShift(0, 32, 3);
ApplyColorMap(0, 32, 3);
gWeatherPtr->fadeScreenCounter = 16;
return FALSE;
}
ApplyGammaShiftWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
ApplyColorMapWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
return TRUE;
}
@ -432,12 +439,12 @@ static bool8 FadeInScreen_Drought(void)
if (++gWeatherPtr->fadeScreenCounter >= 16)
{
ApplyGammaShift(0, 32, -6);
ApplyColorMap(0, 32, -6);
gWeatherPtr->fadeScreenCounter = 16;
return FALSE;
}
ApplyDroughtGammaShiftWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
ApplyDroughtColorMapWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor);
return TRUE;
}
@ -454,24 +461,24 @@ static bool8 FadeInScreen_FogHorizontal(void)
static void DoNothing(void)
{ }
static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex)
{
u16 curPalIndex;
u16 palOffset;
u8 *gammaTable;
u8 *colorMap;
u16 i;
if (gammaIndex > 0)
if (colorMapIndex > 0)
{
gammaIndex--;
colorMapIndex--;
palOffset = startPalIndex * 16;
numPalettes += startPalIndex;
curPalIndex = startPalIndex;
// Loop through the speficied palette range and apply necessary gamma shifts to the colors.
// Loop through the specified palette range and apply necessary color maps.
while (curPalIndex < numPalettes)
{
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE)
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{
// No palette change.
CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16));
@ -481,18 +488,18 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
{
u8 r, g, b;
if (sPaletteGammaTypes[curPalIndex] == GAMMA_ALT || curPalIndex - 16 == gWeatherPtr->altGammaSpritePalIndex)
gammaTable = gWeatherPtr->altGammaShifts[gammaIndex];
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_CONTRAST || curPalIndex - 16 == gWeatherPtr->contrastColorMapSpritePalIndex)
colorMap = gWeatherPtr->contrastColorMaps[colorMapIndex];
else
gammaTable = gWeatherPtr->gammaShifts[gammaIndex];
colorMap = gWeatherPtr->darkenedContrastColorMaps[colorMapIndex];
for (i = 0; i < 16; i++)
{
// Apply gamma shift to the original color.
// Apply color map to the original color.
struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
r = gammaTable[baseColor.r];
g = gammaTable[baseColor.g];
b = gammaTable[baseColor.b];
r = colorMap[baseColor.r];
g = colorMap[baseColor.g];
b = colorMap[baseColor.b];
gPlttBufferFaded[palOffset++] = RGB2(r, g, b);
}
}
@ -500,17 +507,17 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
curPalIndex++;
}
}
else if (gammaIndex < 0)
else if (colorMapIndex < 0)
{
// A negative gammIndex value means that the blending will come from the special Drought weather's palette tables.
gammaIndex = -gammaIndex - 1;
colorMapIndex = -colorMapIndex - 1;
palOffset = startPalIndex * 16;
numPalettes += startPalIndex;
curPalIndex = startPalIndex;
while (curPalIndex < numPalettes)
{
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE)
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_NONE)
{
// No palette change.
CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16));
@ -520,7 +527,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
{
for (i = 0; i < 16; i++)
{
gPlttBufferFaded[palOffset] = sDroughtWeatherColors[gammaIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[palOffset])];
gPlttBufferFaded[palOffset] = sDroughtWeatherColors[colorMapIndex][DROUGHT_COLOR_INDEX(gPlttBufferUnfaded[palOffset])];
palOffset++;
}
}
@ -535,7 +542,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
}
}
static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor)
static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor)
{
u16 palOffset;
u16 curPalIndex;
@ -547,34 +554,34 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
palOffset = startPalIndex * 16;
numPalettes += startPalIndex;
gammaIndex--;
colorMapIndex--;
curPalIndex = startPalIndex;
while (curPalIndex < numPalettes)
{
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE)
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;
}
else
{
u8 *gammaTable;
u8 *colorMap;
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NORMAL)
gammaTable = gWeatherPtr->gammaShifts[gammaIndex];
if (sPaletteColorMapTypes[curPalIndex] == COLOR_MAP_DARK_CONTRAST)
colorMap = gWeatherPtr->darkenedContrastColorMaps[colorMapIndex];
else
gammaTable = gWeatherPtr->altGammaShifts[gammaIndex];
colorMap = gWeatherPtr->contrastColorMaps[colorMapIndex];
for (i = 0; i < 16; i++)
{
struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset];
u8 r = gammaTable[baseColor.r];
u8 g = gammaTable[baseColor.g];
u8 b = gammaTable[baseColor.b];
u8 r = colorMap[baseColor.r];
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;
@ -586,7 +593,7 @@ static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaI
}
}
static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor)
static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor)
{
struct RGBColor color;
u8 rBlend;
@ -596,7 +603,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
u16 palOffset;
u16 i;
gammaIndex = -gammaIndex - 1;
colorMapIndex = -colorMapIndex - 1;
color = *(struct RGBColor *)&blendColor;
rBlend = color.r;
gBlend = color.g;
@ -604,9 +611,9 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
palOffset = 0;
for (curPalIndex = 0; curPalIndex < 32; curPalIndex++)
{
if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE)
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;
}
@ -626,7 +633,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
b1 = color1.b;
offset = ((b1 & 0x1E) << 7) | ((g1 & 0x1E) << 3) | ((r1 & 0x1E) >> 1);
color2 = *(struct RGBColor *)&sDroughtWeatherColors[gammaIndex][offset];
color2 = *(struct RGBColor *)&sDroughtWeatherColors[colorMapIndex][offset];
r2 = color2.r;
g2 = color2.g;
b2 = color2.b;
@ -710,25 +717,25 @@ static bool8 LightenSpritePaletteInFog(u8 paletteIndex)
return FALSE;
}
void ApplyWeatherGammaShiftIfIdle(s8 gammaIndex)
void ApplyWeatherColorMapIfIdle(s8 colorMapIndex)
{
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{
ApplyGammaShift(0, 32, gammaIndex);
gWeatherPtr->gammaIndex = gammaIndex;
ApplyColorMap(0, 32, colorMapIndex);
gWeatherPtr->colorMapIndex = colorMapIndex;
}
}
void ApplyWeatherGammaShiftIfIdle_Gradual(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay)
void ApplyWeatherColorMapIfIdle_Gradual(u8 colorMapIndex, u8 targetColorMapIndex, u8 colorMapStepDelay)
{
if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE)
{
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER;
gWeatherPtr->gammaIndex = gammaIndex;
gWeatherPtr->gammaTargetIndex = gammaTargetIndex;
gWeatherPtr->gammaStepFrameCounter = 0;
gWeatherPtr->gammaStepDelay = gammaStepDelay;
ApplyWeatherGammaShiftIfIdle(gammaIndex);
gWeatherPtr->colorMapIndex = colorMapIndex;
gWeatherPtr->targetColorMapIndex = targetColorMapIndex;
gWeatherPtr->colorMapStepCounter = 0;
gWeatherPtr->colorMapStepDelay = colorMapStepDelay;
ApplyWeatherColorMapIfIdle(colorMapIndex);
}
}
@ -832,7 +839,7 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex)
default:
if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL)
{
ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex);
ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex);
}
else
{
@ -843,9 +850,9 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex)
}
}
void ApplyWeatherGammaShiftToPal(u8 paletteIndex)
void ApplyWeatherColorMapToPal(u8 paletteIndex)
{
ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex);
ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex);
}
// Unused
@ -886,9 +893,9 @@ bool8 LoadDroughtWeatherPalettes(void)
return FALSE;
}
static void SetDroughtGamma(s8 gammaIndex)
static void SetDroughtColorMap(s8 colorMapIndex)
{
ApplyWeatherGammaShiftIfIdle(-gammaIndex - 1);
ApplyWeatherColorMapIfIdle(-colorMapIndex - 1);
}
void DroughtStateInit(void)
@ -907,7 +914,7 @@ void DroughtStateRun(void)
if (++gWeatherPtr->droughtTimer > 5)
{
gWeatherPtr->droughtTimer = 0;
SetDroughtGamma(gWeatherPtr->droughtBrightnessStage++);
SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage++);
if (gWeatherPtr->droughtBrightnessStage > 5)
{
gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage;
@ -920,14 +927,14 @@ void DroughtStateRun(void)
gWeatherPtr->droughtTimer = (gWeatherPtr->droughtTimer + 3) & 0x7F;
gWeatherPtr->droughtBrightnessStage = ((gSineTable[gWeatherPtr->droughtTimer] - 1) >> 6) + 2;
if (gWeatherPtr->droughtBrightnessStage != gWeatherPtr->droughtLastBrightnessStage)
SetDroughtGamma(gWeatherPtr->droughtBrightnessStage);
SetDroughtColorMap(gWeatherPtr->droughtBrightnessStage);
gWeatherPtr->droughtLastBrightnessStage = gWeatherPtr->droughtBrightnessStage;
break;
case 2:
if (++gWeatherPtr->droughtTimer > 5)
{
gWeatherPtr->droughtTimer = 0;
SetDroughtGamma(--gWeatherPtr->droughtBrightnessStage);
SetDroughtColorMap(--gWeatherPtr->droughtBrightnessStage);
if (gWeatherPtr->droughtBrightnessStage == 3)
gWeatherPtr->droughtState = 0;
}
@ -1093,12 +1100,12 @@ void SetWeatherPalStateIdle(void)
void PreservePaletteInWeather(u8 preservedPalIndex)
{
CpuCopy16(sBasePaletteGammaTypes, sFieldEffectPaletteGammaTypes, 32);
sFieldEffectPaletteGammaTypes[preservedPalIndex] = GAMMA_NONE;
sPaletteGammaTypes = sFieldEffectPaletteGammaTypes;
CpuCopy16(sBasePaletteColorMapTypes, sFieldEffectPaletteColorMapTypes, 32);
sFieldEffectPaletteColorMapTypes[preservedPalIndex] = COLOR_MAP_NONE;
sPaletteColorMapTypes = sFieldEffectPaletteColorMapTypes;
}
void ResetPreservedPalettesInWeather(void)
{
sPaletteGammaTypes = sBasePaletteGammaTypes;
sPaletteColorMapTypes = sBasePaletteColorMapTypes;
}

View file

@ -94,8 +94,8 @@ static const struct SpriteTemplate sCloudSpriteTemplate =
void Clouds_InitVars(void)
{
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->initStep = 0;
if (gWeatherPtr->cloudSpritesCreated == FALSE)
@ -152,8 +152,8 @@ bool8 Clouds_Finish(void)
void Sunny_InitVars(void)
{
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
}
void Sunny_InitAll(void)
@ -235,8 +235,8 @@ void Drought_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 0;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 0;
}
void Drought_InitAll(void)
@ -476,8 +476,8 @@ void Rain_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 8;
gWeatherPtr->isDownpour = FALSE;
gWeatherPtr->targetRainSpriteCount = 10;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
SetRainStrengthFromSoundEffect(SE_RAIN);
}
@ -768,8 +768,8 @@ void Snow_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->targetSnowflakeSpriteCount = 16;
gWeatherPtr->snowflakeVisibleCounter = 0;
}
@ -1042,8 +1042,8 @@ void Thunderstorm_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 4;
gWeatherPtr->isDownpour = FALSE;
gWeatherPtr->targetRainSpriteCount = 16;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
gWeatherPtr->thunderTriggered = FALSE;
SetRainStrengthFromSoundEffect(SE_THUNDERSTORM);
@ -1071,8 +1071,8 @@ void Downpour_InitVars(void)
gWeatherPtr->rainSpriteVisibleDelay = 4;
gWeatherPtr->isDownpour = TRUE;
gWeatherPtr->targetRainSpriteCount = 24;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment
SetRainStrengthFromSoundEffect(SE_DOWNPOUR);
}
@ -1128,7 +1128,7 @@ void Thunderstorm_Main(void)
gWeatherPtr->initStep++;
// fall through
case TSTORM_STATE_TRY_THUNDER_SHORT:
ApplyWeatherGammaShiftIfIdle(19);
ApplyWeatherColorMapIfIdle(19);
if (!gWeatherPtr->thunderSkipShort && gWeatherPtr->thunderShortRetries == 1)
SetThunderCounter(20); // Do short thunder
@ -1138,7 +1138,7 @@ void Thunderstorm_Main(void)
case TSTORM_STATE_TRY_NEW_THUNDER:
if (--gWeatherPtr->thunderDelay == 0)
{
ApplyWeatherGammaShiftIfIdle(3);
ApplyWeatherColorMapIfIdle(3);
gWeatherPtr->thunderAllowEnd = TRUE;
if (--gWeatherPtr->thunderShortRetries != 0)
{
@ -1171,7 +1171,7 @@ void Thunderstorm_Main(void)
{
// Do long thunder
SetThunderCounter(100);
ApplyWeatherGammaShiftIfIdle(19);
ApplyWeatherColorMapIfIdle(19);
gWeatherPtr->thunderDelay = (Random() & 0xF) + 30;
gWeatherPtr->initStep++;
}
@ -1179,7 +1179,7 @@ void Thunderstorm_Main(void)
case TSTORM_STATE_FADE_THUNDER_LONG:
if (--gWeatherPtr->thunderDelay == 0)
{
ApplyWeatherGammaShiftIfIdle_Gradual(19, 3, 5);
ApplyWeatherColorMapIfIdle_Gradual(19, 3, 5);
gWeatherPtr->initStep++;
}
break;
@ -1361,8 +1361,8 @@ void FogHorizontal_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
if (gWeatherPtr->fogHSpritesCreated == 0)
{
gWeatherPtr->fogHScrollCounter = 0;
@ -1516,8 +1516,8 @@ void Ash_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = FALSE;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->ashUnused = 20; // Never read
if (!gWeatherPtr->ashSpritesCreated)
{
@ -1726,8 +1726,8 @@ void FogDiagonal_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = 0;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
gWeatherPtr->fogHScrollCounter = 0;
gWeatherPtr->fogHScrollOffset = 1;
if (!gWeatherPtr->fogDSpritesCreated)
@ -1940,8 +1940,8 @@ void Sandstorm_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->weatherGfxLoaded = 0;
gWeatherPtr->gammaTargetIndex = 0;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 0;
gWeatherPtr->colorMapStepDelay = 20;
if (!gWeatherPtr->sandstormSpritesCreated)
{
gWeatherPtr->sandstormXOffset = gWeatherPtr->sandstormYOffset = 0;
@ -2237,8 +2237,8 @@ static void UpdateSandstormSwirlSprite(struct Sprite *sprite)
void Shade_InitVars(void)
{
gWeatherPtr->initStep = 0;
gWeatherPtr->gammaTargetIndex = 3;
gWeatherPtr->gammaStepDelay = 20;
gWeatherPtr->targetColorMapIndex = 3;
gWeatherPtr->colorMapStepDelay = 20;
}
void Shade_InitAll(void)

View file

@ -813,7 +813,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
LoadSecondaryTilesetPalette(gMapHeader.mapLayout);
for (paletteIndex = 6; paletteIndex < 13; paletteIndex++)
ApplyWeatherGammaShiftToPal(paletteIndex);
ApplyWeatherColorMapToPal(paletteIndex);
InitSecondaryTilesetAnimation();
UpdateLocationHistoryForRoamer();