More review addressing

This commit is contained in:
Eduardo Quezada 2025-01-17 18:47:38 -03:00
parent c363c28b22
commit ffc8903f93
11 changed files with 35 additions and 36 deletions

View File

@ -24,6 +24,8 @@
#define FADE_FROM_WHITE 2
#define FADE_TO_WHITE 3
// Shadows values
#define BASE_SHADOW_INTENSITY (16 - OW_SHADOW_INTENSITY)
#define SHADOW_COLOR_INDEX 9 // Within the weather palette, shadow sprites' color index
#endif // GUARD_CONSTANTS_FIELD_WEATHER_H

View File

@ -43,8 +43,8 @@ struct LinkPlayerObjectEvent
struct __attribute__((packed)) TimeBlendSettings
{
u16 weight:9;
u16 time1:3;
u16 time0:3;
u16 finalTimeOfDay:3;
u16 initialTimeOfDay:3;
u16 unused:1;
u16 altWeight;
};

View File

@ -3916,7 +3916,7 @@ void Task_BattleTransition_Intro(u8 taskId)
static bool8 TransitionIntro_FadeToGray(struct Task *task)
{
u8 paletteNum = IndexOfSpritePaletteTag(TAG_WEATHER_START);
u16 index = OBJ_PLTT_ID(paletteNum) + 9; // SHADOW_COLOR_INDEX
u16 index = OBJ_PLTT_ID(paletteNum) + SHADOW_COLOR_INDEX;
if (task->tDelayTimer == 0 || --task->tDelayTimer == 0)
{
task->tDelayTimer = task->tFadeToGrayDelay;
@ -3957,7 +3957,7 @@ static bool8 TransitionIntro_FadeFromGray(struct Task *task)
SetGpuReg(REG_OFFSET_BLDCNT, task->tBldCntSaved);
if (paletteNum < 16)
{
u16 index = OBJ_PLTT_ID(paletteNum) + 9; // SHADOW_COLOR_INDEX
u16 index = OBJ_PLTT_ID(paletteNum) + SHADOW_COLOR_INDEX;
gPlttBufferFaded[index] = task->tShadowColor;
}
}

View File

@ -781,8 +781,8 @@ void FadeScreen(u8 mode, s8 delay)
{
UpdateAltBgPalettes(PALETTES_BG);
BeginTimeOfDayPaletteFade(PALETTES_ALL, delay, 16, 0,
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0],
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1],
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.initialTimeOfDay],
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.finalTimeOfDay],
currentTimeBlend.weight, fadeColor);
}
else

View File

@ -1355,9 +1355,6 @@ void FogHorizontal_Main(void);
static void CreateFogHorizontalSprites(void);
static void DestroyFogHorizontalSprites(void);
// Within the weather palette, shadow sprites' color index
#define SHADOW_COLOR_INDEX 9
// Updates just the color of shadows to match special weather blending
u8 UpdateShadowColor(u16 color)
{

View File

@ -1562,32 +1562,32 @@ void UpdateTimeOfDay(void)
if (IsBetweenHours(hours, MORNING_HOUR_BEGIN, MORNING_HOUR_MIDDLE)) // night->morning
{
currentTimeBlend.time0 = TIME_NIGHT;
currentTimeBlend.time1 = TIME_MORNING;
currentTimeBlend.initialTimeOfDay = TIME_NIGHT;
currentTimeBlend.finalTimeOfDay = TIME_MORNING;
currentTimeBlend.weight = TIME_BLEND_WEIGHT(MORNING_HOUR_BEGIN, MORNING_HOUR_MIDDLE);
currentTimeBlend.altWeight = (DEFAULT_WEIGHT - currentTimeBlend.weight) / 2;
gTimeOfDay = TIME_MORNING;
}
else if (IsBetweenHours(hours, MORNING_HOUR_MIDDLE, MORNING_HOUR_END)) // morning->day
{
currentTimeBlend.time0 = TIME_MORNING;
currentTimeBlend.time1 = TIME_DAY;
currentTimeBlend.initialTimeOfDay = TIME_MORNING;
currentTimeBlend.finalTimeOfDay = TIME_DAY;
currentTimeBlend.weight = TIME_BLEND_WEIGHT(MORNING_HOUR_MIDDLE, MORNING_HOUR_END);
currentTimeBlend.altWeight = (DEFAULT_WEIGHT - currentTimeBlend.weight) / 2 + (DEFAULT_WEIGHT / 2);
gTimeOfDay = TIME_MORNING;
}
else if (IsBetweenHours(hours, EVENING_HOUR_BEGIN, EVENING_HOUR_END)) // evening
{
currentTimeBlend.time0 = TIME_DAY;
currentTimeBlend.time1 = TIME_EVENING;
currentTimeBlend.initialTimeOfDay = TIME_DAY;
currentTimeBlend.finalTimeOfDay = TIME_EVENING;
currentTimeBlend.weight = TIME_BLEND_WEIGHT(EVENING_HOUR_BEGIN, EVENING_HOUR_END);
currentTimeBlend.altWeight = currentTimeBlend.weight / 2 + (DEFAULT_WEIGHT / 2);
gTimeOfDay = TIME_EVENING;
}
else if (IsBetweenHours(hours, NIGHT_HOUR_BEGIN, NIGHT_HOUR_BEGIN + 1)) // evening->night
{
currentTimeBlend.time0 = TIME_EVENING;
currentTimeBlend.time1 = TIME_NIGHT;
currentTimeBlend.initialTimeOfDay = TIME_EVENING;
currentTimeBlend.finalTimeOfDay = TIME_NIGHT;
currentTimeBlend.weight = TIME_BLEND_WEIGHT(NIGHT_HOUR_BEGIN, NIGHT_HOUR_BEGIN + 1);
currentTimeBlend.altWeight = currentTimeBlend.weight / 2;
gTimeOfDay = TIME_NIGHT;
@ -1596,12 +1596,12 @@ void UpdateTimeOfDay(void)
{
currentTimeBlend.weight = DEFAULT_WEIGHT;
currentTimeBlend.altWeight = 0;
gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_NIGHT;
gTimeOfDay = currentTimeBlend.initialTimeOfDay = currentTimeBlend.finalTimeOfDay = TIME_NIGHT;
}
else // day
{
currentTimeBlend.weight = currentTimeBlend.altWeight = DEFAULT_WEIGHT;
gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_DAY;
gTimeOfDay = currentTimeBlend.initialTimeOfDay = currentTimeBlend.finalTimeOfDay = TIME_DAY;
}
}
@ -1661,7 +1661,7 @@ void UpdatePalettesWithTime(u32 palettes)
palettes &= PALETTES_MAP | PALETTES_OBJECTS; // Don't blend UI pals
if (!palettes)
return;
TimeMixPalettes(palettes, gPlttBufferUnfaded, gPlttBufferFaded, (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0], (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1], currentTimeBlend.weight);
TimeMixPalettes(palettes, gPlttBufferUnfaded, gPlttBufferFaded, (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.initialTimeOfDay], (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.finalTimeOfDay], currentTimeBlend.weight);
}
}
@ -1671,7 +1671,7 @@ u8 UpdateSpritePaletteWithTime(u8 paletteNum)
{
if (IS_BLEND_IMMUNE_TAG(GetSpritePaletteTagByPaletteNum(paletteNum)))
return paletteNum;
TimeMixPalettes(1, &gPlttBufferUnfaded[OBJ_PLTT_ID(paletteNum)], &gPlttBufferFaded[OBJ_PLTT_ID(paletteNum)], (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0], (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1], currentTimeBlend.weight
TimeMixPalettes(1, &gPlttBufferUnfaded[OBJ_PLTT_ID(paletteNum)], &gPlttBufferFaded[OBJ_PLTT_ID(paletteNum)], (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.initialTimeOfDay], (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.finalTimeOfDay], currentTimeBlend.weight
);
}
return paletteNum;
@ -1692,15 +1692,15 @@ static void OverworldBasic(void)
if (!gPaletteFade.active && ++gTimeUpdateCounter >= (SECONDS_PER_MINUTE * 60 / FakeRtc_GetSecondsRatio()))
{
struct TimeBlendSettings cachedBlend = {
.time0 = currentTimeBlend.time0,
.time1 = currentTimeBlend.time1,
.initialTimeOfDay = currentTimeBlend.initialTimeOfDay,
.finalTimeOfDay = currentTimeBlend.finalTimeOfDay,
.weight = currentTimeBlend.weight,
};
gTimeUpdateCounter = 0;
UpdateTimeOfDay();
FormChangeTimeUpdate();
if (cachedBlend.time0 != currentTimeBlend.time0
|| cachedBlend.time1 != currentTimeBlend.time1
if (cachedBlend.initialTimeOfDay != currentTimeBlend.initialTimeOfDay
|| cachedBlend.finalTimeOfDay != currentTimeBlend.finalTimeOfDay
|| cachedBlend.weight != currentTimeBlend.weight)
{
UpdateAltBgPalettes(PALETTES_BG);

View File

@ -244,7 +244,7 @@ static u8 UpdateTimeOfDayPaletteFade(void)
if (gPaletteFade.delayCounter < gPaletteFade_delay)
{
gPaletteFade.delayCounter++;
return 2;
return PALETTE_FADE_STATUS_DELAY;
}
gPaletteFade.delayCounter = 0;
}
@ -284,8 +284,8 @@ static u8 UpdateTimeOfDayPaletteFade(void)
// palettes that were not blended above must be copied through
if ((copyPalettes = ~timePalettes))
{
u16 * src1 = src;
u16 * dst1 = dst;
u16 *src1 = src;
u16 *dst1 = dst;
while (copyPalettes)
{
if (copyPalettes & 1)
@ -355,7 +355,7 @@ static u32 UpdateNormalPaletteFade(void)
if (gPaletteFade.delayCounter < gPaletteFade_delay)
{
gPaletteFade.delayCounter++;
return 2;
return PALETTE_FADE_STATUS_DELAY;
}
gPaletteFade.delayCounter = 0;
}
@ -870,14 +870,14 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble
u32 defaultColor = DEFAULT_LIGHT_COLOR;
if (!palettes)
return;
return;
color0 = blend0->blendColor;
tint0 = blend0->isTint;
coeff0 = tint0 ? 8*2 : blend0->coeff*2;
coeff0 = tint0 ? 16 : blend0->coeff * 2;
color1 = blend1->blendColor;
tint1 = blend1->isTint;
coeff1 = tint1 ? 8*2 : blend1->coeff*2;
coeff1 = tint1 ? 16 : blend1->coeff * 2;
if (tint0)
{

View File

@ -387,7 +387,7 @@ void UpdatePulseBlend(struct PulseBlend *pulseBlend)
pulseBlendPalette->delayCounter = pulseBlendPalette->pulseBlendSettings.delay;
CpuFastCopy(gPlttBufferUnfaded + pulseBlendPalette->pulseBlendSettings.paletteOffset, gPlttBufferFaded + pulseBlendPalette->pulseBlendSettings.paletteOffset, PLTT_SIZE_4BPP);
UpdatePalettesWithTime(1 << (pulseBlendPalette->pulseBlendSettings.paletteOffset >> 4));
// pulseBlendSettings has a numColors field, but it is only ever set to 16 (for mirage tower)
// pulseBlendSettings has a numColors field, but it is only ever set to 16 (for Mirage tower)
// So, it's ok to use the fine blending here which blends the entire palette
BlendPalettesFine(1, gPlttBufferFaded + pulseBlendPalette->pulseBlendSettings.paletteOffset, gPlttBufferFaded + pulseBlendPalette->pulseBlendSettings.paletteOffset, pulseBlendPalette->blendCoeff, pulseBlendPalette->pulseBlendSettings.blendColor);
switch (pulseBlendPalette->pulseBlendSettings.fadeType)

View File

@ -1481,6 +1481,7 @@ u16 LoadSpriteSheetByTemplateWithOffset(const struct SpriteTemplate *template, u
sheet.tag = template->tileTag;
return LoadSpriteSheetWithOffset(&sheet, offset);
}
// Like LoadSpriteSheet, but checks if already, and uses template image frames
u16 LoadSpriteSheetByTemplate(const struct SpriteTemplate *template, u8 frame)
{

View File

@ -228,7 +228,7 @@ u32 CalcByteArraySum(const u8 *data, u32 length)
void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u32 blendColor)
{
u16 i;
struct PlttData *data2 = (struct PlttData *)&blendColor;
struct PlttData *data2 = (struct PlttData *) & blendColor;
for (i = 0; i < numEntries; i++)
{
u16 index = i + palOffset;

View File

@ -166,8 +166,7 @@ void ReadJascPalette(char *path, struct Palette *palette)
if (fp == NULL)
return;
// fprintf(stderr, "Opened auxiliary .pla file for reading: %s\n", path);
int i = 0;
// Keep reading lines until number of colors is reached or we run out
while (i < palette->numColors && fgets(line, MAX_LINE_LENGTH, fp) != NULL)