Added default light blending color.

Fixed light palette header offsets.
Changed blending function names.
This commit is contained in:
Ariel Antonitis 2021-03-12 23:20:15 -05:00
parent 2055a56eb0
commit 56b9764aec
8 changed files with 27 additions and 21 deletions

View file

@ -13,7 +13,7 @@ gTileset_General:: @ 83DF704
gTileset_Petalburg:: @ 83DF71C
.byte TRUE @ is compressed
.byte TRUE @ is secondary tileset
.2byte 0xC0 @ lightPalettes 7,8
.2byte 3 @ lightPalettes 6,7
.4byte gTilesetTiles_Petalburg
.4byte gTilesetPalettes_Petalburg
.4byte gMetatiles_Petalburg
@ -24,7 +24,7 @@ gTileset_Petalburg:: @ 83DF71C
gTileset_Rustboro:: @ 83DF734
.byte TRUE @ is compressed
.byte TRUE @ is secondary tileset
.2byte 1 << 6 @ lightPalettes
.2byte 1 @ lightPalettes 6
.4byte gTilesetTiles_Rustboro
.4byte gTilesetPalettes_Rustboro
.4byte gMetatiles_Rustboro
@ -46,7 +46,7 @@ gTileset_Dewford:: @ 83DF74C
gTileset_Slateport:: @ 83DF764
.byte TRUE @ is compressed
.byte TRUE @ is secondary tileset
.2byte 1 << 12 @ lightPalettes
.2byte 0x41 @ lightPalettes 6,12
.4byte gTilesetTiles_Slateport
.4byte gTilesetPalettes_Slateport
.4byte gMetatiles_Slateport

View file

@ -29,7 +29,8 @@ struct Tileset
{
/*0x00*/ bool8 isCompressed;
/*0x01*/ bool8 isSecondary;
/*0x02*/ u16 lightPalettes;
/*0x02*/ u8 lightPalettes; // Bitmask determining whether a palette should be time-blended as a light
/*0x03*/ u8 customLightColor; // Bitmask determining which light palettes have custom light colors (color 15)
/*0x04*/ void *tiles;
/*0x08*/ void *palettes;
/*0x0c*/ u16 *metatiles;

View file

@ -136,7 +136,7 @@ void CleanupOverworldWindowsAndTilemaps(void);
bool32 IsUpdateLinkStateCBActive(void);
void CB1_Overworld(void);
void CB2_OverworldBasic(void);
void BlendPalettesWithTime(u32);
void UpdatePalettesWithTime(u32);
void CB2_Overworld(void);
void SetMainCallback1(void (*cb)(void));
void SetUnusedCallback(void *a0);

View file

@ -76,8 +76,8 @@ void BeginHardwarePaletteFade(u8, u8, u8, u8, u8);
void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color);
void BlendPalettesUnfaded(u32, u8, u16);
void BlendPalettesGradually(u32 selectedPalettes, s8 delay, u8 coeff, u8 coeffTarget, u16 color, u8 priority, u8 id);
void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor);
void TimePalettes(u32 palettes, u8 coeff, u16 color);
void TimeBlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor);
void TimeBlendPalettes(u32 palettes, u8 coeff, u16 color);
void TintPalette_GrayScale(u16 *palette, u16 count);
void TintPalette_GrayScale2(u16 *palette, u16 count);
void TintPalette_SepiaTone(u16 *palette, u16 count);

View file

@ -1142,7 +1142,7 @@ void Thunderstorm_Main(void)
{
ApplyWeatherGammaShiftIfIdle(3);
if (gTimeOfDay != TIME_OF_DAY_DAY)
BlendPalettesWithTime(0xFFFFFFFF);
UpdatePalettesWithTime(0xFFFFFFFF);
gWeatherPtr->thunderAllowEnd = TRUE;
if (--gWeatherPtr->thunderShortRetries != 0)
{
@ -1183,7 +1183,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) : BlendPalettesWithTime(0xFFFFFFFF);
gTimeOfDay == TIME_OF_DAY_DAY ? sub_80ABC7C(19, 3, 5) : UpdatePalettesWithTime(0xFFFFFFFF);
gWeatherPtr->initStep++;
}
break;

View file

@ -887,9 +887,11 @@ void LoadTilesetPalette(struct Tileset const *tileset, u16 destOffset, u16 size)
u8 i;
LoadPalette(((u16*)tileset->palettes) + (NUM_PALS_IN_PRIMARY * 16), destOffset, size);
for (i = NUM_PALS_IN_PRIMARY; i < NUM_PALS_TOTAL; i++) {
if (tileset->lightPalettes & (1 << i)) {
if (tileset->lightPalettes & (1 << (i - NUM_PALS_IN_PRIMARY))) { // Mark as light palette
u16 index = i * 16;
gPlttBufferFaded[index] = gPlttBufferUnfaded[index] |= 0x8000;
if (tileset->customLightColor & (1 << (i - NUM_PALS_IN_PRIMARY))) // Mark as custom light color
gPlttBufferFaded[index+15] = gPlttBufferUnfaded[index+15] |= 0x8000;
}
}
}

View file

@ -846,7 +846,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum)
RoamerMove();
DoCurrentWeather();
ResetFieldTasksArgs();
BlendPalettesWithTime(0xFFFFFFFF);
UpdatePalettesWithTime(0xFFFFFFFF);
RunOnResumeMapScript();
if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER
@ -1512,7 +1512,7 @@ static bool8 FadePalettesWithTime(void) {
}
}
void BlendPalettesWithTime(u32 palettes) {
void UpdatePalettesWithTime(u32 palettes) {
// Only blend if not transitioning between times and the map type allows
if (gTimeOfDayState == 0 && MapHasNaturalLight(gMapHeader.mapType)) {
u8 i;
@ -1524,12 +1524,12 @@ void BlendPalettesWithTime(u32 palettes) {
gTimeOfDay = min(TIME_OF_DAY_MAX, gTimeOfDay);
if (!palettes)
return;
TimePalettes(palettes, sTimeOfDayBlendVars[gTimeOfDay].coeff, sTimeOfDayBlendVars[gTimeOfDay].blendColor);
TimeBlendPalettes(palettes, sTimeOfDayBlendVars[gTimeOfDay].coeff, sTimeOfDayBlendVars[gTimeOfDay].blendColor);
}
}
u8 UpdateSpritePaletteWithTime(u8 paletteNum) { // TODO: Optimize this
BlendPalettesWithTime(1 << (paletteNum + 16));
UpdatePalettesWithTime(1 << (paletteNum + 16));
return paletteNum;
}

View file

@ -496,13 +496,13 @@ static u8 UpdateTimeOfDayPaletteFade(void)
if (gPaletteFade.yDec) {
if (gPaletteFade.objPaletteToggle) { // sprite palettes
if (gPaletteFade.y >= gPaletteFade.targetY || GetSpritePaletteTagByPaletteNum(paletteNum) & 0x8000)
TimePalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor);
TimeBlendPalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor);
// tile palettes
} else if (gPaletteFade.y >= gPaletteFade.targetY || (paletteNum >= 13 && paletteNum <= 15)) {
TimePalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor);
TimeBlendPalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor);
}
} else {
TimePalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor);
TimeBlendPalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor);
}
}
}
@ -979,8 +979,9 @@ void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color)
}
// Like BlendPalette, but ignores blendColor if the transparency high bit is set
void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) {
void TimeBlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) {
u16 i;
u16 defaultBlendColor = 0x3f9f;
s8 r, g, b;
struct PlttData *data2 = (struct PlttData *)&blendColor;
struct PlttData *data3;
@ -992,8 +993,10 @@ void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) {
if (i == 0) {
if (data1->unused_15) { // Color 0 is a bitmask for which colors to blend; color 15 is the alt blend color
gPlttBufferFaded[index] = gPlttBufferUnfaded[index];
altBlendIndices = gPlttBufferUnfaded[index] & 0x7FFF;
altBlendIndices = gPlttBufferUnfaded[index] & 0x7FFF; // Note that color 15 will never be light-blended
data3 = (struct PlttData *)&gPlttBufferUnfaded[index+15];
if (!data3->unused_15) // use default blend color instead
data3 = (struct PlttData *)&defaultBlendColor;
}
continue;
}
@ -1008,11 +1011,11 @@ void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) {
}
// Apply time effect to a series of palettes
void TimePalettes(u32 palettes, u8 coeff, u16 color) {
void TimeBlendPalettes(u32 palettes, u8 coeff, u16 color) {
u16 paletteOffset;
for (paletteOffset = 0; palettes; paletteOffset += 16) {
if (palettes & 1)
TimePalette(paletteOffset, 16, coeff, color);
TimeBlendPalette(paletteOffset, 16, coeff, color);
palettes >>= 1;
}
}