mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-16 12:32:29 +01:00
Create new PaletteMap type to replace byte pointers
This commit is contained in:
@@ -105,7 +105,7 @@ public:
|
|||||||
void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) override;
|
void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) override;
|
||||||
void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) override;
|
void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) override;
|
||||||
void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) override;
|
void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) override;
|
||||||
void DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t* palette) override;
|
void DrawGlyph(uint32_t image, int32_t x, int32_t y, const PaletteMap& palette) override;
|
||||||
|
|
||||||
void FlushCommandBuffers();
|
void FlushCommandBuffers();
|
||||||
|
|
||||||
@@ -875,7 +875,7 @@ void OpenGLDrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y,
|
|||||||
command.depth = _drawCount++;
|
command.depth = _drawCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t* palette)
|
void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, const PaletteMap& palette)
|
||||||
{
|
{
|
||||||
auto g1Element = gfx_get_g1_element(image & 0x7FFFF);
|
auto g1Element = gfx_get_g1_element(image & 0x7FFFF);
|
||||||
if (g1Element == nullptr)
|
if (g1Element == nullptr)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* palette)
|
BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
GlyphId glyphId{};
|
GlyphId glyphId{};
|
||||||
glyphId.Image = image;
|
glyphId.Image = image;
|
||||||
@@ -105,7 +105,12 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* pa
|
|||||||
{
|
{
|
||||||
shared_lock lock(_mutex);
|
shared_lock lock(_mutex);
|
||||||
|
|
||||||
std::copy_n(palette, sizeof(glyphId.Palette), reinterpret_cast<uint8_t*>(&glyphId.Palette));
|
uint8_t glyphMap[8];
|
||||||
|
for (uint8_t i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
glyphMap[i] = paletteMap[i];
|
||||||
|
}
|
||||||
|
std::copy_n(glyphMap, sizeof(glyphId.Palette), reinterpret_cast<uint8_t*>(&glyphId.Palette));
|
||||||
|
|
||||||
auto kvp = _glyphTextureMap.find(glyphId);
|
auto kvp = _glyphTextureMap.find(glyphId);
|
||||||
if (kvp != _glyphTextureMap.end())
|
if (kvp != _glyphTextureMap.end())
|
||||||
@@ -121,7 +126,7 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* pa
|
|||||||
// Load new texture.
|
// Load new texture.
|
||||||
unique_lock lock(_mutex);
|
unique_lock lock(_mutex);
|
||||||
|
|
||||||
auto cacheInfo = LoadGlyphTexture(image, palette);
|
auto cacheInfo = LoadGlyphTexture(image, paletteMap);
|
||||||
auto it = _glyphTextureMap.insert(std::make_pair(glyphId, cacheInfo));
|
auto it = _glyphTextureMap.insert(std::make_pair(glyphId, cacheInfo));
|
||||||
|
|
||||||
return (*it.first).second;
|
return (*it.first).second;
|
||||||
@@ -175,9 +180,13 @@ void TextureCache::GeneratePaletteTexture()
|
|||||||
for (int i = 0; i < PALETTE_TO_G1_OFFSET_COUNT; ++i)
|
for (int i = 0; i < PALETTE_TO_G1_OFFSET_COUNT; ++i)
|
||||||
{
|
{
|
||||||
GLint y = PaletteToY(i);
|
GLint y = PaletteToY(i);
|
||||||
uint16_t image = palette_to_g1_offset[i];
|
|
||||||
auto element = gfx_get_g1_element(image);
|
auto g1Index = GetPaletteG1Index(i);
|
||||||
gfx_draw_sprite_software(&dpi, ImageId(image), -element->x_offset, y - element->y_offset);
|
if (g1Index)
|
||||||
|
{
|
||||||
|
auto element = gfx_get_g1_element(*g1Index);
|
||||||
|
gfx_draw_sprite_software(&dpi, ImageId(*g1Index), -element->x_offset, y - element->y_offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_RECTANGLE, _paletteTexture);
|
glBindTexture(GL_TEXTURE_RECTANGLE, _paletteTexture);
|
||||||
@@ -240,9 +249,9 @@ AtlasTextureInfo TextureCache::LoadImageTexture(uint32_t image)
|
|||||||
return cacheInfo;
|
return cacheInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtlasTextureInfo TextureCache::LoadGlyphTexture(uint32_t image, uint8_t* palette)
|
AtlasTextureInfo TextureCache::LoadGlyphTexture(uint32_t image, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
rct_drawpixelinfo dpi = GetGlyphAsDPI(image, palette);
|
rct_drawpixelinfo dpi = GetGlyphAsDPI(image, paletteMap);
|
||||||
|
|
||||||
auto cacheInfo = AllocateImage(dpi.width, dpi.height);
|
auto cacheInfo = AllocateImage(dpi.width, dpi.height);
|
||||||
cacheInfo.image = image;
|
cacheInfo.image = image;
|
||||||
@@ -304,7 +313,7 @@ rct_drawpixelinfo TextureCache::GetImageAsDPI(uint32_t image, uint32_t tertiaryC
|
|||||||
return dpi;
|
return dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
rct_drawpixelinfo TextureCache::GetGlyphAsDPI(uint32_t image, uint8_t* palette)
|
rct_drawpixelinfo TextureCache::GetGlyphAsDPI(uint32_t image, const PaletteMap& palette)
|
||||||
{
|
{
|
||||||
auto g1Element = gfx_get_g1_element(image & 0x7FFFFUL);
|
auto g1Element = gfx_get_g1_element(image & 0x7FFFFUL);
|
||||||
int32_t width = g1Element->width;
|
int32_t width = g1Element->width;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct rct_drawpixelinfo;
|
struct rct_drawpixelinfo;
|
||||||
|
struct PaletteMap;
|
||||||
|
|
||||||
struct GlyphId
|
struct GlyphId
|
||||||
{
|
{
|
||||||
@@ -218,7 +219,7 @@ public:
|
|||||||
~TextureCache();
|
~TextureCache();
|
||||||
void InvalidateImage(uint32_t image);
|
void InvalidateImage(uint32_t image);
|
||||||
BasicTextureInfo GetOrLoadImageTexture(uint32_t image);
|
BasicTextureInfo GetOrLoadImageTexture(uint32_t image);
|
||||||
BasicTextureInfo GetOrLoadGlyphTexture(uint32_t image, uint8_t* palette);
|
BasicTextureInfo GetOrLoadGlyphTexture(uint32_t image, const PaletteMap& paletteMap);
|
||||||
|
|
||||||
GLuint GetAtlasesTexture();
|
GLuint GetAtlasesTexture();
|
||||||
GLuint GetPaletteTexture();
|
GLuint GetPaletteTexture();
|
||||||
@@ -229,10 +230,10 @@ private:
|
|||||||
void GeneratePaletteTexture();
|
void GeneratePaletteTexture();
|
||||||
void EnlargeAtlasesTexture(GLuint newEntries);
|
void EnlargeAtlasesTexture(GLuint newEntries);
|
||||||
AtlasTextureInfo LoadImageTexture(uint32_t image);
|
AtlasTextureInfo LoadImageTexture(uint32_t image);
|
||||||
AtlasTextureInfo LoadGlyphTexture(uint32_t image, uint8_t* palette);
|
AtlasTextureInfo LoadGlyphTexture(uint32_t image, const PaletteMap& paletteMap);
|
||||||
AtlasTextureInfo AllocateImage(int32_t imageWidth, int32_t imageHeight);
|
AtlasTextureInfo AllocateImage(int32_t imageWidth, int32_t imageHeight);
|
||||||
static rct_drawpixelinfo GetImageAsDPI(uint32_t image, uint32_t tertiaryColour);
|
static rct_drawpixelinfo GetImageAsDPI(uint32_t image, uint32_t tertiaryColour);
|
||||||
static rct_drawpixelinfo GetGlyphAsDPI(uint32_t image, uint8_t* palette);
|
static rct_drawpixelinfo GetGlyphAsDPI(uint32_t image, const PaletteMap& paletteMap);
|
||||||
void FreeTextures();
|
void FreeTextures();
|
||||||
|
|
||||||
static rct_drawpixelinfo CreateDPI(int32_t width, int32_t height);
|
static rct_drawpixelinfo CreateDPI(int32_t width, int32_t height);
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ assert_struct_size(rct_sprite_file_header, 8);
|
|||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
static GamePalette spriteFilePalette;
|
|
||||||
|
|
||||||
static rct_sprite_file_header spriteFileHeader;
|
static rct_sprite_file_header spriteFileHeader;
|
||||||
static rct_g1_element* spriteFileEntries;
|
static rct_g1_element* spriteFileEntries;
|
||||||
static uint8_t* spriteFileData;
|
static uint8_t* spriteFileData;
|
||||||
@@ -221,18 +219,16 @@ static bool sprite_file_export(rct_g1_element* spriteHeader, const char* outPath
|
|||||||
dpi.pitch = 0;
|
dpi.pitch = 0;
|
||||||
dpi.zoom_level = 0;
|
dpi.zoom_level = 0;
|
||||||
|
|
||||||
spriteFilePalette = StandardPalette;
|
|
||||||
|
|
||||||
if (spriteHeader->flags & G1_FLAG_RLE_COMPRESSION)
|
if (spriteHeader->flags & G1_FLAG_RLE_COMPRESSION)
|
||||||
{
|
{
|
||||||
gfx_rle_sprite_to_buffer(
|
gfx_rle_sprite_to_buffer(
|
||||||
spriteHeader->offset, pixels, static_cast<uint8_t*>(spriteFilePalette), &dpi, ImageId(), 0, spriteHeader->height, 0,
|
spriteHeader->offset, pixels, PaletteMap::GetDefault(), &dpi, ImageId(), 0, spriteHeader->height, 0,
|
||||||
spriteHeader->width);
|
spriteHeader->width);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gfx_bmp_sprite_to_buffer(
|
gfx_bmp_sprite_to_buffer(
|
||||||
static_cast<uint8_t*>(spriteFilePalette), spriteHeader->offset, pixels, spriteHeader, &dpi, spriteHeader->height,
|
PaletteMap::GetDefault(), spriteHeader->offset, pixels, spriteHeader, &dpi, spriteHeader->height,
|
||||||
spriteHeader->width, ImageId());
|
spriteHeader->width, ImageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "Drawing.h"
|
#include "Drawing.h"
|
||||||
|
|
||||||
static void FASTCALL gfx_bmp_sprite_to_buffer_magnify(
|
static void FASTCALL gfx_bmp_sprite_to_buffer_magnify(
|
||||||
const uint8_t* palette_pointer, uint8_t* source_pointer, uint8_t* dest_pointer, const rct_g1_element* source_image,
|
const PaletteMap& paletteMap, uint8_t* source_pointer, uint8_t* dest_pointer, const rct_g1_element* source_image,
|
||||||
rct_drawpixelinfo* dest_dpi, int32_t height, int32_t width, ImageId imageId)
|
rct_drawpixelinfo* dest_dpi, int32_t height, int32_t width, ImageId imageId)
|
||||||
{
|
{
|
||||||
auto zoom_level = dest_dpi->zoom_level;
|
auto zoom_level = dest_dpi->zoom_level;
|
||||||
@@ -44,14 +44,14 @@ static void FASTCALL gfx_bmp_sprite_to_buffer_magnify(
|
|||||||
* @param imageId Only flags are used.
|
* @param imageId Only flags are used.
|
||||||
*/
|
*/
|
||||||
void FASTCALL gfx_bmp_sprite_to_buffer(
|
void FASTCALL gfx_bmp_sprite_to_buffer(
|
||||||
const uint8_t* palette_pointer, uint8_t* source_pointer, uint8_t* dest_pointer, const rct_g1_element* source_image,
|
const PaletteMap& paletteMap, uint8_t* source_pointer, uint8_t* dest_pointer, const rct_g1_element* source_image,
|
||||||
rct_drawpixelinfo* dest_dpi, int32_t height, int32_t width, ImageId imageId)
|
rct_drawpixelinfo* dest_dpi, int32_t height, int32_t width, ImageId imageId)
|
||||||
{
|
{
|
||||||
auto zoom_level = dest_dpi->zoom_level;
|
auto zoom_level = dest_dpi->zoom_level;
|
||||||
if (zoom_level < 0)
|
if (zoom_level < 0)
|
||||||
{
|
{
|
||||||
gfx_bmp_sprite_to_buffer_magnify(
|
gfx_bmp_sprite_to_buffer_magnify(
|
||||||
palette_pointer, source_pointer, dest_pointer, source_image, dest_dpi, height, width, imageId);
|
paletteMap, source_pointer, dest_pointer, source_image, dest_dpi, height, width, imageId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +62,6 @@ void FASTCALL gfx_bmp_sprite_to_buffer(
|
|||||||
// Image uses the palette pointer to remap the colours of the image
|
// Image uses the palette pointer to remap the colours of the image
|
||||||
if (imageId.HasPrimary())
|
if (imageId.HasPrimary())
|
||||||
{
|
{
|
||||||
assert(palette_pointer != nullptr);
|
|
||||||
|
|
||||||
// Image with remaps
|
// Image with remaps
|
||||||
for (; height > 0; height -= zoom_amount)
|
for (; height > 0; height -= zoom_amount)
|
||||||
{
|
{
|
||||||
@@ -73,7 +71,7 @@ void FASTCALL gfx_bmp_sprite_to_buffer(
|
|||||||
no_pixels -= zoom_amount, source_pointer += zoom_amount, dest_pointer++)
|
no_pixels -= zoom_amount, source_pointer += zoom_amount, dest_pointer++)
|
||||||
{
|
{
|
||||||
uint8_t pixel = *source_pointer;
|
uint8_t pixel = *source_pointer;
|
||||||
pixel = palette_pointer[pixel];
|
pixel = paletteMap[pixel];
|
||||||
if (pixel)
|
if (pixel)
|
||||||
{
|
{
|
||||||
*dest_pointer = pixel;
|
*dest_pointer = pixel;
|
||||||
@@ -91,7 +89,6 @@ void FASTCALL gfx_bmp_sprite_to_buffer(
|
|||||||
// by the palette pointer.
|
// by the palette pointer.
|
||||||
if (imageId.IsBlended())
|
if (imageId.IsBlended())
|
||||||
{ // Not tested
|
{ // Not tested
|
||||||
assert(palette_pointer != nullptr);
|
|
||||||
for (; height > 0; height -= zoom_amount)
|
for (; height > 0; height -= zoom_amount)
|
||||||
{
|
{
|
||||||
uint8_t* next_source_pointer = source_pointer + source_line_width;
|
uint8_t* next_source_pointer = source_pointer + source_line_width;
|
||||||
@@ -104,7 +101,7 @@ void FASTCALL gfx_bmp_sprite_to_buffer(
|
|||||||
if (pixel)
|
if (pixel)
|
||||||
{
|
{
|
||||||
pixel = *dest_pointer;
|
pixel = *dest_pointer;
|
||||||
pixel = palette_pointer[pixel];
|
pixel = paletteMap[pixel];
|
||||||
*dest_pointer = pixel;
|
*dest_pointer = pixel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
template<int32_t image_type, int32_t zoom_level>
|
template<int32_t image_type, int32_t zoom_level>
|
||||||
static void FASTCALL DrawRLESprite2_Magnify(
|
static void FASTCALL DrawRLESprite2_Magnify(
|
||||||
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const uint8_t* RESTRICT palette_pointer,
|
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const PaletteMap& RESTRICT paletteMap,
|
||||||
const rct_drawpixelinfo* RESTRICT dpi, int32_t source_y_start, int32_t height, int32_t source_x_start, int32_t width)
|
const rct_drawpixelinfo* RESTRICT dpi, int32_t source_y_start, int32_t height, int32_t source_x_start, int32_t width)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
@@ -23,7 +23,7 @@ static void FASTCALL DrawRLESprite2_Magnify(
|
|||||||
|
|
||||||
template<int32_t image_type, int32_t zoom_level>
|
template<int32_t image_type, int32_t zoom_level>
|
||||||
static void FASTCALL DrawRLESprite2(
|
static void FASTCALL DrawRLESprite2(
|
||||||
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const uint8_t* RESTRICT palette_pointer,
|
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const PaletteMap& RESTRICT paletteMap,
|
||||||
const rct_drawpixelinfo* RESTRICT dpi, int32_t source_y_start, int32_t height, int32_t source_x_start, int32_t width)
|
const rct_drawpixelinfo* RESTRICT dpi, int32_t source_y_start, int32_t height, int32_t source_x_start, int32_t width)
|
||||||
{
|
{
|
||||||
// The distance between two samples in the source image.
|
// The distance between two samples in the source image.
|
||||||
@@ -110,11 +110,11 @@ static void FASTCALL DrawRLESprite2(
|
|||||||
if (image_type & IMAGE_TYPE_TRANSPARENT)
|
if (image_type & IMAGE_TYPE_TRANSPARENT)
|
||||||
{
|
{
|
||||||
uint16_t color = ((*copySrc << 8) | *copyDest) - 0x100;
|
uint16_t color = ((*copySrc << 8) | *copyDest) - 0x100;
|
||||||
*copyDest = palette_pointer[color];
|
*copyDest = paletteMap[color];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*copyDest = palette_pointer[*copySrc];
|
*copyDest = paletteMap[*copySrc];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ static void FASTCALL DrawRLESprite2(
|
|||||||
for (int j = 0; j < numPixels; j += zoom_amount, copyDest++)
|
for (int j = 0; j < numPixels; j += zoom_amount, copyDest++)
|
||||||
{
|
{
|
||||||
uint8_t pixel = *copyDest;
|
uint8_t pixel = *copyDest;
|
||||||
pixel = palette_pointer[pixel];
|
pixel = paletteMap[pixel];
|
||||||
*copyDest = pixel;
|
*copyDest = pixel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,16 +147,16 @@ static void FASTCALL DrawRLESprite2(
|
|||||||
|
|
||||||
#define DrawRLESpriteHelper2_Magnify(image_type, zoom_level) \
|
#define DrawRLESpriteHelper2_Magnify(image_type, zoom_level) \
|
||||||
DrawRLESprite2_Magnify<image_type, zoom_level>( \
|
DrawRLESprite2_Magnify<image_type, zoom_level>( \
|
||||||
source_bits_pointer, dest_bits_pointer, palette_pointer, dpi, source_y_start, height, source_x_start, width)
|
source_bits_pointer, dest_bits_pointer, paletteMap, dpi, source_y_start, height, source_x_start, width)
|
||||||
|
|
||||||
#define DrawRLESpriteHelper2(image_type, zoom_level) \
|
#define DrawRLESpriteHelper2(image_type, zoom_level) \
|
||||||
DrawRLESprite2<image_type, zoom_level>( \
|
DrawRLESprite2<image_type, zoom_level>( \
|
||||||
source_bits_pointer, dest_bits_pointer, palette_pointer, dpi, source_y_start, height, source_x_start, width)
|
source_bits_pointer, dest_bits_pointer, paletteMap, dpi, source_y_start, height, source_x_start, width)
|
||||||
|
|
||||||
template<int32_t image_type>
|
template<int32_t image_type>
|
||||||
static void FASTCALL DrawRLESprite1(
|
static void FASTCALL DrawRLESprite1(
|
||||||
const uint8_t* source_bits_pointer, uint8_t* dest_bits_pointer, const uint8_t* palette_pointer,
|
const uint8_t* source_bits_pointer, uint8_t* dest_bits_pointer, const PaletteMap& paletteMap, const rct_drawpixelinfo* dpi,
|
||||||
const rct_drawpixelinfo* dpi, int32_t source_y_start, int32_t height, int32_t source_x_start, int32_t width)
|
int32_t source_y_start, int32_t height, int32_t source_x_start, int32_t width)
|
||||||
{
|
{
|
||||||
auto zoom_level = static_cast<int8_t>(dpi->zoom_level);
|
auto zoom_level = static_cast<int8_t>(dpi->zoom_level);
|
||||||
switch (zoom_level)
|
switch (zoom_level)
|
||||||
@@ -187,7 +187,7 @@ static void FASTCALL DrawRLESprite1(
|
|||||||
|
|
||||||
#define DrawRLESpriteHelper1(image_type) \
|
#define DrawRLESpriteHelper1(image_type) \
|
||||||
DrawRLESprite1<image_type>( \
|
DrawRLESprite1<image_type>( \
|
||||||
source_bits_pointer, dest_bits_pointer, palette_pointer, dpi, source_y_start, height, source_x_start, width)
|
source_bits_pointer, dest_bits_pointer, paletteMap, dpi, source_y_start, height, source_x_start, width)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfers readied images onto buffers
|
* Transfers readied images onto buffers
|
||||||
@@ -196,7 +196,7 @@ static void FASTCALL DrawRLESprite1(
|
|||||||
* @param imageId Only flags are used.
|
* @param imageId Only flags are used.
|
||||||
*/
|
*/
|
||||||
void FASTCALL gfx_rle_sprite_to_buffer(
|
void FASTCALL gfx_rle_sprite_to_buffer(
|
||||||
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const uint8_t* RESTRICT palette_pointer,
|
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const PaletteMap& RESTRICT paletteMap,
|
||||||
const rct_drawpixelinfo* RESTRICT dpi, ImageId imageId, int32_t source_y_start, int32_t height, int32_t source_x_start,
|
const rct_drawpixelinfo* RESTRICT dpi, ImageId imageId, int32_t source_y_start, int32_t height, int32_t source_x_start,
|
||||||
int32_t width)
|
int32_t width)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -358,59 +358,43 @@ bool gfx_load_csg()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t* FASTCALL gfx_draw_sprite_get_palette(ImageId imageId)
|
static std::optional<PaletteMap> FASTCALL gfx_draw_sprite_get_palette(ImageId imageId)
|
||||||
{
|
{
|
||||||
if (!imageId.HasSecondary())
|
if (!imageId.HasSecondary())
|
||||||
{
|
{
|
||||||
uint8_t palette_ref = imageId.GetRemap();
|
uint8_t paletteId = imageId.GetRemap();
|
||||||
if (!imageId.IsBlended())
|
if (!imageId.IsBlended())
|
||||||
{
|
{
|
||||||
palette_ref &= 0x7F;
|
paletteId &= 0x7F;
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t palette_offset = palette_to_g1_offset[palette_ref];
|
|
||||||
auto g1 = gfx_get_g1_element(palette_offset);
|
|
||||||
if (g1 == nullptr)
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return g1->offset;
|
|
||||||
}
|
}
|
||||||
|
return GetPaletteMapForColour(paletteId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8_t* palette_pointer = gPeepPalette;
|
auto paletteMap = PaletteMap(gPeepPalette);
|
||||||
|
|
||||||
uint32_t primary_offset = palette_to_g1_offset[imageId.GetPrimary()];
|
|
||||||
uint32_t secondary_offset = palette_to_g1_offset[imageId.GetSecondary()];
|
|
||||||
|
|
||||||
if (imageId.HasTertiary())
|
if (imageId.HasTertiary())
|
||||||
{
|
{
|
||||||
palette_pointer = gOtherPalette;
|
paletteMap = PaletteMap(gOtherPalette);
|
||||||
#if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2
|
auto tertiaryPaletteMap = GetPaletteMapForColour(imageId.GetTertiary());
|
||||||
assert(tertiary_colour < PALETTE_TO_G1_OFFSET_COUNT);
|
if (tertiaryPaletteMap)
|
||||||
#endif // DEBUG_LEVEL_2
|
|
||||||
uint32_t tertiary_offset = palette_to_g1_offset[imageId.GetTertiary()];
|
|
||||||
auto tertiary_palette = gfx_get_g1_element(tertiary_offset);
|
|
||||||
if (tertiary_palette != nullptr)
|
|
||||||
{
|
{
|
||||||
std::memcpy(palette_pointer + 0x2E, &tertiary_palette->offset[0xF3], 12);
|
paletteMap.Copy(0x2E, *tertiaryPaletteMap, 0xF3, 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto primary_palette = gfx_get_g1_element(primary_offset);
|
|
||||||
if (primary_palette != nullptr)
|
auto primaryPaletteMap = GetPaletteMapForColour(imageId.GetPrimary());
|
||||||
|
if (primaryPaletteMap)
|
||||||
{
|
{
|
||||||
std::memcpy(palette_pointer + 0xF3, &primary_palette->offset[0xF3], 12);
|
paletteMap.Copy(0xF3, *primaryPaletteMap, 0xF3, 12);
|
||||||
}
|
|
||||||
auto secondary_palette = gfx_get_g1_element(secondary_offset);
|
|
||||||
if (secondary_palette != nullptr)
|
|
||||||
{
|
|
||||||
std::memcpy(palette_pointer + 0xCA, &secondary_palette->offset[0xF3], 12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return palette_pointer;
|
auto secondaryPaletteMap = GetPaletteMapForColour(imageId.GetSecondary());
|
||||||
|
if (secondaryPaletteMap)
|
||||||
|
{
|
||||||
|
paletteMap.Copy(0xCA, *secondaryPaletteMap, 0xF3, 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
return paletteMap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,7 +403,11 @@ void FASTCALL gfx_draw_sprite_software(rct_drawpixelinfo* dpi, ImageId imageId,
|
|||||||
if (imageId.HasValue())
|
if (imageId.HasValue())
|
||||||
{
|
{
|
||||||
auto palette = gfx_draw_sprite_get_palette(imageId);
|
auto palette = gfx_draw_sprite_get_palette(imageId);
|
||||||
gfx_draw_sprite_palette_set_software(dpi, imageId, x, y, palette);
|
if (!palette)
|
||||||
|
{
|
||||||
|
palette = PaletteMap::GetDefault();
|
||||||
|
}
|
||||||
|
gfx_draw_sprite_palette_set_software(dpi, imageId, x, y, *palette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +421,7 @@ void FASTCALL gfx_draw_sprite_software(rct_drawpixelinfo* dpi, ImageId imageId,
|
|||||||
* y (dx)
|
* y (dx)
|
||||||
*/
|
*/
|
||||||
void FASTCALL gfx_draw_sprite_palette_set_software(
|
void FASTCALL gfx_draw_sprite_palette_set_software(
|
||||||
rct_drawpixelinfo* dpi, ImageId imageId, int32_t x, int32_t y, const uint8_t* palette_pointer)
|
rct_drawpixelinfo* dpi, ImageId imageId, int32_t x, int32_t y, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
const auto* g1 = gfx_get_g1_element(imageId);
|
const auto* g1 = gfx_get_g1_element(imageId);
|
||||||
if (g1 == nullptr)
|
if (g1 == nullptr)
|
||||||
@@ -452,7 +440,7 @@ void FASTCALL gfx_draw_sprite_palette_set_software(
|
|||||||
zoomed_dpi.pitch = dpi->pitch;
|
zoomed_dpi.pitch = dpi->pitch;
|
||||||
zoomed_dpi.zoom_level = dpi->zoom_level - 1;
|
zoomed_dpi.zoom_level = dpi->zoom_level - 1;
|
||||||
gfx_draw_sprite_palette_set_software(
|
gfx_draw_sprite_palette_set_software(
|
||||||
&zoomed_dpi, imageId.WithIndex(imageId.GetIndex() - g1->zoomed_offset), x >> 1, y >> 1, palette_pointer);
|
&zoomed_dpi, imageId.WithIndex(imageId.GetIndex() - g1->zoomed_offset), x >> 1, y >> 1, paletteMap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,6 +461,7 @@ void FASTCALL gfx_draw_sprite_palette_set_software(
|
|||||||
|
|
||||||
// This will be the height of the drawn image
|
// This will be the height of the drawn image
|
||||||
int32_t height = g1->height;
|
int32_t height = g1->height;
|
||||||
|
|
||||||
// This is the start y coordinate on the destination
|
// This is the start y coordinate on the destination
|
||||||
int16_t dest_start_y = y + g1->y_offset;
|
int16_t dest_start_y = y + g1->y_offset;
|
||||||
|
|
||||||
@@ -529,6 +518,7 @@ void FASTCALL gfx_draw_sprite_palette_set_software(
|
|||||||
|
|
||||||
// This will be the width of the drawn image
|
// This will be the width of the drawn image
|
||||||
int32_t width = g1->width;
|
int32_t width = g1->width;
|
||||||
|
|
||||||
// This is the source start x coordinate
|
// This is the source start x coordinate
|
||||||
int32_t source_start_x = 0;
|
int32_t source_start_x = 0;
|
||||||
// This is the destination start x coordinate
|
// This is the destination start x coordinate
|
||||||
@@ -580,14 +570,14 @@ void FASTCALL gfx_draw_sprite_palette_set_software(
|
|||||||
// We have to use a different method to move the source pointer for
|
// We have to use a different method to move the source pointer for
|
||||||
// rle encoded sprites so that will be handled within this function
|
// rle encoded sprites so that will be handled within this function
|
||||||
gfx_rle_sprite_to_buffer(
|
gfx_rle_sprite_to_buffer(
|
||||||
g1->offset, dest_pointer, palette_pointer, dpi, imageId, source_start_y, height, source_start_x, width);
|
g1->offset, dest_pointer, paletteMap, dpi, imageId, source_start_y, height, source_start_x, width);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (!(g1->flags & G1_FLAG_1))
|
else if (!(g1->flags & G1_FLAG_1))
|
||||||
{
|
{
|
||||||
// Move the pointer to the start point of the source
|
// Move the pointer to the start point of the source
|
||||||
auto source_pointer = g1->offset + ((static_cast<size_t>(g1->width) * source_start_y) + source_start_x);
|
auto source_pointer = g1->offset + ((static_cast<size_t>(g1->width) * source_start_y) + source_start_x);
|
||||||
gfx_bmp_sprite_to_buffer(palette_pointer, source_pointer, dest_pointer, g1, dpi, height, width, imageId);
|
gfx_bmp_sprite_to_buffer(paletteMap, source_pointer, dest_pointer, g1, dpi, height, width, imageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -502,7 +502,9 @@ static void ttf_draw_character_sprite(rct_drawpixelinfo* dpi, int32_t codepoint,
|
|||||||
{
|
{
|
||||||
y += *info->y_offset++;
|
y += *info->y_offset++;
|
||||||
}
|
}
|
||||||
gfx_draw_glpyh(dpi, sprite, x, y, info->palette);
|
|
||||||
|
PaletteMap paletteMap(info->palette);
|
||||||
|
gfx_draw_glyph(dpi, sprite, x, y, paletteMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
info->x += characterWidth;
|
info->x += characterWidth;
|
||||||
@@ -698,21 +700,23 @@ static const utf8* ttf_process_format_code(rct_drawpixelinfo* dpi, const utf8* t
|
|||||||
break;
|
break;
|
||||||
case FORMAT_ADJUST_PALETTE:
|
case FORMAT_ADJUST_PALETTE:
|
||||||
{
|
{
|
||||||
uint16_t eax = palette_to_g1_offset[static_cast<uint8_t>(*nextCh++)];
|
auto paletteMapId = static_cast<colour_t>(*nextCh++);
|
||||||
const rct_g1_element* g1 = gfx_get_g1_element(eax);
|
auto paletteMap = GetPaletteMapForColour(paletteMapId);
|
||||||
if (g1 != nullptr)
|
if (paletteMap)
|
||||||
{
|
{
|
||||||
uint32_t ebx = g1->offset[249] + 256;
|
uint32_t c = (*paletteMap)[249] + 256;
|
||||||
if (!(info->flags & TEXT_DRAW_FLAG_OUTLINE))
|
if (!(info->flags & TEXT_DRAW_FLAG_OUTLINE))
|
||||||
{
|
{
|
||||||
ebx = ebx & 0xFF;
|
c &= 0xFF;
|
||||||
}
|
}
|
||||||
info->palette[1] = ebx & 0xFF;
|
info->palette[1] = c & 0xFF;
|
||||||
info->palette[2] = (ebx >> 8) & 0xFF;
|
info->palette[2] = (c >> 8) & 0xFF;
|
||||||
|
|
||||||
// Adjust the text palette
|
// Adjust the text palette
|
||||||
std::memcpy(info->palette + 3, &(g1->offset[247]), 2);
|
info->palette[3] = (*paletteMap)[247];
|
||||||
std::memcpy(info->palette + 5, &(g1->offset[250]), 2);
|
info->palette[4] = (*paletteMap)[248];
|
||||||
|
info->palette[5] = (*paletteMap)[250];
|
||||||
|
info->palette[6] = (*paletteMap)[251];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,50 @@
|
|||||||
#include "../world/Location.hpp"
|
#include "../world/Location.hpp"
|
||||||
#include "../world/Water.h"
|
#include "../world/Water.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
const PaletteMap& PaletteMap::GetDefault()
|
||||||
|
{
|
||||||
|
static bool initialised = false;
|
||||||
|
static uint8_t data[256];
|
||||||
|
static PaletteMap defaultMap(data, sizeof(data));
|
||||||
|
if (!initialised)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < sizeof(data); i++)
|
||||||
|
{
|
||||||
|
data[i] = static_cast<uint8_t>(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t& PaletteMap::operator[](size_t index)
|
||||||
|
{
|
||||||
|
if (index >= _mapLength)
|
||||||
|
{
|
||||||
|
static uint8_t dummy;
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
return _map[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t PaletteMap::operator[](size_t index) const
|
||||||
|
{
|
||||||
|
if (index >= _mapLength)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return _map[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void PaletteMap::Copy(size_t dstIndex, const PaletteMap& src, size_t srcIndex, size_t length)
|
||||||
|
{
|
||||||
|
auto maxLength = std::min(_mapLength - srcIndex, _mapLength - dstIndex);
|
||||||
|
assert(length <= maxLength);
|
||||||
|
auto copyLength = std::min(length, maxLength);
|
||||||
|
std::memcpy(&_map[dstIndex], &src._map[srcIndex], copyLength);
|
||||||
|
}
|
||||||
|
|
||||||
// HACK These were originally passed back through registers
|
// HACK These were originally passed back through registers
|
||||||
thread_local int32_t gLastDrawStringX;
|
thread_local int32_t gLastDrawStringX;
|
||||||
thread_local int32_t gLastDrawStringY;
|
thread_local int32_t gLastDrawStringY;
|
||||||
@@ -269,7 +313,7 @@ const FILTER_PALETTE_ID GlassPaletteIds[COLOUR_COUNT] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Previously 0x97FCBC use it to get the correct palette from g1_elements
|
// Previously 0x97FCBC use it to get the correct palette from g1_elements
|
||||||
const uint16_t palette_to_g1_offset[PALETTE_TO_G1_OFFSET_COUNT] = {
|
static const uint16_t palette_to_g1_offset[PALETTE_TO_G1_OFFSET_COUNT] = {
|
||||||
SPR_PALETTE_BLACK,
|
SPR_PALETTE_BLACK,
|
||||||
SPR_PALETTE_GREY,
|
SPR_PALETTE_GREY,
|
||||||
SPR_PALETTE_WHITE,
|
SPR_PALETTE_WHITE,
|
||||||
@@ -687,3 +731,26 @@ void gfx_draw_pickedup_peep(rct_drawpixelinfo* dpi)
|
|||||||
gfx_draw_sprite(dpi, gPickupPeepImage, gPickupPeepX, gPickupPeepY, 0);
|
gfx_draw_sprite(dpi, gPickupPeepImage, gPickupPeepX, gPickupPeepY, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId)
|
||||||
|
{
|
||||||
|
if (paletteId < std::size(palette_to_g1_offset))
|
||||||
|
{
|
||||||
|
return palette_to_g1_offset[paletteId];
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<PaletteMap> GetPaletteMapForColour(colour_t paletteId)
|
||||||
|
{
|
||||||
|
auto g1Index = GetPaletteG1Index(paletteId);
|
||||||
|
if (g1Index)
|
||||||
|
{
|
||||||
|
auto g1 = gfx_get_g1_element(*g1Index);
|
||||||
|
if (g1 != nullptr)
|
||||||
|
{
|
||||||
|
return PaletteMap(g1->offset, 256 * 256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|||||||
@@ -450,6 +450,38 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an 8-bit indexed map that maps from one palette index to another.
|
||||||
|
*/
|
||||||
|
struct PaletteMap
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
uint8_t* _map{};
|
||||||
|
size_t _mapLength{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const PaletteMap& GetDefault();
|
||||||
|
|
||||||
|
PaletteMap() = default;
|
||||||
|
|
||||||
|
PaletteMap(uint8_t* map, size_t mapLength)
|
||||||
|
: _map(map)
|
||||||
|
, _mapLength(mapLength)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t TSize>
|
||||||
|
PaletteMap(uint8_t (&map)[TSize])
|
||||||
|
: _map(map)
|
||||||
|
, _mapLength(std::size(map))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t& operator[](size_t index);
|
||||||
|
uint8_t operator[](size_t index) const;
|
||||||
|
void Copy(size_t dstIndex, const PaletteMap& src, size_t srcIndex, size_t length);
|
||||||
|
};
|
||||||
|
|
||||||
#define SPRITE_ID_PALETTE_COLOUR_1(colourId) (IMAGE_TYPE_REMAP | ((colourId) << 19))
|
#define SPRITE_ID_PALETTE_COLOUR_1(colourId) (IMAGE_TYPE_REMAP | ((colourId) << 19))
|
||||||
#define SPRITE_ID_PALETTE_COLOUR_2(primaryId, secondaryId) \
|
#define SPRITE_ID_PALETTE_COLOUR_2(primaryId, secondaryId) \
|
||||||
(IMAGE_TYPE_REMAP_2_PLUS | IMAGE_TYPE_REMAP | (((primaryId) << 19) | ((secondaryId) << 24)))
|
(IMAGE_TYPE_REMAP_2_PLUS | IMAGE_TYPE_REMAP | (((primaryId) << 19) | ((secondaryId) << 24)))
|
||||||
@@ -471,7 +503,6 @@ extern GamePalette gPalette;
|
|||||||
extern uint8_t gGamePalette[256 * 4];
|
extern uint8_t gGamePalette[256 * 4];
|
||||||
extern uint32_t gPaletteEffectFrame;
|
extern uint32_t gPaletteEffectFrame;
|
||||||
extern const FILTER_PALETTE_ID GlassPaletteIds[COLOUR_COUNT];
|
extern const FILTER_PALETTE_ID GlassPaletteIds[COLOUR_COUNT];
|
||||||
extern const uint16_t palette_to_g1_offset[];
|
|
||||||
extern uint8_t gPeepPalette[256];
|
extern uint8_t gPeepPalette[256];
|
||||||
extern uint8_t gOtherPalette[256];
|
extern uint8_t gOtherPalette[256];
|
||||||
extern uint8_t text_palette[];
|
extern uint8_t text_palette[];
|
||||||
@@ -536,21 +567,20 @@ void gfx_object_check_all_images_freed();
|
|||||||
size_t ImageListGetUsedCount();
|
size_t ImageListGetUsedCount();
|
||||||
size_t ImageListGetMaximum();
|
size_t ImageListGetMaximum();
|
||||||
void FASTCALL gfx_bmp_sprite_to_buffer(
|
void FASTCALL gfx_bmp_sprite_to_buffer(
|
||||||
const uint8_t* palette_pointer, uint8_t* source_pointer, uint8_t* dest_pointer, const rct_g1_element* source_image,
|
const PaletteMap& paletteMap, uint8_t* source_pointer, uint8_t* dest_pointer, const rct_g1_element* source_image,
|
||||||
rct_drawpixelinfo* dest_dpi, int32_t height, int32_t width, ImageId imageId);
|
rct_drawpixelinfo* dest_dpi, int32_t height, int32_t width, ImageId imageId);
|
||||||
void FASTCALL gfx_rle_sprite_to_buffer(
|
void FASTCALL gfx_rle_sprite_to_buffer(
|
||||||
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const uint8_t* RESTRICT palette_pointer,
|
const uint8_t* RESTRICT source_bits_pointer, uint8_t* RESTRICT dest_bits_pointer, const PaletteMap& RESTRICT paletteMap,
|
||||||
const rct_drawpixelinfo* RESTRICT dpi, ImageId imageId, int32_t source_y_start, int32_t height, int32_t source_x_start,
|
const rct_drawpixelinfo* RESTRICT dpi, ImageId imageId, int32_t source_y_start, int32_t height, int32_t source_x_start,
|
||||||
int32_t width);
|
int32_t width);
|
||||||
void FASTCALL gfx_draw_sprite(rct_drawpixelinfo* dpi, int32_t image_id, int32_t x, int32_t y, uint32_t tertiary_colour);
|
void FASTCALL gfx_draw_sprite(rct_drawpixelinfo* dpi, int32_t image_id, int32_t x, int32_t y, uint32_t tertiary_colour);
|
||||||
void FASTCALL gfx_draw_glpyh(rct_drawpixelinfo* dpi, int32_t image_id, int32_t x, int32_t y, uint8_t* palette);
|
void FASTCALL gfx_draw_glyph(rct_drawpixelinfo* dpi, int32_t image_id, int32_t x, int32_t y, const PaletteMap& paletteMap);
|
||||||
void FASTCALL gfx_draw_sprite_raw_masked(rct_drawpixelinfo* dpi, int32_t x, int32_t y, int32_t maskImage, int32_t colourImage);
|
void FASTCALL gfx_draw_sprite_raw_masked(rct_drawpixelinfo* dpi, int32_t x, int32_t y, int32_t maskImage, int32_t colourImage);
|
||||||
void FASTCALL gfx_draw_sprite_solid(rct_drawpixelinfo* dpi, int32_t image, int32_t x, int32_t y, uint8_t colour);
|
void FASTCALL gfx_draw_sprite_solid(rct_drawpixelinfo* dpi, int32_t image, int32_t x, int32_t y, uint8_t colour);
|
||||||
|
|
||||||
void FASTCALL gfx_draw_sprite_software(rct_drawpixelinfo* dpi, ImageId imageId, int32_t x, int32_t y);
|
void FASTCALL gfx_draw_sprite_software(rct_drawpixelinfo* dpi, ImageId imageId, int32_t x, int32_t y);
|
||||||
const uint8_t* FASTCALL gfx_draw_sprite_get_palette(ImageId imageId);
|
|
||||||
void FASTCALL gfx_draw_sprite_palette_set_software(
|
void FASTCALL gfx_draw_sprite_palette_set_software(
|
||||||
rct_drawpixelinfo* dpi, ImageId imageId, int32_t x, int32_t y, const uint8_t* palette_pointer);
|
rct_drawpixelinfo* dpi, ImageId imageId, int32_t x, int32_t y, const PaletteMap& paletteMap);
|
||||||
void FASTCALL
|
void FASTCALL
|
||||||
gfx_draw_sprite_raw_masked_software(rct_drawpixelinfo* dpi, int32_t x, int32_t y, int32_t maskImage, int32_t colourImage);
|
gfx_draw_sprite_raw_masked_software(rct_drawpixelinfo* dpi, int32_t x, int32_t y, int32_t maskImage, int32_t colourImage);
|
||||||
|
|
||||||
@@ -627,6 +657,9 @@ extern void (*mask_fn)(
|
|||||||
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
int32_t width, int32_t height, const uint8_t* RESTRICT maskSrc, const uint8_t* RESTRICT colourSrc, uint8_t* RESTRICT dst,
|
||||||
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
int32_t maskWrap, int32_t colourWrap, int32_t dstWrap);
|
||||||
|
|
||||||
|
std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId);
|
||||||
|
std::optional<PaletteMap> GetPaletteMapForColour(colour_t paletteId);
|
||||||
|
|
||||||
#include "NewDrawing.h"
|
#include "NewDrawing.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ namespace OpenRCT2::Drawing
|
|||||||
virtual void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) abstract;
|
virtual void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) abstract;
|
||||||
virtual void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) abstract;
|
virtual void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) abstract;
|
||||||
virtual void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) abstract;
|
virtual void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) abstract;
|
||||||
virtual void DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t * palette) abstract;
|
virtual void DrawGlyph(uint32_t image, int32_t x, int32_t y, const PaletteMap& palette) abstract;
|
||||||
};
|
};
|
||||||
} // namespace OpenRCT2::Drawing
|
} // namespace OpenRCT2::Drawing
|
||||||
|
|||||||
@@ -254,13 +254,13 @@ void FASTCALL gfx_draw_sprite(rct_drawpixelinfo* dpi, int32_t image, int32_t x,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FASTCALL gfx_draw_glpyh(rct_drawpixelinfo* dpi, int32_t image, int32_t x, int32_t y, uint8_t* palette)
|
void FASTCALL gfx_draw_glyph(rct_drawpixelinfo* dpi, int32_t image, int32_t x, int32_t y, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
auto drawingEngine = dpi->DrawingEngine;
|
auto drawingEngine = dpi->DrawingEngine;
|
||||||
if (drawingEngine != nullptr)
|
if (drawingEngine != nullptr)
|
||||||
{
|
{
|
||||||
IDrawingContext* dc = drawingEngine->GetDrawingContext(dpi);
|
IDrawingContext* dc = drawingEngine->GetDrawingContext(dpi);
|
||||||
dc->DrawGlyph(image, x, y, palette);
|
dc->DrawGlyph(image, x, y, paletteMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -703,11 +703,9 @@ void X8DrawingContext::FilterRect(FILTER_PALETTE_ID palette, int32_t left, int32
|
|||||||
(startY / dpi->zoom_level) * ((dpi->width / dpi->zoom_level) + dpi->pitch) + (startX / dpi->zoom_level));
|
(startY / dpi->zoom_level) * ((dpi->width / dpi->zoom_level) + dpi->pitch) + (startX / dpi->zoom_level));
|
||||||
|
|
||||||
// Find colour in colour table?
|
// Find colour in colour table?
|
||||||
uint16_t g1Index = palette_to_g1_offset[palette];
|
auto paletteMap = GetPaletteMapForColour(palette);
|
||||||
auto g1Element = gfx_get_g1_element(g1Index);
|
if (paletteMap)
|
||||||
if (g1Element != nullptr)
|
|
||||||
{
|
{
|
||||||
auto g1Bits = g1Element->offset;
|
|
||||||
const int32_t scaled_width = width / dpi->zoom_level;
|
const int32_t scaled_width = width / dpi->zoom_level;
|
||||||
const int32_t step = ((dpi->width / dpi->zoom_level) + dpi->pitch);
|
const int32_t step = ((dpi->width / dpi->zoom_level) + dpi->pitch);
|
||||||
|
|
||||||
@@ -718,7 +716,8 @@ void X8DrawingContext::FilterRect(FILTER_PALETTE_ID palette, int32_t left, int32
|
|||||||
uint8_t* nextdst = dst + step * i;
|
uint8_t* nextdst = dst + step * i;
|
||||||
for (int32_t j = 0; j < scaled_width; j++)
|
for (int32_t j = 0; j < scaled_width; j++)
|
||||||
{
|
{
|
||||||
*(nextdst + j) = g1Bits[*(nextdst + j)];
|
auto index = *(nextdst + j);
|
||||||
|
*(nextdst + j) = (*paletteMap)[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -741,15 +740,13 @@ void X8DrawingContext::DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskIm
|
|||||||
|
|
||||||
void X8DrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour)
|
void X8DrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour)
|
||||||
{
|
{
|
||||||
uint8_t palette[256];
|
gfx_draw_sprite_palette_set_software(
|
||||||
std::fill_n(palette, sizeof(palette), colour);
|
_dpi, ImageId::FromUInt32((image & 0x7FFFF) | IMAGE_TYPE_REMAP), x, y, PaletteMap::GetDefault());
|
||||||
palette[0] = 0;
|
|
||||||
gfx_draw_sprite_palette_set_software(_dpi, ImageId::FromUInt32((image & 0x7FFFF) | IMAGE_TYPE_REMAP), x, y, palette);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void X8DrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t* palette)
|
void X8DrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
gfx_draw_sprite_palette_set_software(_dpi, ImageId::FromUInt32(image), x, y, palette);
|
gfx_draw_sprite_palette_set_software(_dpi, ImageId::FromUInt32(image), x, y, paletteMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void X8DrawingContext::SetDPI(rct_drawpixelinfo* dpi)
|
void X8DrawingContext::SetDPI(rct_drawpixelinfo* dpi)
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ namespace OpenRCT2
|
|||||||
void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) override;
|
void DrawSprite(uint32_t image, int32_t x, int32_t y, uint32_t tertiaryColour) override;
|
||||||
void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) override;
|
void DrawSpriteRawMasked(int32_t x, int32_t y, uint32_t maskImage, uint32_t colourImage) override;
|
||||||
void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) override;
|
void DrawSpriteSolid(uint32_t image, int32_t x, int32_t y, uint8_t colour) override;
|
||||||
void DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8_t* palette) override;
|
void DrawGlyph(uint32_t image, int32_t x, int32_t y, const PaletteMap& paletteMap) override;
|
||||||
|
|
||||||
void SetDPI(rct_drawpixelinfo* dpi);
|
void SetDPI(rct_drawpixelinfo* dpi);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1288,7 +1288,8 @@ static bool PSSpriteTypeIsInFilter(paint_struct* ps, uint16_t filter)
|
|||||||
/**
|
/**
|
||||||
* rct2: 0x00679236, 0x00679662, 0x00679B0D, 0x00679FF1
|
* rct2: 0x00679236, 0x00679662, 0x00679B0D, 0x00679FF1
|
||||||
*/
|
*/
|
||||||
static bool is_pixel_present_bmp(uint32_t imageType, const rct_g1_element* g1, const uint8_t* index, const uint8_t* palette)
|
static bool is_pixel_present_bmp(
|
||||||
|
uint32_t imageType, const rct_g1_element* g1, const uint8_t* index, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
// Probably used to check for corruption
|
// Probably used to check for corruption
|
||||||
if (!(g1->flags & G1_FLAG_BMP))
|
if (!(g1->flags & G1_FLAG_BMP))
|
||||||
@@ -1298,7 +1299,7 @@ static bool is_pixel_present_bmp(uint32_t imageType, const rct_g1_element* g1, c
|
|||||||
|
|
||||||
if (imageType & IMAGE_TYPE_REMAP)
|
if (imageType & IMAGE_TYPE_REMAP)
|
||||||
{
|
{
|
||||||
return palette[*index] != 0;
|
return paletteMap[*index] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageType & IMAGE_TYPE_TRANSPARENT)
|
if (imageType & IMAGE_TYPE_TRANSPARENT)
|
||||||
@@ -1405,7 +1406,7 @@ static bool is_pixel_present_rle(const uint8_t* esi, int16_t x_start_point, int1
|
|||||||
* @return value originally stored in 0x00141F569
|
* @return value originally stored in 0x00141F569
|
||||||
*/
|
*/
|
||||||
static bool is_sprite_interacted_with_palette_set(
|
static bool is_sprite_interacted_with_palette_set(
|
||||||
rct_drawpixelinfo* dpi, int32_t imageId, int16_t x, int16_t y, const uint8_t* palette)
|
rct_drawpixelinfo* dpi, int32_t imageId, int16_t x, int16_t y, const PaletteMap& paletteMap)
|
||||||
{
|
{
|
||||||
const rct_g1_element* g1 = gfx_get_g1_element(imageId & 0x7FFFF);
|
const rct_g1_element* g1 = gfx_get_g1_element(imageId & 0x7FFFF);
|
||||||
if (g1 == nullptr)
|
if (g1 == nullptr)
|
||||||
@@ -1433,7 +1434,7 @@ static bool is_sprite_interacted_with_palette_set(
|
|||||||
/* .zoom_level = */ dpi->zoom_level - 1,
|
/* .zoom_level = */ dpi->zoom_level - 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
return is_sprite_interacted_with_palette_set(&zoomed_dpi, imageId - g1->zoomed_offset, x / 2, y / 2, palette);
|
return is_sprite_interacted_with_palette_set(&zoomed_dpi, imageId - g1->zoomed_offset, x / 2, y / 2, paletteMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1535,7 +1536,7 @@ static bool is_sprite_interacted_with_palette_set(
|
|||||||
|
|
||||||
if (!(g1->flags & G1_FLAG_1))
|
if (!(g1->flags & G1_FLAG_1))
|
||||||
{
|
{
|
||||||
return is_pixel_present_bmp(imageType, g1, offset, palette);
|
return is_pixel_present_bmp(imageType, g1, offset, paletteMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Guard::Assert(false, "Invalid image type encountered.");
|
Guard::Assert(false, "Invalid image type encountered.");
|
||||||
@@ -1548,7 +1549,7 @@ static bool is_sprite_interacted_with_palette_set(
|
|||||||
*/
|
*/
|
||||||
static bool is_sprite_interacted_with(rct_drawpixelinfo* dpi, int32_t imageId, int32_t x, int32_t y)
|
static bool is_sprite_interacted_with(rct_drawpixelinfo* dpi, int32_t imageId, int32_t x, int32_t y)
|
||||||
{
|
{
|
||||||
const uint8_t* palette = nullptr;
|
auto paletteMap = PaletteMap::GetDefault();
|
||||||
imageId &= ~IMAGE_TYPE_TRANSPARENT;
|
imageId &= ~IMAGE_TYPE_TRANSPARENT;
|
||||||
if (imageId & IMAGE_TYPE_REMAP)
|
if (imageId & IMAGE_TYPE_REMAP)
|
||||||
{
|
{
|
||||||
@@ -1558,18 +1559,16 @@ static bool is_sprite_interacted_with(rct_drawpixelinfo* dpi, int32_t imageId, i
|
|||||||
{
|
{
|
||||||
index &= 0x1F;
|
index &= 0x1F;
|
||||||
}
|
}
|
||||||
int32_t g1Index = palette_to_g1_offset[index];
|
if (auto pm = GetPaletteMapForColour(index))
|
||||||
const rct_g1_element* g1 = gfx_get_g1_element(g1Index);
|
|
||||||
if (g1 != nullptr)
|
|
||||||
{
|
{
|
||||||
palette = g1->offset;
|
paletteMap = *pm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_currentImageType = 0;
|
_currentImageType = 0;
|
||||||
}
|
}
|
||||||
return is_sprite_interacted_with_palette_set(dpi, imageId, x, y, palette);
|
return is_sprite_interacted_with_palette_set(dpi, imageId, x, y, paletteMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user