From eb2b0c153707889d5481de63d26924a0df5b7c97 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 10 Jan 2022 13:10:56 +0100 Subject: [PATCH] Move platform_update_palette() to Drawing.cpp --- src/openrct2/Game.cpp | 6 ++-- src/openrct2/drawing/Drawing.cpp | 53 ++++++++++++++++++++++++++++-- src/openrct2/drawing/Drawing.h | 1 + src/openrct2/platform/Shared.cpp | 46 -------------------------- src/openrct2/platform/platform.h | 1 - src/openrct2/scenario/Scenario.cpp | 2 +- 6 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index c2fdf8c540..caa7e6954c 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -167,7 +167,7 @@ void update_palette_effects() paletteOffset[(i * 4) + 1] = -((0xFF - g1->offset[(i * 3) + 1]) / 2) - 1; paletteOffset[(i * 4) + 2] = -((0xFF - g1->offset[(i * 3) + 2]) / 2) - 1; } - platform_update_palette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); + UpdatePalette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); } gClimateLightningFlash++; } @@ -286,10 +286,10 @@ void update_palette_effects() } } - platform_update_palette(gGamePalette, PALETTE_OFFSET_ANIMATED, PALETTE_LENGTH_ANIMATED); + UpdatePalette(gGamePalette, PALETTE_OFFSET_ANIMATED, PALETTE_LENGTH_ANIMATED); if (gClimateLightningFlash == 2) { - platform_update_palette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); + UpdatePalette(gGamePalette, PALETTE_OFFSET_DYNAMIC, PALETTE_LENGTH_DYNAMIC); gClimateLightningFlash = 0; } } diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 93757015e1..5d5cf48c28 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -10,6 +10,7 @@ #include "Drawing.h" #include "../Context.h" +#include "../Game.h" #include "../OpenRCT2.h" #include "../common.h" #include "../core/Guard.hpp" @@ -17,8 +18,10 @@ #include "../platform/platform.h" #include "../sprites.h" #include "../util/Util.h" +#include "../world/Climate.h" #include "../world/Location.hpp" #include "../world/Water.h" +#include "LightFX.h" #include @@ -600,7 +603,7 @@ void gfx_transpose_palette(int32_t pal, uint8_t product) source_pointer += 3; dest_pointer += 4; } - platform_update_palette(gGamePalette, 10, 236); + UpdatePalette(gGamePalette, 10, 236); } } @@ -641,7 +644,7 @@ void load_palette() dst += 4; } } - platform_update_palette(gGamePalette, 10, 236); + UpdatePalette(gGamePalette, 10, 236); gfx_invalidate_screen(); } @@ -787,3 +790,49 @@ FilterPaletteID GetGlassPaletteId(colour_t c) { return GlassPaletteIds[c]; } + +void UpdatePalette(const uint8_t* colours, int32_t start_index, int32_t num_colours) +{ + colours += start_index * 4; + + for (int32_t i = start_index; i < num_colours + start_index; i++) + { + uint8_t r = colours[2]; + uint8_t g = colours[1]; + uint8_t b = colours[0]; + +#ifdef __ENABLE_LIGHTFX__ + if (lightfx_is_available()) + { + lightfx_apply_palette_filter(i, &r, &g, &b); + } + else +#endif + { + float night = gDayNightCycle; + if (night >= 0 && gClimateLightningFlash == 0) + { + r = lerp(r, soft_light(r, 8), night); + g = lerp(g, soft_light(g, 8), night); + b = lerp(b, soft_light(b, 128), night); + } + } + + gPalette[i].Red = r; + gPalette[i].Green = g; + gPalette[i].Blue = b; + gPalette[i].Alpha = 0; + colours += 4; + } + + // Fix #1749 and #6535: rainbow path, donut shop and pause button contain black spots that should be white. + gPalette[255].Alpha = 0; + gPalette[255].Red = 255; + gPalette[255].Green = 255; + gPalette[255].Blue = 255; + + if (!gOpenRCT2Headless) + { + drawing_engine_set_palette(gPalette); + } +} diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index eea7daa0c3..8a81b79a4d 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -599,5 +599,6 @@ extern void (*mask_fn)( 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); #include "NewDrawing.h" diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index 513a965e91..dbe4637abd 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -141,52 +141,6 @@ namespace Platform GamePalette gPalette; -void platform_update_palette(const uint8_t* colours, int32_t start_index, int32_t num_colours) -{ - colours += start_index * 4; - - for (int32_t i = start_index; i < num_colours + start_index; i++) - { - uint8_t r = colours[2]; - uint8_t g = colours[1]; - uint8_t b = colours[0]; - -#ifdef __ENABLE_LIGHTFX__ - if (lightfx_is_available()) - { - lightfx_apply_palette_filter(i, &r, &g, &b); - } - else -#endif - { - float night = gDayNightCycle; - if (night >= 0 && gClimateLightningFlash == 0) - { - r = lerp(r, soft_light(r, 8), night); - g = lerp(g, soft_light(g, 8), night); - b = lerp(b, soft_light(b, 128), night); - } - } - - gPalette[i].Red = r; - gPalette[i].Green = g; - gPalette[i].Blue = b; - gPalette[i].Alpha = 0; - colours += 4; - } - - // Fix #1749 and #6535: rainbow path, donut shop and pause button contain black spots that should be white. - gPalette[255].Alpha = 0; - gPalette[255].Red = 255; - gPalette[255].Green = 255; - gPalette[255].Blue = 255; - - if (!gOpenRCT2Headless) - { - drawing_engine_set_palette(gPalette); - } -} - void platform_toggle_windowed_mode() { int32_t targetMode = gConfigGeneral.fullscreen_mode == 0 ? 2 : 0; diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index b711360e88..d8692737a6 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -82,7 +82,6 @@ struct file_dialog_desc }; // Platform shared definitions -void platform_update_palette(const uint8_t* colours, int32_t start_index, int32_t num_colours); void platform_toggle_windowed_mode(); void platform_refresh_video(bool recreate_window); diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 50963f6af8..eb54d46dfb 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -389,7 +389,7 @@ static void scenario_update_daynight_cycle() // Only update palette if day / night cycle has changed if (gDayNightCycle != currentDayNightCycle) { - platform_update_palette(gGamePalette, 10, 236); + UpdatePalette(gGamePalette, 10, 236); } }