Use dpi ref in misc drawing folder places

This commit is contained in:
Gymnasiast 2023-04-03 22:55:11 +02:00 committed by duncanspumpkin
parent 0139c8d19e
commit 2941f6f7a5
9 changed files with 64 additions and 64 deletions

View File

@ -222,7 +222,7 @@ void TextureCache::GeneratePaletteTexture()
const auto* element = GfxGetG1Element(g1Index.value());
if (element != nullptr)
{
GfxDrawSpriteSoftware(&dpi, ImageId(g1Index.value()), { -element->x_offset, y - element->y_offset });
GfxDrawSpriteSoftware(dpi, ImageId(g1Index.value()), { -element->x_offset, y - element->y_offset });
}
}
}
@ -357,7 +357,7 @@ DrawPixelInfo TextureCache::GetImageAsDPI(const ImageId imageId)
int32_t height = g1Element->height;
DrawPixelInfo dpi = CreateDPI(width, height);
GfxDrawSpriteSoftware(&dpi, imageId, { -g1Element->x_offset, -g1Element->y_offset });
GfxDrawSpriteSoftware(dpi, imageId, { -g1Element->x_offset, -g1Element->y_offset });
return dpi;
}
@ -370,7 +370,7 @@ DrawPixelInfo TextureCache::GetGlyphAsDPI(const ImageId imageId, const PaletteMa
DrawPixelInfo dpi = CreateDPI(width, height);
const auto glyphCoords = ScreenCoordsXY{ -g1Element->x_offset, -g1Element->y_offset };
GfxDrawSpritePaletteSetSoftware(&dpi, imageId, glyphCoords, palette);
GfxDrawSpritePaletteSetSoftware(dpi, imageId, glyphCoords, palette);
return dpi;
}

View File

@ -444,7 +444,7 @@ static std::optional<PaletteMap> FASTCALL GfxDrawSpriteGetPalette(ImageId imageI
return paletteMap;
}
void FASTCALL GfxDrawSpriteSoftware(DrawPixelInfo* dpi, const ImageId imageId, const ScreenCoordsXY& spriteCoords)
void FASTCALL GfxDrawSpriteSoftware(DrawPixelInfo& dpi, const ImageId imageId, const ScreenCoordsXY& spriteCoords)
{
if (imageId.HasValue())
{
@ -467,7 +467,7 @@ void FASTCALL GfxDrawSpriteSoftware(DrawPixelInfo* dpi, const ImageId imageId, c
* y (dx)
*/
void FASTCALL GfxDrawSpritePaletteSetSoftware(
DrawPixelInfo* dpi, const ImageId imageId, const ScreenCoordsXY& coords, const PaletteMap& paletteMap)
DrawPixelInfo& dpi, const ImageId imageId, const ScreenCoordsXY& coords, const PaletteMap& paletteMap)
{
int32_t x = coords.x;
int32_t y = coords.y;
@ -478,30 +478,30 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
return;
}
if (dpi->zoom_level > ZoomLevel{ 0 } && (g1->flags & G1_FLAG_HAS_ZOOM_SPRITE))
if (dpi.zoom_level > ZoomLevel{ 0 } && (g1->flags & G1_FLAG_HAS_ZOOM_SPRITE))
{
DrawPixelInfo zoomed_dpi = *dpi;
zoomed_dpi.bits = dpi->bits;
zoomed_dpi.x = dpi->x >> 1;
zoomed_dpi.y = dpi->y >> 1;
zoomed_dpi.height = dpi->height >> 1;
zoomed_dpi.width = dpi->width >> 1;
zoomed_dpi.pitch = dpi->pitch;
zoomed_dpi.zoom_level = dpi->zoom_level - 1;
DrawPixelInfo zoomed_dpi = dpi;
zoomed_dpi.bits = dpi.bits;
zoomed_dpi.x = dpi.x >> 1;
zoomed_dpi.y = dpi.y >> 1;
zoomed_dpi.height = dpi.height >> 1;
zoomed_dpi.width = dpi.width >> 1;
zoomed_dpi.pitch = dpi.pitch;
zoomed_dpi.zoom_level = dpi.zoom_level - 1;
const auto spriteCoords = ScreenCoordsXY{ x >> 1, y >> 1 };
GfxDrawSpritePaletteSetSoftware(
&zoomed_dpi, imageId.WithIndex(imageId.GetIndex() - g1->zoomed_offset), spriteCoords, paletteMap);
zoomed_dpi, imageId.WithIndex(imageId.GetIndex() - g1->zoomed_offset), spriteCoords, paletteMap);
return;
}
if (dpi->zoom_level > ZoomLevel{ 0 } && (g1->flags & G1_FLAG_NO_ZOOM_DRAW))
if (dpi.zoom_level > ZoomLevel{ 0 } && (g1->flags & G1_FLAG_NO_ZOOM_DRAW))
{
return;
}
// Its used super often so we will define it to a separate variable.
const auto zoom_level = dpi->zoom_level;
const auto zoom_level = dpi.zoom_level;
const int32_t zoom_mask = zoom_level > ZoomLevel{ 0 } ? zoom_level.ApplyTo(0xFFFFFFFF) : 0xFFFFFFFF;
if (zoom_level > ZoomLevel{ 0 } && g1->flags & G1_FLAG_RLE_COMPRESSION)
@ -520,11 +520,11 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
// the zoom mask on the y coordinate but does on x.
if (g1->flags & G1_FLAG_RLE_COMPRESSION)
{
dest_start_y -= dpi->y;
dest_start_y -= dpi.y;
}
else
{
dest_start_y = (dest_start_y & zoom_mask) - dpi->y;
dest_start_y = (dest_start_y & zoom_mask) - dpi.y;
}
// This is the start y coordinate on the source
int32_t source_start_y = 0;
@ -555,11 +555,11 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
int32_t dest_end_y = dest_start_y + height;
if (dest_end_y > dpi->height)
if (dest_end_y > dpi.height)
{
// If the destination y is outside of the drawing
// image reduce the height of the image
height -= dest_end_y - dpi->height;
height -= dest_end_y - dpi.height;
}
// If the image no longer has anything to draw
if (height <= 0)
@ -573,7 +573,7 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
// This is the source start x coordinate
int32_t source_start_x = 0;
// This is the destination start x coordinate
int16_t dest_start_x = ((x + g1->x_offset + ~zoom_mask) & zoom_mask) - dpi->x;
int16_t dest_start_x = ((x + g1->x_offset + ~zoom_mask) & zoom_mask) - dpi.x;
if (dest_start_x < 0)
{
@ -600,11 +600,11 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
int32_t dest_end_x = dest_start_x + width;
if (dest_end_x > dpi->width)
if (dest_end_x > dpi.width)
{
// If the destination x is outside of the drawing area
// reduce the image width.
width -= dest_end_x - dpi->width;
width -= dest_end_x - dpi.width;
// If there is no image to draw.
if (width <= 0)
return;
@ -612,12 +612,12 @@ void FASTCALL GfxDrawSpritePaletteSetSoftware(
dest_start_x = zoom_level.ApplyInversedTo(dest_start_x);
uint8_t* dest_pointer = dpi->bits;
uint8_t* dest_pointer = dpi.bits;
// Move the pointer to the start point of the destination
dest_pointer += (zoom_level.ApplyInversedTo(dpi->width) + dpi->pitch) * dest_start_y + dest_start_x;
dest_pointer += (zoom_level.ApplyInversedTo(dpi.width) + dpi.pitch) * dest_start_y + dest_start_x;
DrawSpriteArgs args(imageId, paletteMap, *g1, source_start_x, source_start_y, width, height, dest_pointer);
GfxSpriteToBuffer(*dpi, args);
GfxSpriteToBuffer(dpi, args);
}
void FASTCALL GfxSpriteToBuffer(DrawPixelInfo& dpi, const DrawSpriteArgs& args)
@ -639,7 +639,7 @@ void FASTCALL GfxSpriteToBuffer(DrawPixelInfo& dpi, const DrawSpriteArgs& args)
* rct2: 0x00681DE2
*/
void FASTCALL GfxDrawSpriteRawMaskedSoftware(
DrawPixelInfo* dpi, const ScreenCoordsXY& scrCoords, const ImageId maskImage, const ImageId colourImage)
DrawPixelInfo& dpi, const ScreenCoordsXY& scrCoords, const ImageId maskImage, const ImageId colourImage)
{
int32_t left, top, right, bottom, width, height;
auto imgMask = GfxGetG1Element(maskImage);
@ -656,7 +656,7 @@ void FASTCALL GfxDrawSpriteRawMaskedSoftware(
return;
}
if (dpi->zoom_level != ZoomLevel{ 0 })
if (dpi.zoom_level != ZoomLevel{ 0 })
{
// TODO: Implement other zoom levels (probably not used though)
assert(false);
@ -668,10 +668,10 @@ void FASTCALL GfxDrawSpriteRawMaskedSoftware(
auto offsetCoords = scrCoords + ScreenCoordsXY{ imgMask->x_offset, imgMask->y_offset };
left = std::max<int32_t>(dpi->x, offsetCoords.x);
top = std::max<int32_t>(dpi->y, offsetCoords.y);
right = std::min(dpi->x + dpi->width, offsetCoords.x + width);
bottom = std::min(dpi->y + dpi->height, offsetCoords.y + height);
left = std::max<int32_t>(dpi.x, offsetCoords.x);
top = std::max<int32_t>(dpi.y, offsetCoords.y);
right = std::min(dpi.x + dpi.width, offsetCoords.x + width);
bottom = std::min(dpi.y + dpi.height, offsetCoords.y + height);
width = right - left;
height = bottom - top;
@ -683,11 +683,11 @@ void FASTCALL GfxDrawSpriteRawMaskedSoftware(
uint8_t const* maskSrc = imgMask->offset + (skipY * imgMask->width) + skipX;
uint8_t const* colourSrc = imgColour->offset + (skipY * imgColour->width) + skipX;
uint8_t* dst = dpi->bits + (left - dpi->x) + ((top - dpi->y) * (dpi->width + dpi->pitch));
uint8_t* dst = dpi.bits + (left - dpi.x) + ((top - dpi.y) * (dpi.width + dpi.pitch));
int32_t maskWrap = imgMask->width - width;
int32_t colourWrap = imgColour->width - width;
int32_t dstWrap = ((dpi->width + dpi->pitch) - width);
int32_t dstWrap = ((dpi.width + dpi.pitch) - width);
MaskFn(width, height, maskSrc, colourSrc, dst, maskWrap, colourWrap, dstWrap);
}

View File

@ -518,7 +518,7 @@ void GfxDrawPickedUpPeep(DrawPixelInfo* dpi);
// line
void GfxDrawLine(DrawPixelInfo* dpi, const ScreenLine& line, int32_t colour);
void GfxDrawLineSoftware(DrawPixelInfo* dpi, const ScreenLine& line, int32_t colour);
void GfxDrawLineSoftware(DrawPixelInfo& dpi, const ScreenLine& line, int32_t colour);
void GfxDrawDashedLine(
DrawPixelInfo* dpi, const ScreenLine& screenLine, const int32_t dashedLineSegmentLength, const int32_t color);
@ -547,11 +547,11 @@ void FASTCALL GfxDrawGlyph(DrawPixelInfo* dpi, const ImageId image, const Screen
void FASTCALL GfxDrawSpriteSolid(DrawPixelInfo* dpi, const ImageId image, const ScreenCoordsXY& coords, uint8_t colour);
void FASTCALL GfxDrawSpriteRawMasked(
DrawPixelInfo* dpi, const ScreenCoordsXY& coords, const ImageId maskImage, const ImageId colourImage);
void FASTCALL GfxDrawSpriteSoftware(DrawPixelInfo* dpi, const ImageId imageId, const ScreenCoordsXY& spriteCoords);
void FASTCALL GfxDrawSpriteSoftware(DrawPixelInfo& dpi, const ImageId imageId, const ScreenCoordsXY& spriteCoords);
void FASTCALL GfxDrawSpritePaletteSetSoftware(
DrawPixelInfo* dpi, const ImageId imageId, const ScreenCoordsXY& coords, const PaletteMap& paletteMap);
DrawPixelInfo& dpi, const ImageId imageId, const ScreenCoordsXY& coords, const PaletteMap& paletteMap);
void FASTCALL GfxDrawSpriteRawMaskedSoftware(
DrawPixelInfo* dpi, const ScreenCoordsXY& scrCoords, const ImageId maskImage, const ImageId colourImage);
DrawPixelInfo& dpi, const ScreenCoordsXY& scrCoords, const ImageId maskImage, const ImageId colourImage);
// string
void GfxDrawString(DrawPixelInfo& dpi, const ScreenCoordsXY& coords, const_utf8string buffer, TextPaint textPaint = {});

View File

@ -180,11 +180,11 @@ void LightFXInit()
CalcRescaleLightHalf(_bakedLightTexture_spot_0, _bakedLightTexture_spot_1, 32, 32);
}
void LightFXUpdateBuffers(DrawPixelInfo* info)
void LightFXUpdateBuffers(DrawPixelInfo& info)
{
_light_rendered_buffer_front = realloc(_light_rendered_buffer_front, info->width * info->height);
_light_rendered_buffer_back = realloc(_light_rendered_buffer_back, info->width * info->height);
_pixelInfo = *info;
_light_rendered_buffer_front = realloc(_light_rendered_buffer_front, info.width * info.height);
_light_rendered_buffer_back = realloc(_light_rendered_buffer_back, info.width * info.height);
_pixelInfo = info;
}
void LightFXPrepareLightList()

View File

@ -48,7 +48,7 @@ bool LightFXForVehiclesIsAvailable();
void LightFXInit();
void LightFXUpdateBuffers(DrawPixelInfo*);
void LightFXUpdateBuffers(DrawPixelInfo&);
void LightFXPrepareLightList();
void LightFXSwapBuffers();

View File

@ -16,14 +16,14 @@
* Draws a horizontal line of specified colour to a buffer.
* rct2: 0x0068474C
*/
static void GfxDrawLineOnBuffer(DrawPixelInfo* dpi, char colour, const ScreenCoordsXY& coords, int32_t no_pixels)
static void GfxDrawLineOnBuffer(DrawPixelInfo& dpi, char colour, const ScreenCoordsXY& coords, int32_t no_pixels)
{
ScreenCoordsXY offset{ coords.x - dpi->x, coords.y - dpi->y };
ScreenCoordsXY offset{ coords.x - dpi.x, coords.y - dpi.y };
// Check to make sure point is in the y range
if (offset.y < 0)
return;
if (offset.y >= dpi->height)
if (offset.y >= dpi.height)
return;
// Check to make sure we are drawing at least a pixel
if (!no_pixels)
@ -41,18 +41,18 @@ static void GfxDrawLineOnBuffer(DrawPixelInfo* dpi, char colour, const ScreenCoo
}
// Ensure that the end point of the line is within range
if (offset.x + no_pixels - dpi->width > 0)
if (offset.x + no_pixels - dpi.width > 0)
{
// If the end point has any pixels outside range
// cut them off. If there are now no pixels return.
no_pixels -= offset.x + no_pixels - dpi->width;
no_pixels -= offset.x + no_pixels - dpi.width;
if (no_pixels <= 0)
return;
}
// Get the buffer we are drawing to and move to the first coordinate.
uint8_t* bits_pointer = dpi->bits
+ offset.y * (static_cast<int64_t>(static_cast<int64_t>(dpi->pitch) + static_cast<int64_t>(dpi->width))) + offset.x;
uint8_t* bits_pointer = dpi.bits
+ offset.y * (static_cast<int64_t>(static_cast<int64_t>(dpi.pitch) + static_cast<int64_t>(dpi.width))) + offset.x;
// Draw the line to the specified colour
for (; no_pixels > 0; --no_pixels, ++bits_pointer)
@ -72,29 +72,29 @@ static void GfxDrawLineOnBuffer(DrawPixelInfo* dpi, char colour, const ScreenCoo
* colour (ebp)
*/
void GfxDrawLineSoftware(DrawPixelInfo* dpi, const ScreenLine& line, int32_t colour)
void GfxDrawLineSoftware(DrawPixelInfo& dpi, const ScreenLine& line, int32_t colour)
{
int32_t x1 = line.GetX1();
int32_t x2 = line.GetX2();
int32_t y1 = line.GetY1();
int32_t y2 = line.GetY2();
// Check to make sure the line is within the drawing area
if ((x1 < dpi->x) && (x2 < dpi->x))
if ((x1 < dpi.x) && (x2 < dpi.x))
{
return;
}
if ((y1 < dpi->y) && (y2 < dpi->y))
if ((y1 < dpi.y) && (y2 < dpi.y))
{
return;
}
if ((x1 > (dpi->x + dpi->width)) && (x2 > (dpi->x + dpi->width)))
if ((x1 > (dpi.x + dpi.width)) && (x2 > (dpi.x + dpi.width)))
{
return;
}
if ((y1 > (dpi->y + dpi->height)) && (y2 > (dpi->y + dpi->height)))
if ((y1 > (dpi.y + dpi.height)) && (y2 > (dpi.y + dpi.height)))
{
return;
}

View File

@ -58,7 +58,7 @@ static void ScrollingTextInitialiseCharacterBitmaps(uint32_t glyphStart, uint16_
for (int32_t i = 0; i < count; i++)
{
std::fill_n(drawingSurface, sizeof(drawingSurface), 0x00);
GfxDrawSpriteSoftware(&dpi, ImageId(glyphStart + (EnumValue(FontStyle::Tiny) * count) + i), { -1, 0 });
GfxDrawSpriteSoftware(dpi, ImageId(glyphStart + (EnumValue(FontStyle::Tiny) * count) + i), { -1, 0 });
for (int32_t x = 0; x < 8; x++)
{

View File

@ -340,7 +340,7 @@ void X8DrawingEngine::ConfigureBits(uint32_t width, uint32_t height, uint32_t pi
if (LightFXIsAvailable())
{
LightFXUpdateBuffers(dpi);
LightFXUpdateBuffers(*dpi);
}
}
@ -704,18 +704,18 @@ void X8DrawingContext::FilterRect(
void X8DrawingContext::DrawLine(DrawPixelInfo* dpi, uint32_t colour, const ScreenLine& line)
{
GfxDrawLineSoftware(dpi, line, colour);
GfxDrawLineSoftware(*dpi, line, colour);
}
void X8DrawingContext::DrawSprite(DrawPixelInfo* dpi, const ImageId imageId, int32_t x, int32_t y)
{
GfxDrawSpriteSoftware(dpi, imageId, { x, y });
GfxDrawSpriteSoftware(*dpi, imageId, { x, y });
}
void X8DrawingContext::DrawSpriteRawMasked(
DrawPixelInfo* dpi, int32_t x, int32_t y, const ImageId maskImage, const ImageId colourImage)
{
GfxDrawSpriteRawMaskedSoftware(dpi, { x, y }, maskImage, colourImage);
GfxDrawSpriteRawMaskedSoftware(*dpi, { x, y }, maskImage, colourImage);
}
void X8DrawingContext::DrawSpriteSolid(DrawPixelInfo* dpi, const ImageId image, int32_t x, int32_t y, uint8_t colour)
@ -725,10 +725,10 @@ void X8DrawingContext::DrawSpriteSolid(DrawPixelInfo* dpi, const ImageId image,
palette[0] = 0;
const auto spriteCoords = ScreenCoordsXY{ x, y };
GfxDrawSpritePaletteSetSoftware(dpi, ImageId(image.GetIndex(), 0), spriteCoords, PaletteMap(palette));
GfxDrawSpritePaletteSetSoftware(*dpi, ImageId(image.GetIndex(), 0), spriteCoords, PaletteMap(palette));
}
void X8DrawingContext::DrawGlyph(DrawPixelInfo* dpi, const ImageId image, int32_t x, int32_t y, const PaletteMap& paletteMap)
{
GfxDrawSpritePaletteSetSoftware(dpi, image, { x, y }, paletteMap);
GfxDrawSpritePaletteSetSoftware(*dpi, image, { x, y }, paletteMap);
}

View File

@ -60,7 +60,7 @@ void CarEntrySetImageMaxSizes(CarEntry& carEntry, int32_t numImages)
for (int32_t i = 0; i < numImages; ++i)
{
GfxDrawSpriteSoftware(&dpi, ImageId(carEntry.base_image_id + i), { 0, 0 });
GfxDrawSpriteSoftware(dpi, ImageId(carEntry.base_image_id + i), { 0, 0 });
}
int32_t spriteWidth = -1;
for (int32_t i = 99; i != 0; --i)