1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-19 05:52:27 +01:00

Move GamePalette into ColourPalette.h, use namespace for it also

This commit is contained in:
ζeh Matt
2024-12-04 22:48:31 +02:00
parent 8d645c6316
commit 0e1517be4f
16 changed files with 50 additions and 59 deletions

View File

@@ -21,6 +21,7 @@
#include <vector> #include <vector>
using namespace OpenRCT2::Ui; using namespace OpenRCT2::Ui;
using namespace OpenRCT2::Drawing;
constexpr uint32_t kUnusedIndex = 0xFFFFFFFF; constexpr uint32_t kUnusedIndex = 0xFFFFFFFF;
@@ -206,7 +207,7 @@ void TextureCache::CreateTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, 0, GL_R8UI, PALETTE_SIZE, PALETTE_SIZE, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, blendArray); GL_TEXTURE_2D, 0, GL_R8UI, kGamePaletteSize, kGamePaletteSize, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, blendArray);
} }
_initialized = true; _initialized = true;

View File

@@ -214,7 +214,7 @@ static bool SpriteImageExport(const G1Element& spriteElement, u8string_view outP
image.Height = dpi.height; image.Height = dpi.height;
image.Depth = 8; image.Depth = 8;
image.Stride = dpi.LineStride(); image.Stride = dpi.LineStride();
image.Palette = std::make_unique<GamePalette>(StandardPalette); image.Palette = StandardPalette;
image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen); image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen);
Imaging::WriteToFile(outPath, image, IMAGE_FORMAT::PNG); Imaging::WriteToFile(outPath, image, IMAGE_FORMAT::PNG);
return true; return true;

View File

@@ -189,7 +189,7 @@ namespace OpenRCT2::Imaging
if (image.Depth == 8) if (image.Depth == 8)
{ {
if (image.Palette == nullptr) if (!image.Palette.has_value())
{ {
throw std::runtime_error("Expected a palette for 8-bit image."); throw std::runtime_error("Expected a palette for 8-bit image.");
} }

View File

@@ -14,6 +14,7 @@
#include <functional> #include <functional>
#include <istream> #include <istream>
#include <memory> #include <memory>
#include <optional>
#include <string_view> #include <string_view>
#include <vector> #include <vector>
@@ -37,7 +38,7 @@ struct Image
// Data // Data
std::vector<uint8_t> Pixels; std::vector<uint8_t> Pixels;
std::unique_ptr<GamePalette> Palette; std::optional<OpenRCT2::Drawing::GamePalette> Palette;
uint32_t Stride{}; uint32_t Stride{};
}; };

View File

@@ -0,0 +1,21 @@
#pragma once
#include <array>
#include <cstdint>
namespace OpenRCT2::Drawing
{
struct PaletteBGRA
{
uint8_t Blue{};
uint8_t Green{};
uint8_t Red{};
uint8_t Alpha{};
};
constexpr auto kGamePaletteSize = 256u;
using GamePalette = std::array<PaletteBGRA, kGamePaletteSize>;
} // namespace OpenRCT2::Drawing

View File

@@ -95,7 +95,7 @@ void PaletteMap::Copy(size_t dstIndex, const PaletteMap& src, size_t srcIndex, s
std::memcpy(&_data[dstIndex], &src._data[srcIndex], copyLength); std::memcpy(&_data[dstIndex], &src._data[srcIndex], copyLength);
} }
GamePalette gPalette; OpenRCT2::Drawing::GamePalette gPalette;
uint8_t gGamePalette[256 * 4]; uint8_t gGamePalette[256 * 4];
uint32_t gPaletteEffectFrame; uint32_t gPaletteEffectFrame;

View File

@@ -14,10 +14,12 @@
#include "../interface/Colour.h" #include "../interface/Colour.h"
#include "../interface/ZoomLevel.h" #include "../interface/ZoomLevel.h"
#include "../world/Location.hpp" #include "../world/Location.hpp"
#include "ColourPalette.h"
#include "Font.h" #include "Font.h"
#include "ImageId.hpp" #include "ImageId.hpp"
#include "Text.h" #include "Text.h"
#include <array>
#include <cassert> #include <cassert>
#include <memory> #include <memory>
#include <optional> #include <optional>
@@ -26,6 +28,7 @@
struct ScreenCoordsXY; struct ScreenCoordsXY;
struct ScreenLine; struct ScreenLine;
struct ScreenRect; struct ScreenRect;
namespace OpenRCT2 namespace OpenRCT2
{ {
struct IPlatformEnvironment; struct IPlatformEnvironment;
@@ -37,47 +40,6 @@ namespace OpenRCT2::Drawing
struct IDrawingEngine; struct IDrawingEngine;
} }
struct PaletteBGRA
{
uint8_t Blue{};
uint8_t Green{};
uint8_t Red{};
uint8_t Alpha{};
};
constexpr auto PALETTE_SIZE = 256u;
struct GamePalette
{
PaletteBGRA Colour[PALETTE_SIZE]{};
PaletteBGRA& operator[](size_t idx)
{
assert(idx < PALETTE_SIZE);
if (idx >= PALETTE_SIZE)
{
static PaletteBGRA dummy;
return dummy;
}
return Colour[idx];
}
const PaletteBGRA operator[](size_t idx) const
{
assert(idx < PALETTE_SIZE);
if (idx >= PALETTE_SIZE)
return {};
return Colour[idx];
}
explicit operator uint8_t*()
{
return reinterpret_cast<uint8_t*>(Colour);
}
};
struct G1Element struct G1Element
{ {
uint8_t* offset = nullptr; // 0x00 uint8_t* offset = nullptr; // 0x00
@@ -528,7 +490,7 @@ constexpr uint8_t kPaletteTotalOffsets = 192;
constexpr int8_t kMaxScrollingTextModes = 38; constexpr int8_t kMaxScrollingTextModes = 38;
extern GamePalette gPalette; extern OpenRCT2::Drawing::GamePalette gPalette;
extern uint8_t gGamePalette[256 * 4]; extern uint8_t gGamePalette[256 * 4];
extern uint32_t gPaletteEffectFrame; extern uint32_t gPaletteEffectFrame;

View File

@@ -10,6 +10,7 @@
#pragma once #pragma once
#include "./Weather.h" #include "./Weather.h"
#include "ColourPalette.h"
#include <memory> #include <memory>
#include <string> #include <string>
@@ -39,7 +40,6 @@ enum DRAWING_ENGINE_FLAGS
}; };
struct DrawPixelInfo; struct DrawPixelInfo;
struct GamePalette;
namespace OpenRCT2::Ui namespace OpenRCT2::Ui
{ {

View File

@@ -306,7 +306,7 @@ namespace OpenRCT2::Drawing
{ {
if (!IsTransparentPixel(colour)) if (!IsTransparentPixel(colour))
{ {
for (uint32_t i = 0; i < PALETTE_SIZE; i++) for (uint32_t i = 0; i < kGamePaletteSize; i++)
{ {
if (static_cast<int16_t>(palette[i].Red) == colour[0] && static_cast<int16_t>(palette[i].Green) == colour[1] if (static_cast<int16_t>(palette[i].Red) == colour[0] && static_cast<int16_t>(palette[i].Green) == colour[1]
&& static_cast<int16_t>(palette[i].Blue) == colour[2]) && static_cast<int16_t>(palette[i].Blue) == colour[2])
@@ -364,7 +364,7 @@ namespace OpenRCT2::Drawing
{ {
auto smallestError = static_cast<uint32_t>(-1); auto smallestError = static_cast<uint32_t>(-1);
auto bestMatch = PALETTE_TRANSPARENT; auto bestMatch = PALETTE_TRANSPARENT;
for (uint32_t x = 0; x < PALETTE_SIZE; x++) for (uint32_t x = 0; x < kGamePaletteSize; x++)
{ {
if (IsChangablePixel(x)) if (IsChangablePixel(x))
{ {

View File

@@ -93,7 +93,7 @@ namespace OpenRCT2::Drawing
ImageImportMeta createImageImportMetaFromJson(json_t& input); ImageImportMeta createImageImportMetaFromJson(json_t& input);
} // namespace OpenRCT2::Drawing } // namespace OpenRCT2::Drawing
constexpr GamePalette StandardPalette = { { constexpr OpenRCT2::Drawing::GamePalette StandardPalette = { {
// 0 (Unused/Transparent) // 0 (Unused/Transparent)
{ 0, 0, 0, 255 }, { 0, 0, 0, 255 },

View File

@@ -29,6 +29,7 @@
#include <cstring> #include <cstring>
using namespace OpenRCT2; using namespace OpenRCT2;
using namespace OpenRCT2::Drawing;
static uint8_t _bakedLightTexture_lantern_0[32 * 32]; static uint8_t _bakedLightTexture_lantern_0[32 * 32];
static uint8_t _bakedLightTexture_lantern_1[64 * 64]; static uint8_t _bakedLightTexture_lantern_1[64 * 64];

View File

@@ -9,12 +9,13 @@
#pragma once #pragma once
#include "ColourPalette.h"
#include <cstdint> #include <cstdint>
struct CoordsXY; struct CoordsXY;
struct Vehicle; struct Vehicle;
struct DrawPixelInfo; struct DrawPixelInfo;
struct GamePalette;
struct CoordsXYZ; struct CoordsXYZ;
struct EntityBase; struct EntityBase;
@@ -56,7 +57,7 @@ void LightFXRenderLightsToFrontBuffer();
void LightFXUpdateViewportSettings(); void LightFXUpdateViewportSettings();
void* LightFXGetFrontBuffer(); void* LightFXGetFrontBuffer();
const GamePalette& LightFXGetPalette(); const OpenRCT2::Drawing::GamePalette& LightFXGetPalette();
void LightFXAdd3DLight(const EntityBase& entity, const uint8_t id, const CoordsXYZ& loc, const LightType lightType); void LightFXAdd3DLight(const EntityBase& entity, const uint8_t id, const CoordsXYZ& loc, const LightType lightType);

View File

@@ -10,9 +10,10 @@
#pragma once #pragma once
#include "../localisation/StringIdType.h" #include "../localisation/StringIdType.h"
#include "ColourPalette.h"
struct DrawPixelInfo; struct DrawPixelInfo;
struct GamePalette; struct PaletteBGRA;
enum class DrawingEngine : int32_t; enum class DrawingEngine : int32_t;
extern StringId DrawingEngineStringIds[3]; extern StringId DrawingEngineStringIds[3];
@@ -21,7 +22,7 @@ DrawingEngine drawing_engine_get_type();
bool DrawingEngineRequiresNewWindow(DrawingEngine srcEngine, DrawingEngine dstEngine); bool DrawingEngineRequiresNewWindow(DrawingEngine srcEngine, DrawingEngine dstEngine);
void DrawingEngineInit(); void DrawingEngineInit();
void DrawingEngineResize(); void DrawingEngineResize();
void DrawingEngineSetPalette(const GamePalette& colours); void DrawingEngineSetPalette(const OpenRCT2::Drawing::GamePalette& colours);
void DrawingEngineCopyRect(int32_t x, int32_t y, int32_t width, int32_t height, int32_t dx, int32_t dy); void DrawingEngineCopyRect(int32_t x, int32_t y, int32_t width, int32_t height, int32_t dx, int32_t dy);
void DrawingEngineDispose(); void DrawingEngineDispose();

View File

@@ -16,6 +16,8 @@
#include <cmath> #include <cmath>
using namespace OpenRCT2::Drawing;
ColourShadeMap ColourMapA[COLOUR_COUNT] = {}; ColourShadeMap ColourMapA[COLOUR_COUNT] = {};
static constexpr uint8_t kLegacyColourMaskBase = 0x1F; static constexpr uint8_t kLegacyColourMaskBase = 0x1F;
@@ -169,9 +171,9 @@ static uint8_t FindClosestPaletteIndex(uint8_t red, uint8_t green, uint8_t blue)
static void InitBlendColourMap() static void InitBlendColourMap()
{ {
for (size_t i = 0; i < PALETTE_SIZE; i++) for (size_t i = 0; i < kGamePaletteSize; i++)
{ {
for (size_t j = i; j < PALETTE_SIZE; j++) for (size_t j = i; j < kGamePaletteSize; j++)
{ {
uint8_t red = (gPalette[i].Red + gPalette[j].Red) / 2; uint8_t red = (gPalette[i].Red + gPalette[j].Red) / 2;
uint8_t green = (gPalette[i].Green + gPalette[j].Green) / 2; uint8_t green = (gPalette[i].Green + gPalette[j].Green) / 2;

View File

@@ -63,7 +63,7 @@ static bool WriteDpiToFile(std::string_view path, const DrawPixelInfo& dpi, cons
image.Height = dpi.height; image.Height = dpi.height;
image.Depth = 8; image.Depth = 8;
image.Stride = dpi.LineStride(); image.Stride = dpi.LineStride();
image.Palette = std::make_unique<GamePalette>(palette); image.Palette = palette;
image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen); image.Pixels = std::vector<uint8_t>(pixels8, pixels8 + pixelsLen);
Imaging::WriteToFile(path, image, IMAGE_FORMAT::PNG); Imaging::WriteToFile(path, image, IMAGE_FORMAT::PNG);
return true; return true;

View File

@@ -237,6 +237,7 @@
<ClInclude Include="core\ZipStream.hpp" /> <ClInclude Include="core\ZipStream.hpp" />
<ClInclude Include="Date.h" /> <ClInclude Include="Date.h" />
<ClInclude Include="Diagnostic.h" /> <ClInclude Include="Diagnostic.h" />
<ClInclude Include="drawing\ColourPalette.h" />
<ClInclude Include="drawing\Drawing.h" /> <ClInclude Include="drawing\Drawing.h" />
<ClInclude Include="drawing\Font.h" /> <ClInclude Include="drawing\Font.h" />
<ClInclude Include="drawing\IDrawingContext.h" /> <ClInclude Include="drawing\IDrawingContext.h" />