From ffc8903f93d115ad375e09df3b45f05bed986371 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Fri, 17 Jan 2025 18:47:38 -0300 Subject: [PATCH] More review addressing --- include/constants/field_weather.h | 2 ++ include/overworld.h | 4 ++-- src/battle_transition.c | 4 ++-- src/field_weather.c | 4 ++-- src/field_weather_effect.c | 3 --- src/overworld.c | 32 +++++++++++++++---------------- src/palette.c | 14 +++++++------- src/palette_util.c | 2 +- src/sprite.c | 1 + src/util.c | 2 +- tools/gbagfx/jasc_pal.c | 3 +-- 11 files changed, 35 insertions(+), 36 deletions(-) diff --git a/include/constants/field_weather.h b/include/constants/field_weather.h index bc4826ee36..d4f17e261c 100644 --- a/include/constants/field_weather.h +++ b/include/constants/field_weather.h @@ -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 diff --git a/include/overworld.h b/include/overworld.h index 328655ecda..d62d76c24c 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -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; }; diff --git a/src/battle_transition.c b/src/battle_transition.c index 422257433c..1aabda2aa3 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -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; } } diff --git a/src/field_weather.c b/src/field_weather.c index 9274863be1..db6ab5d179 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -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 diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index df23a6b0e0..e00e7ba863 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -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) { diff --git a/src/overworld.c b/src/overworld.c index 4d4d74e5dc..4c353b7562 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -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); diff --git a/src/palette.c b/src/palette.c index f2fdac9fdc..145b1e90d9 100644 --- a/src/palette.c +++ b/src/palette.c @@ -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) { diff --git a/src/palette_util.c b/src/palette_util.c index 54549ffcce..5effdd2b15 100644 --- a/src/palette_util.c +++ b/src/palette_util.c @@ -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) diff --git a/src/sprite.c b/src/sprite.c index c300e4a5bc..80418a0d76 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -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) { diff --git a/src/util.c b/src/util.c index 1d9db59160..6fb123662b 100644 --- a/src/util.c +++ b/src/util.c @@ -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; diff --git a/tools/gbagfx/jasc_pal.c b/tools/gbagfx/jasc_pal.c index 732db08a1b..3ae7f8b905 100644 --- a/tools/gbagfx/jasc_pal.c +++ b/tools/gbagfx/jasc_pal.c @@ -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)