From 5491820d0291e171245d997983057c386daa928e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sun, 6 Sep 2026 16:41:19 +0200 Subject: [PATCH] Move game palette-related stuff into Palette.{cpp.h} --- src/openrct2-ui/title/TitleSequencePlayer.cpp | 3 +- .../windows/EditorObjectSelection.cpp | 3 +- src/openrct2/Context.cpp | 3 +- src/openrct2/Game.cpp | 4 +- src/openrct2/GameState.cpp | 4 +- src/openrct2/drawing/BlendColourMap.cpp | 1 + src/openrct2/drawing/Drawing.cpp | 269 +---------------- src/openrct2/drawing/Drawing.h | 13 - src/openrct2/drawing/Palette.cpp | 285 ++++++++++++++++++ src/openrct2/drawing/Palette.h | 30 ++ src/openrct2/interface/Screenshot.cpp | 1 + src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/object/WaterObject.cpp | 4 +- src/openrct2/paint/Painter.cpp | 1 + src/openrct2/scenario/Scenario.cpp | 4 +- .../scenes/editor/EditorController.cpp | 3 +- src/openrct2/scenes/editor/EditorScene.cpp | 6 +- .../scenes/editor/TrackDesignerScene.cpp | 4 +- .../scenes/editor/TrackManagerScene.cpp | 4 +- src/openrct2/scenes/intro/IntroScene.cpp | 1 + src/openrct2/scenes/title/TitleScene.cpp | 3 +- test/tests/PlayTests.cpp | 3 +- test/tests/S6ImportExportTests.cpp | 3 +- 23 files changed, 352 insertions(+), 302 deletions(-) create mode 100644 src/openrct2/drawing/Palette.cpp create mode 100644 src/openrct2/drawing/Palette.h diff --git a/src/openrct2-ui/title/TitleSequencePlayer.cpp b/src/openrct2-ui/title/TitleSequencePlayer.cpp index 91b944a216..58d4f1cf16 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.cpp +++ b/src/openrct2-ui/title/TitleSequencePlayer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -441,7 +442,7 @@ namespace OpenRCT2::Title ContextBroadcastIntent(&intent); Ui::Windows::WindowScenerySetDefaultPlacementConfiguration(); News::InitQueue(gameState); - LoadPalette(); + Drawing::LoadPalette(); gScreenAge = 0; gGamePaused = false; gGameSpeed = 1; diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index d360eb955c..f9a0bde650 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -1721,7 +1722,7 @@ namespace OpenRCT2::Ui::Windows if (Editor::_numSelectedObjectsForType[EnumValue(ObjectType::water)] == 0) { // Reloads the default cyan water palette if no palette was selected. - LoadPalette(); + Drawing::LoadPalette(); } if (showFallbackWarning) ContextShowError(STR_OBJECT_SELECTION_FALLBACK_IMAGES_WARNING, kStringIdEmpty, {}); diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 6709afca4e..748e4b5d1a 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -47,6 +47,7 @@ #include "drawing/IDrawingEngine.h" #include "drawing/Image.h" #include "drawing/LightFX.h" +#include "drawing/Palette.h" #include "drawing/PickupPeep.h" #include "entity/EntityTweener.h" #include "entity/PatrolArea.h" @@ -1390,7 +1391,7 @@ namespace OpenRCT2 if (GameIsNotPaused()) { - gPaletteEffectFrame += gCurrentDeltaTime; + Drawing::gPaletteEffectFrame += gCurrentDeltaTime; } DateUpdateRealTimeOfDay(); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 416a9a2f16..830607f900 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -28,7 +28,7 @@ #include "core/FileSystem.hpp" #include "core/Path.hpp" #include "core/String.hpp" -#include "drawing/Drawing.h" +#include "drawing/Palette.h" #include "drawing/ScrollingText.h" #include "entity/EntityList.h" #include "entity/EntityRegistry.h" @@ -374,7 +374,7 @@ void GameLoadInit() gWindowUpdateTicks = 0; gCurrentRealTimeTicks = 0; - LoadPalette(); + Drawing::LoadPalette(); if (!gOpenRCT2Headless) { diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 33bdb376cb..37aca8d4d2 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -16,7 +16,7 @@ #include "ReplayManager.h" #include "actions/GameActionRunner.h" #include "config/Config.h" -#include "drawing/Drawing.h" +#include "drawing/Palette.h" #include "entity/EntityTweener.h" #include "entity/PatrolArea.h" #include "interface/Screenshot.h" @@ -84,7 +84,7 @@ namespace OpenRCT2 auto clipboardIntent = Intent(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD); ContextBroadcastIntent(&clipboardIntent); - LoadPalette(); + Drawing::LoadPalette(); CheatsReset(); ClearRestrictedScenery(); diff --git a/src/openrct2/drawing/BlendColourMap.cpp b/src/openrct2/drawing/BlendColourMap.cpp index fd400ea0c1..fa1283cb9d 100644 --- a/src/openrct2/drawing/BlendColourMap.cpp +++ b/src/openrct2/drawing/BlendColourMap.cpp @@ -15,6 +15,7 @@ #include "../core/EnumUtils.hpp" #include "Drawing.h" + #include "Palette.h" #include "PaletteType.h" #include diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 7d1ad5f2b3..32a97531d3 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -10,23 +10,16 @@ #include "Drawing.h" #include "../Context.h" -#include "../Diagnostic.h" #include "../Game.h" #include "../GameState.h" -#include "../OpenRCT2.h" #include "../SpriteIds.h" #include "../config/Config.h" -#include "../core/Guard.hpp" #include "../interface/ScreenCoords.hpp" -#include "../object/ObjectEntryManager.h" -#include "../object/WaterEntry.h" -#include "../util/Util.h" -#include "../world/Weather.h" #include "Drawing.Sprite.h" #include "FilterPaletteIds.h" #include "Font.h" -#include "LightFX.h" #include "NewDrawing.h" +#include "Palette.h" #include "Rectangle.h" #include "RenderTarget.h" #include "Text.h" @@ -38,19 +31,6 @@ using namespace OpenRCT2; using namespace OpenRCT2::Drawing; -static constexpr auto kPaletteOffsetDynamic = PaletteIndex::pi10; -static constexpr uint8_t kPaletteLengthDynamic = 236; - -static constexpr uint8_t kPaletteLengthWaterWaves = 5; -static constexpr uint8_t kPaletteLengthWaterSparkles = 5; - -static constexpr auto kPaletteOffsetAnimated = PaletteIndex::waterWaves0; -static constexpr uint8_t kPaletteLengthAnimated = 16; - -GamePalette gPalette; -GamePalette gGamePalette; -uint32_t gPaletteEffectFrame; - bool gPaintForceRedraw{ false }; static constexpr FilterPaletteID kGlassPaletteIds[kColourNumTotal] = { @@ -430,70 +410,6 @@ void GfxFilterPixel(RenderTarget& rt, const ScreenCoordsXY& coords, FilterPalett Rectangle::filter(rt, { coords, coords }, palette); } -/** - * - * rct2: 0x00683854 - * a1 (ebx) - * product (cl) - */ -void GfxTransposePalette(ImageIndex pal, uint8_t product) -{ - const auto* g1 = GfxGetG1Palette(pal); - if (g1 == nullptr) - return; - - auto index = g1->startIndex; - auto* src = g1->palette; - - for (auto numColours = g1->numColours; numColours > 0; numColours--) - { - auto& dst = gGamePalette[index]; - // Make sure the image never gets darker than the void colour (not-quite-black), to avoid the background colour - // jumping between void and 100% black. - dst.blue = std::max(35, ((src->blue * product) >> 8)); - dst.green = std::max(35, ((src->green * product) >> 8)); - dst.red = std::max(23, ((src->red * product) >> 8)); - src++; - - index++; - } - UpdatePalette(gGamePalette, PaletteIndex::pi10, 236); -} - -/** - * - * rct2: 0x006837E3 - */ -void LoadPalette() -{ - if (gOpenRCT2NoGraphics) - { - return; - } - - const auto& waterEntry = getActiveWaterEntry(); - Guard::Assert(waterEntry.mainPalette != kImageIndexUndefined, "Failed to load water palette"); - auto palette = waterEntry.mainPalette; - - const auto* g1 = GfxGetG1Palette(palette); - if (g1 != nullptr) - { - auto index = g1->startIndex; - auto* src = g1->palette; - for (auto numColours = g1->numColours; numColours > 0; numColours--) - { - auto& dst = gGamePalette[index]; - dst.blue = src->blue; - dst.green = src->green; - dst.red = src->red; - src++; - index++; - } - } - UpdatePalette(gGamePalette, PaletteIndex::pi10, 236); - GfxInvalidateScreen(); -} - /** * * rct2: 0x006ED7E5 @@ -590,191 +506,10 @@ FilterPaletteID GetGlassPaletteId(Colour c) return kGlassPaletteIds[EnumValue(c)]; } -void UpdatePalette(std::span palette, PaletteIndex startIndex, int32_t numColours) -{ - for (int32_t i = EnumValue(startIndex); i < numColours + EnumValue(startIndex); i++) - { - const auto& colour = palette[i]; - uint8_t b = colour.blue; - uint8_t g = colour.green; - uint8_t r = colour.red; - - if (LightFx::IsAvailable()) - { - LightFx::ApplyPaletteFilter(i, &r, &g, &b); - } - else - { - float night = gDayNightCycle; - if (night >= 0 && Weather::gLightningFlash == 0) - { - r = Lerp(r, SoftLight(r, 8), night); - g = Lerp(g, SoftLight(g, 8), night); - b = Lerp(b, SoftLight(b, 128), night); - } - } - - gPalette[i].blue = b; - gPalette[i].green = g; - gPalette[i].red = r; - gPalette[i].alpha = 0; - } - - // Fix #1749 and #6535: rainbow path, donut shop and pause button contain black spots that should be white. - gPalette[255].blue = 255; - gPalette[255].green = 255; - gPalette[255].red = 255; - gPalette[255].alpha = 0; - - if (!gOpenRCT2Headless) - { - DrawingEngineSetPalette(gPalette); - } -} - -/** - * - * rct2: 0x006838BD - */ -void UpdatePaletteEffects() -{ - const auto& waterEntry = getActiveWaterEntry(); - - if (Weather::gLightningFlash == 1) - { - // Change palette to lighter colour during lightning - auto palette = waterEntry.mainPalette; - const auto* g1 = GfxGetG1Palette(palette); - if (g1 != nullptr) - { - auto startIndex = g1->startIndex; - - for (int32_t i = 0; i < g1->numColours; i++) - { - auto& paletteOffset = gGamePalette[startIndex + i]; - const auto& g1PaletteEntry = g1->palette[i]; - paletteOffset.blue = -((0xFF - g1PaletteEntry.blue) / 2) - 1; - paletteOffset.green = -((0xFF - g1PaletteEntry.green) / 2) - 1; - paletteOffset.red = -((0xFF - g1PaletteEntry.red) / 2) - 1; - } - - UpdatePalette(gGamePalette, kPaletteOffsetDynamic, kPaletteLengthDynamic); - } - Weather::gLightningFlash++; - } - else - { - if (Weather::gLightningFlash == 2) - { - // Change palette back to normal after lightning - auto palette = waterEntry.mainPalette; - const auto* g1 = GfxGetG1Palette(palette); - if (g1 != nullptr) - { - auto startIndex = g1->startIndex; - - for (int32_t i = 0; i < g1->numColours; i++) - { - auto& paletteOffset = gGamePalette[startIndex + i]; - const auto& g1PaletteEntry = g1->palette[i]; - paletteOffset.blue = g1PaletteEntry.blue; - paletteOffset.green = g1PaletteEntry.green; - paletteOffset.red = g1PaletteEntry.red; - } - } - } - - // Animate the water/lava/chain movement palette - uint32_t shade = 0; - if (Config::Get().general.renderWeatherGloom) - { - auto paletteId = Weather::getWeatherGloomPaletteId(getGameState().weatherCurrent); - if (paletteId != FilterPaletteID::paletteNull) - { - shade = 1; - if (paletteId != FilterPaletteID::paletteDarken1) - { - shade = 2; - } - } - } - uint32_t j = gPaletteEffectFrame; - j = ((static_cast((~j / 2) * 128) * 15) >> 16); - - auto waterId = waterEntry.waterWavesPalette; - const auto* g1 = GfxGetG1Palette(shade + waterId); - if (g1 != nullptr) - { - const auto* g1PaletteEntry = &g1->palette[j]; - int32_t n = kPaletteLengthWaterWaves; - for (int32_t i = 0; i < n; i++) - { - auto& vd = gGamePalette[EnumValue(PaletteIndex::waterWaves0) + i]; - vd.blue = g1PaletteEntry->blue; - vd.green = g1PaletteEntry->green; - vd.red = g1PaletteEntry->red; - g1PaletteEntry += 3; - if (g1PaletteEntry >= &g1->palette[3 * n]) - { - g1PaletteEntry -= 3 * n; - } - } - } - - waterId = waterEntry.waterSparklesPalette; - g1 = GfxGetG1Palette(shade + waterId); - if (g1 != nullptr) - { - auto* src = &g1->palette[j]; - int32_t n = kPaletteLengthWaterSparkles; - for (int32_t i = 0; i < n; i++) - { - auto& vd = gGamePalette[EnumValue(PaletteIndex::waterSparkles0) + i]; - vd.blue = src->blue; - vd.green = src->green; - vd.red = src->red; - src += 3; - if (src >= &g1->palette[3 * n]) - { - src -= 3 * n; - } - } - } - - j = (static_cast(gPaletteEffectFrame * -960) * 3) >> 16; - waterId = SPR_GAME_PALETTE_4; - g1 = GfxGetG1Palette(shade + waterId); - if (g1 != nullptr) - { - auto* src = &g1->palette[j]; - const int32_t n = 3; - for (int32_t i = 0; i < n; i++) - { - auto& vd = gGamePalette[EnumValue(PaletteIndex::primaryRemap0) + i]; - vd.blue = src->blue; - vd.green = src->green; - vd.red = src->red; - src++; - if (src >= &g1->palette[3]) - { - src -= n; - } - } - } - - UpdatePalette(gGamePalette, kPaletteOffsetAnimated, kPaletteLengthAnimated); - if (Weather::gLightningFlash == 2) - { - UpdatePalette(gGamePalette, kPaletteOffsetDynamic, kPaletteLengthDynamic); - Weather::gLightningFlash = 0; - } - } -} - void RefreshVideo() { ContextRecreateWindow(); - DrawingEngineSetPalette(gPalette); + DrawingEngineSetPalette(Drawing::gPalette); GfxInvalidateScreen(); } diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index e71d4f90de..7f1a4ec557 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -13,10 +13,8 @@ #include "Colour.h" #include "ImageId.hpp" #include "PaletteMap.h" -#include "PaletteType.h" #include -#include struct ScreenCoordsXY; struct ScreenLine; @@ -43,10 +41,6 @@ namespace OpenRCT2::Drawing constexpr uint8_t kPaletteTotalOffsets = 192; -extern OpenRCT2::Drawing::GamePalette gPalette; -extern OpenRCT2::Drawing::GamePalette gGamePalette; -extern uint32_t gPaletteEffectFrame; - extern const OpenRCT2::Drawing::TranslucentWindowPalette kTranslucentWindowPalettes[OpenRCT2::Drawing::kColourNumTotal]; extern bool gPaintForceRedraw; @@ -57,10 +51,6 @@ bool ClipRenderTarget( void GfxSetDirtyBlocks(const ScreenRect& rect); void GfxInvalidateScreen(); -// palette -void GfxTransposePalette(ImageIndex pal, uint8_t product); -void LoadPalette(); - // other void GfxClear(OpenRCT2::Drawing::RenderTarget& rt, OpenRCT2::Drawing::PaletteIndex paletteIndex); void GfxFilterPixel( @@ -85,9 +75,6 @@ void FASTCALL GfxDrawSpriteRawMasked( std::optional GetPaletteG1Index(OpenRCT2::Drawing::FilterPaletteID paletteId); std::optional GetPaletteMapForColour(OpenRCT2::Drawing::FilterPaletteID paletteId); -void UpdatePalette( - std::span palette, OpenRCT2::Drawing::PaletteIndex startIndex, int32_t numColours); -void UpdatePaletteEffects(); void RefreshVideo(); void ToggleWindowedMode(); diff --git a/src/openrct2/drawing/Palette.cpp b/src/openrct2/drawing/Palette.cpp new file mode 100644 index 0000000000..9cd5ffdf36 --- /dev/null +++ b/src/openrct2/drawing/Palette.cpp @@ -0,0 +1,285 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "Palette.h" + +#include "../Game.h" +#include "../GameState.h" +#include "../OpenRCT2.h" +#include "../SpriteIds.h" +#include "../config/Config.h" +#include "../object/WaterEntry.h" +#include "../util/Util.h" +#include "../world/Weather.h" +#include "Drawing.Sprite.h" +#include "Drawing.h" +#include "FilterPaletteIds.h" +#include "LightFX.h" +#include "NewDrawing.h" + +namespace OpenRCT2::Drawing +{ + static constexpr auto kPaletteOffsetDynamic = PaletteIndex::pi10; + static constexpr uint8_t kPaletteLengthDynamic = 236; + + static constexpr uint8_t kPaletteLengthWaterWaves = 5; + static constexpr uint8_t kPaletteLengthWaterSparkles = 5; + + static constexpr auto kPaletteOffsetAnimated = PaletteIndex::waterWaves0; + static constexpr uint8_t kPaletteLengthAnimated = 16; + + GamePalette gPalette; + GamePalette gGamePalette; + uint32_t gPaletteEffectFrame; + + void UpdatePalette(std::span palette, PaletteIndex startIndex, int32_t numColours) + { + for (int32_t i = EnumValue(startIndex); i < numColours + EnumValue(startIndex); i++) + { + const auto& colour = palette[i]; + uint8_t b = colour.blue; + uint8_t g = colour.green; + uint8_t r = colour.red; + + if (LightFx::IsAvailable()) + { + LightFx::ApplyPaletteFilter(i, &r, &g, &b); + } + else + { + float night = gDayNightCycle; + if (night >= 0 && Weather::gLightningFlash == 0) + { + r = Lerp(r, SoftLight(r, 8), night); + g = Lerp(g, SoftLight(g, 8), night); + b = Lerp(b, SoftLight(b, 128), night); + } + } + + gPalette[i].blue = b; + gPalette[i].green = g; + gPalette[i].red = r; + gPalette[i].alpha = 0; + } + + // Fix #1749 and #6535: rainbow path, donut shop and pause button contain black spots that should be white. + gPalette[255].blue = 255; + gPalette[255].green = 255; + gPalette[255].red = 255; + gPalette[255].alpha = 0; + + if (!gOpenRCT2Headless) + { + DrawingEngineSetPalette(gPalette); + } + } + + /** + * + * rct2: 0x006838BD + */ + void UpdatePaletteEffects() + { + const auto& waterEntry = getActiveWaterEntry(); + + if (Weather::gLightningFlash == 1) + { + // Change palette to lighter colour during lightning + auto palette = waterEntry.mainPalette; + const auto* g1 = GfxGetG1Palette(palette); + if (g1 != nullptr) + { + auto startIndex = g1->startIndex; + + for (int32_t i = 0; i < g1->numColours; i++) + { + auto& paletteOffset = gGamePalette[startIndex + i]; + const auto& g1PaletteEntry = g1->palette[i]; + paletteOffset.blue = -((0xFF - g1PaletteEntry.blue) / 2) - 1; + paletteOffset.green = -((0xFF - g1PaletteEntry.green) / 2) - 1; + paletteOffset.red = -((0xFF - g1PaletteEntry.red) / 2) - 1; + } + + UpdatePalette(gGamePalette, kPaletteOffsetDynamic, kPaletteLengthDynamic); + } + Weather::gLightningFlash++; + } + else + { + if (Weather::gLightningFlash == 2) + { + // Change palette back to normal after lightning + auto palette = waterEntry.mainPalette; + const auto* g1 = GfxGetG1Palette(palette); + if (g1 != nullptr) + { + auto startIndex = g1->startIndex; + + for (int32_t i = 0; i < g1->numColours; i++) + { + auto& paletteOffset = gGamePalette[startIndex + i]; + const auto& g1PaletteEntry = g1->palette[i]; + paletteOffset.blue = g1PaletteEntry.blue; + paletteOffset.green = g1PaletteEntry.green; + paletteOffset.red = g1PaletteEntry.red; + } + } + } + + // Animate the water/lava/chain movement palette + uint32_t shade = 0; + if (Config::Get().general.renderWeatherGloom) + { + auto paletteId = Weather::getWeatherGloomPaletteId(getGameState().weatherCurrent); + if (paletteId != FilterPaletteID::paletteNull) + { + shade = 1; + if (paletteId != FilterPaletteID::paletteDarken1) + { + shade = 2; + } + } + } + uint32_t j = gPaletteEffectFrame; + j = ((static_cast((~j / 2) * 128) * 15) >> 16); + + auto waterId = waterEntry.waterWavesPalette; + const auto* g1 = GfxGetG1Palette(shade + waterId); + if (g1 != nullptr) + { + const auto* g1PaletteEntry = &g1->palette[j]; + int32_t n = kPaletteLengthWaterWaves; + for (int32_t i = 0; i < n; i++) + { + auto& vd = gGamePalette[EnumValue(PaletteIndex::waterWaves0) + i]; + vd.blue = g1PaletteEntry->blue; + vd.green = g1PaletteEntry->green; + vd.red = g1PaletteEntry->red; + g1PaletteEntry += 3; + if (g1PaletteEntry >= &g1->palette[3 * n]) + { + g1PaletteEntry -= 3 * n; + } + } + } + + waterId = waterEntry.waterSparklesPalette; + g1 = GfxGetG1Palette(shade + waterId); + if (g1 != nullptr) + { + auto* src = &g1->palette[j]; + int32_t n = kPaletteLengthWaterSparkles; + for (int32_t i = 0; i < n; i++) + { + auto& vd = gGamePalette[EnumValue(PaletteIndex::waterSparkles0) + i]; + vd.blue = src->blue; + vd.green = src->green; + vd.red = src->red; + src += 3; + if (src >= &g1->palette[3 * n]) + { + src -= 3 * n; + } + } + } + + j = (static_cast(gPaletteEffectFrame * -960) * 3) >> 16; + waterId = SPR_GAME_PALETTE_4; + g1 = GfxGetG1Palette(shade + waterId); + if (g1 != nullptr) + { + auto* src = &g1->palette[j]; + const int32_t n = 3; + for (int32_t i = 0; i < n; i++) + { + auto& vd = gGamePalette[EnumValue(PaletteIndex::primaryRemap0) + i]; + vd.blue = src->blue; + vd.green = src->green; + vd.red = src->red; + src++; + if (src >= &g1->palette[3]) + { + src -= n; + } + } + } + + UpdatePalette(gGamePalette, kPaletteOffsetAnimated, kPaletteLengthAnimated); + if (Weather::gLightningFlash == 2) + { + UpdatePalette(gGamePalette, kPaletteOffsetDynamic, kPaletteLengthDynamic); + Weather::gLightningFlash = 0; + } + } + } + + /** + * + * rct2: 0x00683854 + * a1 (ebx) + * product (cl) + */ + void GfxTransposePalette(ImageIndex pal, uint8_t product) + { + const auto* g1 = GfxGetG1Palette(pal); + if (g1 == nullptr) + return; + + auto index = g1->startIndex; + auto* src = g1->palette; + + for (auto numColours = g1->numColours; numColours > 0; numColours--) + { + auto& dst = gGamePalette[index]; + // Make sure the image never gets darker than the void colour (not-quite-black), to avoid the background colour + // jumping between void and 100% black. + dst.blue = std::max(35, ((src->blue * product) >> 8)); + dst.green = std::max(35, ((src->green * product) >> 8)); + dst.red = std::max(23, ((src->red * product) >> 8)); + src++; + + index++; + } + UpdatePalette(gGamePalette, PaletteIndex::pi10, 236); + } + + /** + * + * rct2: 0x006837E3 + */ + void LoadPalette() + { + if (gOpenRCT2NoGraphics) + { + return; + } + + const auto& waterEntry = getActiveWaterEntry(); + Guard::Assert(waterEntry.mainPalette != kImageIndexUndefined, "Failed to load water palette"); + auto palette = waterEntry.mainPalette; + + const auto* g1 = GfxGetG1Palette(palette); + if (g1 != nullptr) + { + auto index = g1->startIndex; + auto* src = g1->palette; + for (auto numColours = g1->numColours; numColours > 0; numColours--) + { + auto& dst = gGamePalette[index]; + dst.blue = src->blue; + dst.green = src->green; + dst.red = src->red; + src++; + index++; + } + } + UpdatePalette(gGamePalette, PaletteIndex::pi10, 236); + GfxInvalidateScreen(); + } +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/drawing/Palette.h b/src/openrct2/drawing/Palette.h new file mode 100644 index 0000000000..166892f127 --- /dev/null +++ b/src/openrct2/drawing/Palette.h @@ -0,0 +1,30 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "ImageIndexType.h" +#include "PaletteType.h" + +#include +#include + +namespace OpenRCT2::Drawing +{ + enum class PaletteIndex : uint8_t; + + extern GamePalette gPalette; + extern GamePalette gGamePalette; + extern uint32_t gPaletteEffectFrame; + + void UpdatePalette(std::span palette, PaletteIndex startIndex, int32_t numColours); + void UpdatePaletteEffects(); + void GfxTransposePalette(ImageIndex pal, uint8_t product); + void LoadPalette(); +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index aae0037dab..3151862caf 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -24,6 +24,7 @@ #include "../core/String.hpp" #include "../drawing/Drawing.h" #include "../drawing/NewDrawing.h" +#include "../drawing/Palette.h" #include "../drawing/X8DrawingEngine.h" #include "../localisation/Formatter.h" #include "../localisation/StringIds.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index bc103bd1d5..b5bc6be0ce 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -266,6 +266,7 @@ + @@ -911,6 +912,7 @@ + diff --git a/src/openrct2/object/WaterObject.cpp b/src/openrct2/object/WaterObject.cpp index 7356ed49ad..be593e4c14 100644 --- a/src/openrct2/object/WaterObject.cpp +++ b/src/openrct2/object/WaterObject.cpp @@ -12,8 +12,8 @@ #include "../core/Guard.hpp" #include "../core/IStream.hpp" #include "../core/Json.hpp" -#include "../drawing/Drawing.h" #include "../drawing/ImageImporter.h" +#include "../drawing/Palette.h" #include "../drawing/Text.h" #include "../interface/ScreenCoords.hpp" #include "../localisation/Language.h" @@ -38,7 +38,7 @@ namespace OpenRCT2 _legacyType.waterWavesPalette = _legacyType.mainPalette + 1; _legacyType.waterSparklesPalette = _legacyType.mainPalette + 4; - LoadPalette(); + Drawing::LoadPalette(); } void WaterObject::Unload() diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index bca9c7b149..1c5a5832d1 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -16,6 +16,7 @@ #include "../drawing/Drawing.String.h" #include "../drawing/Drawing.h" #include "../drawing/IDrawingEngine.h" +#include "../drawing/Palette.h" #include "../drawing/PickupPeep.h" #include "../drawing/Text.h" #include "../interface/Viewport.h" diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 8b473697e6..b18129216c 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -20,7 +20,7 @@ #include "../core/Guard.hpp" #include "../core/Path.hpp" #include "../core/Random.hpp" -#include "../drawing/Drawing.h" +#include "../drawing/Palette.h" #include "../drawing/PaletteIndex.h" #include "../entity/Duck.h" #include "../entity/Staff.h" @@ -363,7 +363,7 @@ static void ScenarioUpdateDayNightCycle() // Only update palette if day / night cycle has changed if (gDayNightCycle != currentDayNightCycle) { - UpdatePalette(gGamePalette, Drawing::PaletteIndex::pi10, 236); + Drawing::UpdatePalette(Drawing::gGamePalette, Drawing::PaletteIndex::pi10, 236); } } diff --git a/src/openrct2/scenes/editor/EditorController.cpp b/src/openrct2/scenes/editor/EditorController.cpp index c8fd2c45f5..4fd3e905d3 100644 --- a/src/openrct2/scenes/editor/EditorController.cpp +++ b/src/openrct2/scenes/editor/EditorController.cpp @@ -17,6 +17,7 @@ #include "../../audio/Audio.h" #include "../../core/EnumUtils.hpp" #include "../../drawing/Drawing.h" +#include "../../drawing/Palette.h" #include "../../entity/EntityList.h" #include "../../entity/Guest.h" #include "../../entity/Staff.h" @@ -673,7 +674,7 @@ namespace OpenRCT2::Editor auto newPaletteEntry = ObjectEntryDescriptor(*item); if (objectManager.GetLoadedObject(newPaletteEntry) != nullptr || objectManager.LoadObject(newPaletteEntry) != nullptr) { - LoadPalette(); + Drawing::LoadPalette(); } else { diff --git a/src/openrct2/scenes/editor/EditorScene.cpp b/src/openrct2/scenes/editor/EditorScene.cpp index 42ee763e0d..b4ad506552 100644 --- a/src/openrct2/scenes/editor/EditorScene.cpp +++ b/src/openrct2/scenes/editor/EditorScene.cpp @@ -20,7 +20,7 @@ #include "../../actions/park/LandSetRightsAction.h" #include "../../audio/Audio.h" #include "../../core/Path.hpp" -#include "../../drawing/Drawing.h" +#include "../../drawing/Palette.h" #include "../../entity/EntityList.h" #include "../../entity/Guest.h" #include "../../entity/PatrolArea.h" @@ -58,7 +58,7 @@ void EditorScene::Load() OpenEditorWindows(); resetMainViewport(); - LoadPalette(); + Drawing::LoadPalette(); gScreenAge = 0; gameState.scenarioOptions.name = LanguageGetString(STR_MY_NEW_SCENARIO); @@ -312,7 +312,7 @@ void EditorScene::FinaliseMainView() windowManager->BroadcastIntent(Intent(INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD)); gWindowUpdateTicks = 0; - LoadPalette(); + Drawing::LoadPalette(); } void EditorScene::resetMainViewport() diff --git a/src/openrct2/scenes/editor/TrackDesignerScene.cpp b/src/openrct2/scenes/editor/TrackDesignerScene.cpp index 2315f7e582..c5e5e0d483 100644 --- a/src/openrct2/scenes/editor/TrackDesignerScene.cpp +++ b/src/openrct2/scenes/editor/TrackDesignerScene.cpp @@ -15,7 +15,7 @@ #include "../../GameState.h" #include "../../OpenRCT2.h" #include "../../audio/Audio.h" -#include "../../drawing/Drawing.h" +#include "../../drawing/Palette.h" #include "../../world/Map.h" #include "EditorController.h" @@ -39,7 +39,7 @@ void TrackDesignerScene::Load() OpenEditorWindows(); resetMainViewport(); - LoadPalette(); + Drawing::LoadPalette(); GameLoadScripts(); GameNotifyMapChanged(); diff --git a/src/openrct2/scenes/editor/TrackManagerScene.cpp b/src/openrct2/scenes/editor/TrackManagerScene.cpp index e0ee139cb8..4ff305777b 100644 --- a/src/openrct2/scenes/editor/TrackManagerScene.cpp +++ b/src/openrct2/scenes/editor/TrackManagerScene.cpp @@ -15,7 +15,7 @@ #include "../../GameState.h" #include "../../OpenRCT2.h" #include "../../audio/Audio.h" -#include "../../drawing/Drawing.h" +#include "../../drawing/Palette.h" #include "../../world/Map.h" #include "EditorController.h" @@ -39,7 +39,7 @@ void TrackManagerScene::Load() OpenEditorWindows(); resetMainViewport(); - LoadPalette(); + Drawing::LoadPalette(); GameLoadScripts(); GameNotifyMapChanged(); diff --git a/src/openrct2/scenes/intro/IntroScene.cpp b/src/openrct2/scenes/intro/IntroScene.cpp index bb6de0d5de..a1378468d0 100644 --- a/src/openrct2/scenes/intro/IntroScene.cpp +++ b/src/openrct2/scenes/intro/IntroScene.cpp @@ -17,6 +17,7 @@ #include "../../audio/AudioMixer.h" #include "../../drawing/Drawing.h" #include "../../drawing/NewDrawing.h" +#include "../../drawing/Palette.h" #include "../../drawing/PaletteIndex.h" #include "../../drawing/Rectangle.h" #include "../../scenes/SceneManager.h" diff --git a/src/openrct2/scenes/title/TitleScene.cpp b/src/openrct2/scenes/title/TitleScene.cpp index 62bf97290f..9ca14c5c69 100644 --- a/src/openrct2/scenes/title/TitleScene.cpp +++ b/src/openrct2/scenes/title/TitleScene.cpp @@ -19,6 +19,7 @@ #include "../../config/Config.h" #include "../../core/Console.hpp" #include "../../drawing/Drawing.h" +#include "../../drawing/Palette.h" #include "../../interface/Screenshot.h" #include "../../interface/Window.h" #include "../../network/NetworkBase.h" @@ -153,7 +154,7 @@ void TitleScene::Tick() { gameStateUpdateLogic(); } - UpdatePaletteEffects(); + Drawing::UpdatePaletteEffects(); // update_weather_animation(); } diff --git a/test/tests/PlayTests.cpp b/test/tests/PlayTests.cpp index bd40a6ac72..c367904f71 100644 --- a/test/tests/PlayTests.cpp +++ b/test/tests/PlayTests.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +61,7 @@ static std::unique_ptr localStartGame(const std::string& parkPath) gameState.entities.resetEntitySpatialIndices(); ResetAllSpriteQuadrantPlacements(); - LoadPalette(); + Drawing::LoadPalette(); EntityTweener::get().reset(); MapAnimations::MarkAllTiles(); FixInvalidVehicleSpriteSizes(); diff --git a/test/tests/S6ImportExportTests.cpp b/test/tests/S6ImportExportTests.cpp index 064278dd4e..a6499a0767 100644 --- a/test/tests/S6ImportExportTests.cpp +++ b/test/tests/S6ImportExportTests.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +61,7 @@ static void GameInit(bool retainSpatialIndices) gameState.entities.resetEntitySpatialIndices(); ResetAllSpriteQuadrantPlacements(); - LoadPalette(); + Drawing::LoadPalette(); EntityTweener::get().reset(); MapAnimations::MarkAllTiles(); FixInvalidVehicleSpriteSizes();