From dcc1a0627d6d76de0717561a7d6113a0c32a0f31 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 29 Apr 2024 18:01:39 +0200 Subject: [PATCH 1/4] Move gPeepPalette, gOtherPalette to Drawing.Sprite.cpp --- src/openrct2/drawing/Drawing.Sprite.cpp | 44 +++++++++++++++++++++++ src/openrct2/drawing/Drawing.cpp | 47 +------------------------ src/openrct2/drawing/Drawing.h | 4 +-- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index 7b130421de..b1920419d5 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -30,7 +30,51 @@ using namespace OpenRCT2; using namespace OpenRCT2::Ui; +/** + * 12 elements from 0xF3 are the peep top colour, 12 elements from 0xCA are peep trouser colour + * + * rct2: 0x0009ABE0C + */ // clang-format off +static thread_local uint8_t gPeepPalette[256] = { + 0x00, 0xF3, 0xF4, 0xF5, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0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, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, +}; + constexpr struct { int start; diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 9f73daa40c..95cb1f3048 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -96,51 +96,6 @@ ImageId gPickupPeepImage; int32_t gPickupPeepX; int32_t gPickupPeepY; -/** - * 12 elements from 0xF3 are the peep top colour, 12 elements from 0xCA are peep trouser colour - * - * rct2: 0x0009ABE0C - */ -// clang-format off -thread_local uint8_t gPeepPalette[256] = { - 0x00, 0xF3, 0xF4, 0xF5, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E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1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, -}; - -/** rct2: 0x009ABF0C */ -thread_local uint8_t gOtherPalette[256] = { - 0x00, 0xF3, 0xF4, 0xF5, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, - 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, -}; - // Originally 0x9ABE04 uint8_t gTextPalette[0x8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -405,6 +360,7 @@ const FilterPaletteID GlassPaletteIds[COLOUR_COUNT] = { }; // Previously 0x97FCBC use it to get the correct palette from g1_elements +// clang-format off static constexpr uint16_t palette_to_g1_offset[kPaletteTotalOffsets] = { SPR_PALETTE_BLACK, SPR_PALETTE_GREY, @@ -463,7 +419,6 @@ static constexpr uint16_t palette_to_g1_offset[kPaletteTotalOffsets] = { SPR_PALETTE_INVISIBLE, SPR_PALETTE_VOID, - SPR_PALETTE_WATER, // PaletteWater (water) SPR_PALETTE_3100, SPR_PALETTE_3101, // Palette34 diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index b787dbcaf8..40b6cf72c6 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -515,9 +515,7 @@ constexpr uint8_t kPaletteTotalOffsets = 192; extern GamePalette gPalette; extern uint8_t gGamePalette[256 * 4]; extern uint32_t gPaletteEffectFrame; -extern const FilterPaletteID GlassPaletteIds[COLOUR_COUNT]; -extern thread_local uint8_t gPeepPalette[256]; -extern thread_local uint8_t gOtherPalette[256]; + extern uint8_t gTextPalette[]; extern const TranslucentWindowPalette TranslucentWindowPalettes[COLOUR_COUNT]; From 25faa361ad41830db20202513c02f3314b416dca Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 29 Apr 2024 18:04:17 +0200 Subject: [PATCH 2/4] Rename to secondaryRemapPalette, tertiaryRemapPalette --- src/openrct2/drawing/Drawing.Sprite.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index b1920419d5..d691286a0f 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -36,7 +36,7 @@ using namespace OpenRCT2::Ui; * rct2: 0x0009ABE0C */ // clang-format off -static thread_local uint8_t gPeepPalette[256] = { +static thread_local uint8_t secondaryRemapPalette[256] = { 0x00, 0xF3, 0xF4, 0xF5, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, @@ -56,7 +56,7 @@ static thread_local uint8_t gPeepPalette[256] = { }; /** rct2: 0x009ABF0C */ -static thread_local uint8_t gOtherPalette[256] = { +static thread_local uint8_t tertiaryRemapPalette[256] = { 0x00, 0xF3, 0xF4, 0xF5, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, @@ -459,10 +459,10 @@ static std::optional FASTCALL GfxDrawSpriteGetPalette(ImageId imageI return GetPaletteMapForColour(paletteId); } - auto paletteMap = PaletteMap(gPeepPalette); + auto paletteMap = PaletteMap(secondaryRemapPalette); if (imageId.HasTertiary()) { - paletteMap = PaletteMap(gOtherPalette); + paletteMap = PaletteMap(tertiaryRemapPalette); auto tertiaryPaletteMap = GetPaletteMapForColour(imageId.GetTertiary()); if (tertiaryPaletteMap.has_value()) { From 66cb4a1d81964571f14bd8cf33c720f1199515e6 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 29 Apr 2024 18:05:25 +0200 Subject: [PATCH 3/4] Mark GlassPaletteIds static constexpr --- src/openrct2/drawing/Drawing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 95cb1f3048..9684b6033b 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -300,7 +300,7 @@ enum SPR_PALETTE_GLASS_VOID, }; -const FilterPaletteID GlassPaletteIds[COLOUR_COUNT] = { +static constexpr FilterPaletteID GlassPaletteIds[COLOUR_COUNT] = { FilterPaletteID::PaletteGlassBlack, FilterPaletteID::PaletteGlassGrey, FilterPaletteID::PaletteGlassWhite, From 95239d75c9b23568ad64a5756fc2e0390d3e9bb9 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 29 Apr 2024 18:14:09 +0200 Subject: [PATCH 4/4] Move UpdatePaletteEffects to Drawing.cpp --- src/openrct2/Game.cpp | 171 ------------------------------ src/openrct2/Game.h | 1 - src/openrct2/drawing/Drawing.cpp | 175 ++++++++++++++++++++++++++++++- src/openrct2/drawing/Drawing.h | 1 + 4 files changed, 175 insertions(+), 173 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index ba1a7cbfc1..e5166ace0e 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -136,177 +136,6 @@ void GameCreateWindows() WindowResizeGui(ContextGetWidth(), ContextGetHeight()); } -enum -{ - SPR_GAME_PALETTE_DEFAULT = 1532, - SPR_GAME_PALETTE_WATER = 1533, - SPR_GAME_PALETTE_WATER_DARKER_1 = 1534, - SPR_GAME_PALETTE_WATER_DARKER_2 = 1535, - SPR_GAME_PALETTE_3 = 1536, - SPR_GAME_PALETTE_3_DARKER_1 = 1537, - SPR_GAME_PALETTE_3_DARKER_2 = 1538, - SPR_GAME_PALETTE_4 = 1539, - SPR_GAME_PALETTE_4_DARKER_1 = 1540, - SPR_GAME_PALETTE_4_DARKER_2 = 1541, -}; - -/** - * - * rct2: 0x006838BD - */ -void UpdatePaletteEffects() -{ - auto water_type = OpenRCT2::ObjectManager::GetObjectEntry(0); - - if (gClimateLightningFlash == 1) - { - // Change palette to lighter colour during lightning - int32_t palette = SPR_GAME_PALETTE_DEFAULT; - - if (water_type != nullptr) - { - palette = water_type->image_id; - } - const G1Element* g1 = GfxGetG1Element(palette); - if (g1 != nullptr) - { - int32_t xoffset = g1->x_offset; - xoffset = xoffset * 4; - uint8_t* paletteOffset = gGamePalette + xoffset; - for (int32_t i = 0; i < g1->width; i++) - { - paletteOffset[(i * 4) + 0] = -((0xFF - g1->offset[(i * 3) + 0]) / 2) - 1; - paletteOffset[(i * 4) + 1] = -((0xFF - g1->offset[(i * 3) + 1]) / 2) - 1; - paletteOffset[(i * 4) + 2] = -((0xFF - g1->offset[(i * 3) + 2]) / 2) - 1; - } - UpdatePalette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); - } - gClimateLightningFlash++; - } - else - { - if (gClimateLightningFlash == 2) - { - // Change palette back to normal after lightning - int32_t palette = SPR_GAME_PALETTE_DEFAULT; - - if (water_type != nullptr) - { - palette = water_type->image_id; - } - - const G1Element* g1 = GfxGetG1Element(palette); - if (g1 != nullptr) - { - int32_t xoffset = g1->x_offset; - xoffset = xoffset * 4; - uint8_t* paletteOffset = gGamePalette + xoffset; - for (int32_t i = 0; i < g1->width; i++) - { - paletteOffset[(i * 4) + 0] = g1->offset[(i * 3) + 0]; - paletteOffset[(i * 4) + 1] = g1->offset[(i * 3) + 1]; - paletteOffset[(i * 4) + 2] = g1->offset[(i * 3) + 2]; - } - } - } - - // Animate the water/lava/chain movement palette - uint32_t shade = 0; - if (gConfigGeneral.RenderWeatherGloom) - { - auto paletteId = ClimateGetWeatherGloomPaletteId(GetGameState().ClimateCurrent); - if (paletteId != FilterPaletteID::PaletteNull) - { - shade = 1; - if (paletteId != FilterPaletteID::PaletteDarken1) - { - shade = 2; - } - } - } - uint32_t j = gPaletteEffectFrame; - j = ((static_cast((~j / 2) * 128) * 15) >> 16); - uint32_t waterId = SPR_GAME_PALETTE_WATER; - if (water_type != nullptr) - { - waterId = water_type->palette_index_1; - } - const G1Element* g1 = GfxGetG1Element(shade + waterId); - if (g1 != nullptr) - { - uint8_t* vs = &g1->offset[j * 3]; - uint8_t* vd = &gGamePalette[PALETTE_OFFSET_WATER_WAVES * 4]; - int32_t n = PALETTE_LENGTH_WATER_WAVES; - for (int32_t i = 0; i < n; i++) - { - vd[0] = vs[0]; - vd[1] = vs[1]; - vd[2] = vs[2]; - vs += 9; - if (vs >= &g1->offset[9 * n]) - { - vs -= 9 * n; - } - vd += 4; - } - } - - waterId = SPR_GAME_PALETTE_3; - if (water_type != nullptr) - { - waterId = water_type->palette_index_2; - } - g1 = GfxGetG1Element(shade + waterId); - if (g1 != nullptr) - { - uint8_t* vs = &g1->offset[j * 3]; - uint8_t* vd = &gGamePalette[PALETTE_OFFSET_WATER_SPARKLES * 4]; - int32_t n = PALETTE_LENGTH_WATER_SPARKLES; - for (int32_t i = 0; i < n; i++) - { - vd[0] = vs[0]; - vd[1] = vs[1]; - vd[2] = vs[2]; - vs += 9; - if (vs >= &g1->offset[9 * n]) - { - vs -= 9 * n; - } - vd += 4; - } - } - - j = (static_cast(gPaletteEffectFrame * -960) * 3) >> 16; - waterId = SPR_GAME_PALETTE_4; - g1 = GfxGetG1Element(shade + waterId); - if (g1 != nullptr) - { - uint8_t* vs = &g1->offset[j * 3]; - uint8_t* vd = &gGamePalette[PALETTE_INDEX_243 * 4]; - int32_t n = 3; - for (int32_t i = 0; i < n; i++) - { - vd[0] = vs[0]; - vd[1] = vs[1]; - vd[2] = vs[2]; - vs += 3; - if (vs >= &g1->offset[3 * n]) - { - vs -= 3 * n; - } - vd += 4; - } - } - - UpdatePalette(gGamePalette, PALETTE_OFFSET_ANIMATED, PALETTE_LENGTH_ANIMATED); - if (gClimateLightningFlash == 2) - { - UpdatePalette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); - gClimateLightningFlash = 0; - } - } -} - void PauseToggle() { gGamePaused ^= GAME_PAUSED_NORMAL; diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index dd6ddfdf22..876de954bc 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -156,7 +156,6 @@ void GameReduceGameSpeed(); void GameCreateWindows(); void ResetAllSpriteQuadrantPlacements(); -void UpdatePaletteEffects(); void GameLoadOrQuitNoSavePrompt(); void GameLoadInit(); diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 9684b6033b..8a5de8f107 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../Game.h" +#include "../GameState.h" #include "../OpenRCT2.h" #include "../common.h" #include "../config/Config.h" @@ -27,7 +28,7 @@ #include -GamePalette gPalette; +using namespace OpenRCT2; const PaletteMap& PaletteMap::GetDefault() { @@ -89,6 +90,7 @@ void PaletteMap::Copy(size_t dstIndex, const PaletteMap& src, size_t srcIndex, s std::memcpy(&_data[dstIndex], &src._data[srcIndex], copyLength); } +GamePalette gPalette; uint8_t gGamePalette[256 * 4]; uint32_t gPaletteEffectFrame; @@ -951,6 +953,177 @@ void UpdatePalette(const uint8_t* colours, int32_t start_index, int32_t num_colo } } +enum +{ + SPR_GAME_PALETTE_DEFAULT = 1532, + SPR_GAME_PALETTE_WATER = 1533, + SPR_GAME_PALETTE_WATER_DARKER_1 = 1534, + SPR_GAME_PALETTE_WATER_DARKER_2 = 1535, + SPR_GAME_PALETTE_3 = 1536, + SPR_GAME_PALETTE_3_DARKER_1 = 1537, + SPR_GAME_PALETTE_3_DARKER_2 = 1538, + SPR_GAME_PALETTE_4 = 1539, + SPR_GAME_PALETTE_4_DARKER_1 = 1540, + SPR_GAME_PALETTE_4_DARKER_2 = 1541, +}; + +/** + * + * rct2: 0x006838BD + */ +void UpdatePaletteEffects() +{ + auto water_type = OpenRCT2::ObjectManager::GetObjectEntry(0); + + if (gClimateLightningFlash == 1) + { + // Change palette to lighter colour during lightning + int32_t palette = SPR_GAME_PALETTE_DEFAULT; + + if (water_type != nullptr) + { + palette = water_type->image_id; + } + const G1Element* g1 = GfxGetG1Element(palette); + if (g1 != nullptr) + { + int32_t xoffset = g1->x_offset; + xoffset = xoffset * 4; + uint8_t* paletteOffset = gGamePalette + xoffset; + for (int32_t i = 0; i < g1->width; i++) + { + paletteOffset[(i * 4) + 0] = -((0xFF - g1->offset[(i * 3) + 0]) / 2) - 1; + paletteOffset[(i * 4) + 1] = -((0xFF - g1->offset[(i * 3) + 1]) / 2) - 1; + paletteOffset[(i * 4) + 2] = -((0xFF - g1->offset[(i * 3) + 2]) / 2) - 1; + } + UpdatePalette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); + } + gClimateLightningFlash++; + } + else + { + if (gClimateLightningFlash == 2) + { + // Change palette back to normal after lightning + int32_t palette = SPR_GAME_PALETTE_DEFAULT; + + if (water_type != nullptr) + { + palette = water_type->image_id; + } + + const G1Element* g1 = GfxGetG1Element(palette); + if (g1 != nullptr) + { + int32_t xoffset = g1->x_offset; + xoffset = xoffset * 4; + uint8_t* paletteOffset = gGamePalette + xoffset; + for (int32_t i = 0; i < g1->width; i++) + { + paletteOffset[(i * 4) + 0] = g1->offset[(i * 3) + 0]; + paletteOffset[(i * 4) + 1] = g1->offset[(i * 3) + 1]; + paletteOffset[(i * 4) + 2] = g1->offset[(i * 3) + 2]; + } + } + } + + // Animate the water/lava/chain movement palette + uint32_t shade = 0; + if (gConfigGeneral.RenderWeatherGloom) + { + auto paletteId = ClimateGetWeatherGloomPaletteId(GetGameState().ClimateCurrent); + if (paletteId != FilterPaletteID::PaletteNull) + { + shade = 1; + if (paletteId != FilterPaletteID::PaletteDarken1) + { + shade = 2; + } + } + } + uint32_t j = gPaletteEffectFrame; + j = ((static_cast((~j / 2) * 128) * 15) >> 16); + uint32_t waterId = SPR_GAME_PALETTE_WATER; + if (water_type != nullptr) + { + waterId = water_type->palette_index_1; + } + const G1Element* g1 = GfxGetG1Element(shade + waterId); + if (g1 != nullptr) + { + uint8_t* vs = &g1->offset[j * 3]; + uint8_t* vd = &gGamePalette[PALETTE_OFFSET_WATER_WAVES * 4]; + int32_t n = PALETTE_LENGTH_WATER_WAVES; + for (int32_t i = 0; i < n; i++) + { + vd[0] = vs[0]; + vd[1] = vs[1]; + vd[2] = vs[2]; + vs += 9; + if (vs >= &g1->offset[9 * n]) + { + vs -= 9 * n; + } + vd += 4; + } + } + + waterId = SPR_GAME_PALETTE_3; + if (water_type != nullptr) + { + waterId = water_type->palette_index_2; + } + g1 = GfxGetG1Element(shade + waterId); + if (g1 != nullptr) + { + uint8_t* vs = &g1->offset[j * 3]; + uint8_t* vd = &gGamePalette[PALETTE_OFFSET_WATER_SPARKLES * 4]; + int32_t n = PALETTE_LENGTH_WATER_SPARKLES; + for (int32_t i = 0; i < n; i++) + { + vd[0] = vs[0]; + vd[1] = vs[1]; + vd[2] = vs[2]; + vs += 9; + if (vs >= &g1->offset[9 * n]) + { + vs -= 9 * n; + } + vd += 4; + } + } + + j = (static_cast(gPaletteEffectFrame * -960) * 3) >> 16; + waterId = SPR_GAME_PALETTE_4; + g1 = GfxGetG1Element(shade + waterId); + if (g1 != nullptr) + { + uint8_t* vs = &g1->offset[j * 3]; + uint8_t* vd = &gGamePalette[PALETTE_INDEX_243 * 4]; + int32_t n = 3; + for (int32_t i = 0; i < n; i++) + { + vd[0] = vs[0]; + vd[1] = vs[1]; + vd[2] = vs[2]; + vs += 3; + if (vs >= &g1->offset[3 * n]) + { + vs -= 3 * n; + } + vd += 4; + } + } + + UpdatePalette(gGamePalette, PALETTE_OFFSET_ANIMATED, PALETTE_LENGTH_ANIMATED); + if (gClimateLightningFlash == 2) + { + UpdatePalette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); + gClimateLightningFlash = 0; + } + } +} + void RefreshVideo(bool recreateWindow) { if (recreateWindow) diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 40b6cf72c6..012ad0ac28 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -628,6 +628,7 @@ void MaskFn( std::optional GetPaletteG1Index(colour_t paletteId); std::optional GetPaletteMapForColour(colour_t paletteId); void UpdatePalette(const uint8_t* colours, int32_t start_index, int32_t num_colours); +void UpdatePaletteEffects(); void RefreshVideo(bool recreateWindow); void ToggleWindowedMode();