From f66c0a65f9da330c164cfe2625bcd30fbfd2497b Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Sat, 22 Aug 2026 11:19:36 +0200 Subject: [PATCH] Move PaletteMap implementation to PaletteMap.cpp (#26969) --- src/openrct2/drawing/Drawing.cpp | 48 --------------------- src/openrct2/drawing/PaletteMap.cpp | 65 +++++++++++++++++++++++++++++ src/openrct2/libopenrct2.vcxproj | 1 + 3 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 src/openrct2/drawing/PaletteMap.cpp diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index faa6e7608b..56033a7311 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -47,54 +47,6 @@ static constexpr uint8_t kPaletteLengthWaterSparkles = 5; static constexpr auto kPaletteOffsetAnimated = PaletteIndex::waterWaves0; static constexpr uint8_t kPaletteLengthAnimated = 16; -static auto _defaultPaletteMapping = []() { - std::array res; - for (size_t i = 0; i < std::size(res); i++) - { - res[i] = static_cast(i); - } - return res; -}(); - -PaletteMap PaletteMap::GetDefault() -{ - return PaletteMap(_defaultPaletteMapping); -} - -PaletteIndex& PaletteMap::operator[](size_t index) -{ - return _data[index]; -} - -PaletteIndex PaletteMap::operator[](size_t index) const -{ - return _data[index]; -} - -PaletteIndex PaletteMap::Blend(PaletteIndex src, PaletteIndex dst) const -{ - const auto srcValue = EnumValue(src); - const auto dstValue = EnumValue(dst); -#ifdef _DEBUG - // src = 0 would be transparent so there is no blend palette for that, hence (src - 1) - assert(src != PaletteIndex::transparent); - assert(static_cast(srcValue - 1) < _numMaps); - assert(static_cast(dstValue) < _mapLength); -#endif - auto idx = ((srcValue - 1) * 256) + dstValue; - return _data[idx]; -} - -void PaletteMap::Copy(PaletteIndex dstIndex, const PaletteMap& src, PaletteIndex srcIndex, size_t length) -{ - auto srcOffset = EnumValue(srcIndex); - auto dstOffset = EnumValue(dstIndex); - auto maxLength = std::min(_data.size() - srcOffset, _data.size() - dstOffset); - assert(length <= maxLength); - auto copyLength = std::min(length, maxLength); - std::copy(src._data.begin() + srcOffset, src._data.begin() + srcOffset + copyLength, _data.begin() + dstOffset); -} - GamePalette gPalette; GamePalette gGamePalette; uint32_t gPaletteEffectFrame; diff --git a/src/openrct2/drawing/PaletteMap.cpp b/src/openrct2/drawing/PaletteMap.cpp new file mode 100644 index 0000000000..11c042e5f1 --- /dev/null +++ b/src/openrct2/drawing/PaletteMap.cpp @@ -0,0 +1,65 @@ +/***************************************************************************** + * 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 "PaletteMap.h" + +#include "../core/EnumUtils.hpp" + +#include + +namespace OpenRCT2::Drawing +{ + static auto _defaultPaletteMapping = []() { + std::array res; + for (size_t i = 0; i < std::size(res); i++) + { + res[i] = static_cast(i); + } + return res; + }(); + + PaletteMap PaletteMap::GetDefault() + { + return PaletteMap(_defaultPaletteMapping); + } + + PaletteIndex& PaletteMap::operator[](size_t index) + { + return _data[index]; + } + + PaletteIndex PaletteMap::operator[](size_t index) const + { + return _data[index]; + } + + PaletteIndex PaletteMap::Blend(PaletteIndex src, PaletteIndex dst) const + { + const auto srcValue = EnumValue(src); + const auto dstValue = EnumValue(dst); +#ifdef _DEBUG + // src = 0 would be transparent so there is no blend palette for that, hence (src - 1) + assert(src != PaletteIndex::transparent); + assert(static_cast(srcValue - 1) < _numMaps); + assert(static_cast(dstValue) < _mapLength); +#endif + auto idx = ((srcValue - 1) * 256) + dstValue; + return _data[idx]; + } + + void PaletteMap::Copy(PaletteIndex dstIndex, const PaletteMap& src, PaletteIndex srcIndex, size_t length) + { + auto srcOffset = EnumValue(srcIndex); + auto dstOffset = EnumValue(dstIndex); + auto maxLength = std::min(_data.size() - srcOffset, _data.size() - dstOffset); + assert(length <= maxLength); + auto copyLength = std::min(length, maxLength); + std::copy(src._data.begin() + srcOffset, src._data.begin() + srcOffset + copyLength, _data.begin() + dstOffset); + } +} // namespace OpenRCT2::Drawing diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 1ed1d40445..2587d5c6d7 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -909,6 +909,7 @@ +