Changed time blending to work with FadeScreen.
This commit is contained in:
parent
c0d6692ce8
commit
65e616342b
6 changed files with 40 additions and 23 deletions
|
@ -7,3 +7,4 @@ gFieldCallback2
|
|||
gLocalLinkPlayerId
|
||||
gFieldLinkPlayerCount
|
||||
gTimeOfDay
|
||||
currentTimeBlend
|
||||
|
|
|
@ -62,11 +62,15 @@ extern void (*gFieldCallback)(void);
|
|||
extern bool8 (*gFieldCallback2)(void);
|
||||
extern u8 gLocalLinkPlayerId;
|
||||
extern u8 gFieldLinkPlayerCount;
|
||||
|
||||
extern u8 gTimeOfDay;
|
||||
extern struct TimeBlendSettings currentTimeBlend;
|
||||
|
||||
// Exported ROM declarations
|
||||
extern const struct UCoords32 gDirectionToVectors[];
|
||||
|
||||
extern const struct BlendSettings gTimeOfDayBlend[];
|
||||
|
||||
void DoWhiteOut(void);
|
||||
void Overworld_ResetStateAfterFly(void);
|
||||
void Overworld_ResetStateAfterTeleport(void);
|
||||
|
@ -142,6 +146,7 @@ bool32 IsUpdateLinkStateCBActive(void);
|
|||
void CB1_Overworld(void);
|
||||
void CB2_OverworldBasic(void);
|
||||
u8 UpdateTimeOfDay(void);
|
||||
bool8 MapHasNaturalLight(u8 mapType);
|
||||
void UpdatePalettesWithTime(u32);
|
||||
void CB2_Overworld(void);
|
||||
void SetMainCallback1(void (*cb)(void));
|
||||
|
|
|
@ -70,7 +70,7 @@ u8 UpdatePaletteFade(void);
|
|||
void ResetPaletteFade(void);
|
||||
void ReadPlttIntoBuffers(void);
|
||||
bool8 BeginNormalPaletteFade(u32, s8, u8, u8, u16);
|
||||
bool8 BeginTimeOfDayPaletteFade(u32, s8, u8, u8, struct BlendSettings *, struct BlendSettings *, u16);
|
||||
bool8 BeginTimeOfDayPaletteFade(u32, s8, u8, u8, struct BlendSettings *, struct BlendSettings *, u16, u16);
|
||||
bool8 unref_sub_8073D3C(u32, u8, u8, u8, u16);
|
||||
void unref_sub_8073D84(u8, u32 *);
|
||||
void ResetPaletteStructByUid(u16);
|
||||
|
|
|
@ -472,6 +472,7 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex)
|
|||
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));
|
||||
|
@ -647,7 +648,7 @@ static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 bl
|
|||
}
|
||||
}
|
||||
|
||||
static void ApplyFogBlend(u8 blendCoeff, u16 blendColor)
|
||||
static void ApplyFogBlend(u8 blendCoeff, u16 blendColor) // TODO: How does this interact with time
|
||||
{
|
||||
struct RGBColor color;
|
||||
u8 rBlend;
|
||||
|
@ -794,9 +795,18 @@ void FadeScreen(u8 mode, s8 delay)
|
|||
{
|
||||
gWeatherPtr->fadeDestColor = fadeColor;
|
||||
if (useWeatherPal)
|
||||
gWeatherPtr->fadeScreenCounter = 0;
|
||||
else
|
||||
gWeatherPtr->fadeScreenCounter = 0; // Triggers gamma-shift-based fade-in
|
||||
else {
|
||||
UpdateTimeOfDay();
|
||||
if (MapHasNaturalLight(gMapHeader.mapType)) {
|
||||
BeginTimeOfDayPaletteFade(PALETTES_ALL, delay, 16, 0,
|
||||
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0],
|
||||
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1],
|
||||
currentTimeBlend.weight, fadeColor);
|
||||
} else {
|
||||
BeginNormalPaletteFade(PALETTES_ALL, delay, 16, 0, fadeColor);
|
||||
}
|
||||
}
|
||||
|
||||
gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_IN;
|
||||
gWeatherPtr->fadeInFirstFrame = TRUE;
|
||||
|
|
|
@ -187,7 +187,7 @@ static bool8 sReceivingFromLink;
|
|||
static u8 sRfuKeepAliveTimer;
|
||||
|
||||
static u16 sTimeUpdateCounter; // playTimeVBlanks will eventually overflow, so this is used to update TOD
|
||||
static struct TimeBlendSettings currentTimeBlend;
|
||||
|
||||
|
||||
// IWRAM common
|
||||
u16 *gBGTilemapBuffers1;
|
||||
|
@ -200,6 +200,7 @@ u8 gLocalLinkPlayerId; // This is our player id in a multiplayer mode.
|
|||
u8 gFieldLinkPlayerCount;
|
||||
|
||||
u8 gTimeOfDay;
|
||||
struct TimeBlendSettings currentTimeBlend;
|
||||
|
||||
// EWRAM vars
|
||||
EWRAM_DATA static u8 sObjectEventLoadFlag = 0;
|
||||
|
@ -828,7 +829,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
|
|||
RoamerMove();
|
||||
DoCurrentWeather();
|
||||
ResetFieldTasksArgs();
|
||||
UpdatePalettesWithTime(0xFFFFFFFF);
|
||||
UpdatePalettesWithTime(PALETTES_ALL);
|
||||
RunOnResumeMapScript();
|
||||
|
||||
if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER
|
||||
|
@ -1462,7 +1463,7 @@ void CB1_Overworld(void)
|
|||
|
||||
|
||||
|
||||
static const struct BlendSettings sTimeOfDayBlendVars[] =
|
||||
const struct BlendSettings gTimeOfDayBlend[] =
|
||||
{
|
||||
[TIME_OF_DAY_NIGHT] = {.coeff = 10, .blendColor = 0x1400},
|
||||
[TIME_OF_DAY_TWILIGHT] = {.coeff = 4, .blendColor = 0x56dc, .isTint = TRUE},
|
||||
|
@ -1506,20 +1507,21 @@ u8 UpdateTimeOfDay(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool8 MapHasNaturalLight(u8 mapType) { // Whether a map type is naturally lit/outside
|
||||
bool8 MapHasNaturalLight(u8 mapType) { // Whether a map type is naturally lit/outside
|
||||
return mapType == MAP_TYPE_TOWN || mapType == MAP_TYPE_CITY || mapType == MAP_TYPE_ROUTE
|
||||
|| mapType == MAP_TYPE_OCEAN_ROUTE;
|
||||
}
|
||||
|
||||
// TODO: Rewrite palette fading to work with FadeScreen
|
||||
// Currently, this cancels the "Normal" palette fade started by FadeScreen
|
||||
static bool8 FadePalettesWithTime(void) { // Only used to fade back in
|
||||
gTimeOfDay = UpdateTimeOfDay();
|
||||
UpdateTimeOfDay();
|
||||
if (MapHasNaturalLight(gMapHeader.mapType)) {
|
||||
ResetPaletteFade();
|
||||
BeginTimeOfDayPaletteFade(0xFFFFFFFF, 0, 16, 0,
|
||||
(struct BlendSettings *)&sTimeOfDayBlendVars[currentTimeBlend.time0],
|
||||
(struct BlendSettings *)&sTimeOfDayBlendVars[currentTimeBlend.time1],
|
||||
currentTimeBlend.weight);
|
||||
BeginTimeOfDayPaletteFade(PALETTES_ALL, 0, 16, 0,
|
||||
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0],
|
||||
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1],
|
||||
currentTimeBlend.weight, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1537,8 +1539,8 @@ void UpdatePalettesWithTime(u32 palettes) {
|
|||
TimeMixPalettes(palettes,
|
||||
gPlttBufferUnfaded,
|
||||
gPlttBufferFaded,
|
||||
(struct BlendSettings *)&sTimeOfDayBlendVars[currentTimeBlend.time0],
|
||||
(struct BlendSettings *)&sTimeOfDayBlendVars[currentTimeBlend.time1],
|
||||
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0],
|
||||
(struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1],
|
||||
currentTimeBlend.weight);
|
||||
}
|
||||
}
|
||||
|
@ -1571,7 +1573,7 @@ static void OverworldBasic(void)
|
|||
if (cachedBlend.time0 != currentTimeBlend.time0
|
||||
|| cachedBlend.time1 != currentTimeBlend.time1
|
||||
|| cachedBlend.weight != currentTimeBlend.weight)
|
||||
UpdatePalettesWithTime(0xFFFFFFFF);
|
||||
UpdatePalettesWithTime(PALETTES_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1686,7 +1688,7 @@ static void CB2_LoadMap2(void)
|
|||
DoMapLoadLoop(&gMain.state);
|
||||
SetFieldVBlankCallback();
|
||||
SetMainCallback1(CB1_Overworld);
|
||||
FadePalettesWithTime();
|
||||
// FadePalettesWithTime();
|
||||
SetMainCallback2(CB2_Overworld);
|
||||
}
|
||||
|
||||
|
@ -1743,7 +1745,7 @@ static void CB2_ReturnToFieldLocal(void)
|
|||
if (ReturnToFieldLocal(&gMain.state))
|
||||
{
|
||||
SetFieldVBlankCallback();
|
||||
FadePalettesWithTime();
|
||||
// FadePalettesWithTime();
|
||||
SetMainCallback2(CB2_Overworld);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,8 +204,7 @@ bool8 BeginNormalPaletteFade(u32 selectedPalettes, s8 delay, u8 startY, u8 targe
|
|||
}
|
||||
|
||||
// Like normal palette fade but respects sprite/tile palettes immune to time of day fading
|
||||
// Blend color here is always assumed to be 0 (black).
|
||||
bool8 BeginTimeOfDayPaletteFade(u32 selectedPalettes, s8 delay, u8 startY, u8 targetY, struct BlendSettings *bld0, struct BlendSettings *bld1, u16 weight)
|
||||
bool8 BeginTimeOfDayPaletteFade(u32 selectedPalettes, s8 delay, u8 startY, u8 targetY, struct BlendSettings *bld0, struct BlendSettings *bld1, u16 weight, u16 color)
|
||||
{
|
||||
u8 temp;
|
||||
|
||||
|
@ -231,7 +230,7 @@ bool8 BeginTimeOfDayPaletteFade(u32 selectedPalettes, s8 delay, u8 startY, u8 ta
|
|||
gPaletteFade.active = 1;
|
||||
gPaletteFade.mode = TIME_OF_DAY_FADE;
|
||||
|
||||
gPaletteFade.blendColor = 0;
|
||||
gPaletteFade.blendColor = color;
|
||||
gPaletteFade.bld0 = bld0;
|
||||
gPaletteFade.bld1 = bld1;
|
||||
gPaletteFade.weight = weight;
|
||||
|
@ -522,7 +521,7 @@ static u8 UpdateTimeOfDayPaletteFade(void)
|
|||
u16 * dst1 = dst;
|
||||
while (copyPalettes) {
|
||||
if (copyPalettes & 1)
|
||||
CpuFastCopy(src1, dst1, 64);
|
||||
CpuFastCopy(src1, dst1, 32);
|
||||
copyPalettes >>= 1;
|
||||
src1 += 16;
|
||||
dst1 += 16;
|
||||
|
@ -530,7 +529,7 @@ static u8 UpdateTimeOfDayPaletteFade(void)
|
|||
}
|
||||
|
||||
// Then, blend from faded->faded with native BlendPalettes
|
||||
BlendPalettesFine(selectedPalettes, dst, dst, gPaletteFade.y, 0);
|
||||
BlendPalettesFine(selectedPalettes, dst, dst, gPaletteFade.y, gPaletteFade.blendColor);
|
||||
|
||||
gPaletteFade.objPaletteToggle ^= 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue