Use dpi ref in paint folder

This commit is contained in:
Gymnasiast 2023-04-03 21:54:13 +02:00 committed by duncanspumpkin
parent f09df5a06a
commit 3e764677da
11 changed files with 60 additions and 70 deletions

View File

@ -2669,7 +2669,7 @@ private:
TileElement tempSideTrackTileElement{ 0x80, 0x8F, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
TileElement tempTrackTileElement{};
TileElement* backupTileElementArrays[5]{};
PaintSession* session = PaintSessionAlloc(&dpi, 0);
PaintSession* session = PaintSessionAlloc(dpi, 0);
trackDirection &= 3;
auto currentRide = GetRide(rideIndex);

View File

@ -305,7 +305,7 @@ void LightFXPrepareLightList()
dpi.zoom_level = _current_view_zoom_front;
dpi.width = 1;
PaintSession* session = PaintSessionAlloc(&dpi, w->viewport->flags);
PaintSession* session = PaintSessionAlloc(dpi, w->viewport->flags);
PaintSessionGenerate(*session);
PaintSessionArrange(*session);
auto info = SetInteractionInfoFromPaintSession(session, w->viewport->flags, ViewportInteractionItemAll);

View File

@ -945,7 +945,7 @@ static void ViewportPaintColumn(PaintSession& session)
if (session.PSStringHead != nullptr)
{
PaintDrawMoneyStructs(&session.DPI, session.PSStringHead);
PaintDrawMoneyStructs(session.DPI, session.PSStringHead);
}
}
@ -1031,7 +1031,7 @@ void ViewportPaint(
// Generate and sort columns.
for (x = alignedX; x < rightBorder; x += 32, index++)
{
PaintSession* session = PaintSessionAlloc(&dpi1, viewFlags);
PaintSession* session = PaintSessionAlloc(dpi1, viewFlags);
_paintColumns.push_back(session);
DrawPixelInfo& dpi2 = session->DPI;
@ -1921,7 +1921,7 @@ InteractionInfo GetMapCoordinatesFromPosWindow(WindowBase* window, const ScreenC
dpi.zoom_level = myviewport->zoom;
dpi.width = 1;
PaintSession* session = PaintSessionAlloc(&dpi, myviewport->flags);
PaintSession* session = PaintSessionAlloc(dpi, myviewport->flags);
PaintSessionGenerate(*session);
PaintSessionArrange(*session);
info = SetInteractionInfoFromPaintSession(session, myviewport->flags, flags & 0xFFFF);

View File

@ -47,8 +47,7 @@ void EntityPaintSetup(PaintSession& session, const CoordsXY& pos)
return;
}
DrawPixelInfo* dpi = &session.DPI;
if (dpi->zoom_level > ZoomLevel{ 2 })
if (session.DPI.zoom_level > ZoomLevel{ 2 })
{
return;
}
@ -95,10 +94,8 @@ void EntityPaintSetup(PaintSession& session, const CoordsXY& pos)
}
}
dpi = &session.DPI;
if (dpi->y + dpi->height <= spr->SpriteData.SpriteRect.GetTop() || spr->SpriteData.SpriteRect.GetBottom() <= dpi->y
|| dpi->x + dpi->width <= spr->SpriteData.SpriteRect.GetLeft() || spr->SpriteData.SpriteRect.GetRight() <= dpi->x)
if (session.DPI.y + session.DPI.height <= spr->SpriteData.SpriteRect.GetTop() || spr->SpriteData.SpriteRect.GetBottom() <= session.DPI.y
|| session.DPI.x + session.DPI.width <= spr->SpriteData.SpriteRect.GetLeft() || spr->SpriteData.SpriteRect.GetRight() <= session.DPI.x)
{
continue;
}

View File

@ -55,8 +55,8 @@ bool gShowDirtyVisuals;
bool gPaintBoundingBoxes;
bool gPaintBlockedTiles;
static void PaintAttachedPS(DrawPixelInfo* dpi, PaintStruct* ps, uint32_t viewFlags);
static void PaintPSImageWithBoundingBoxes(DrawPixelInfo* dpi, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y);
static void PaintAttachedPS(DrawPixelInfo& dpi, PaintStruct* ps, uint32_t viewFlags);
static void PaintPSImageWithBoundingBoxes(DrawPixelInfo& dpi, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y);
static ImageId PaintPSColourifyImage(const PaintStruct* ps, ImageId imageId, uint32_t viewFlags);
static int32_t RemapPositionToQuadrant(const PaintStruct& ps, uint8_t rotation)
@ -483,18 +483,16 @@ void PaintSessionArrange(PaintSessionCore& session)
static void PaintDrawStruct(PaintSession& session, PaintStruct* ps)
{
DrawPixelInfo* dpi = &session.DPI;
auto x = ps->x;
auto y = ps->y;
if (ps->sprite_type == ViewportInteractionItem::Entity)
{
if (dpi->zoom_level >= ZoomLevel{ 1 })
if (session.DPI.zoom_level >= ZoomLevel{ 1 })
{
x = Floor2(x, 2);
y = Floor2(y, 2);
if (dpi->zoom_level >= ZoomLevel{ 2 })
if (session.DPI.zoom_level >= ZoomLevel{ 2 })
{
x = Floor2(x, 4);
y = Floor2(y, 4);
@ -503,13 +501,13 @@ static void PaintDrawStruct(PaintSession& session, PaintStruct* ps)
}
auto imageId = PaintPSColourifyImage(ps, ps->image_id, session.ViewFlags);
if (gPaintBoundingBoxes && dpi->zoom_level == ZoomLevel{ 0 })
if (gPaintBoundingBoxes && session.DPI.zoom_level == ZoomLevel{ 0 })
{
PaintPSImageWithBoundingBoxes(dpi, ps, imageId, x, y);
PaintPSImageWithBoundingBoxes(session.DPI, ps, imageId, x, y);
}
else
{
GfxDrawSprite(*dpi, imageId, { x, y });
GfxDrawSprite(session.DPI, imageId, { x, y });
}
if (ps->children != nullptr)
@ -518,7 +516,7 @@ static void PaintDrawStruct(PaintSession& session, PaintStruct* ps)
}
else
{
PaintAttachedPS(dpi, ps, session.ViewFlags);
PaintAttachedPS(session.DPI, ps, session.ViewFlags);
}
}
@ -545,7 +543,7 @@ void PaintDrawStructs(PaintSession& session)
* rct2: 0x00688596
* Part of 0x688485
*/
static void PaintAttachedPS(DrawPixelInfo* dpi, PaintStruct* ps, uint32_t viewFlags)
static void PaintAttachedPS(DrawPixelInfo& dpi, PaintStruct* ps, uint32_t viewFlags)
{
AttachedPaintStruct* attached_ps = ps->attached_ps;
for (; attached_ps != nullptr; attached_ps = attached_ps->next)
@ -555,16 +553,16 @@ static void PaintAttachedPS(DrawPixelInfo* dpi, PaintStruct* ps, uint32_t viewFl
auto imageId = PaintPSColourifyImage(ps, attached_ps->image_id, viewFlags);
if (attached_ps->IsMasked)
{
GfxDrawSpriteRawMasked(dpi, screenCoords, imageId, attached_ps->ColourImageId);
GfxDrawSpriteRawMasked(&dpi, screenCoords, imageId, attached_ps->ColourImageId);
}
else
{
GfxDrawSprite(*dpi, imageId, screenCoords);
GfxDrawSprite(dpi, imageId, screenCoords);
}
}
}
static void PaintPSImageWithBoundingBoxes(DrawPixelInfo* dpi, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y)
static void PaintPSImageWithBoundingBoxes(DrawPixelInfo& dpi, PaintStruct* ps, ImageId imageId, int32_t x, int32_t y)
{
const uint8_t colour = BoundBoxDebugColours[EnumValue(ps->sprite_type)];
const uint8_t rotation = GetCurrentRotation();
@ -626,28 +624,28 @@ static void PaintPSImageWithBoundingBoxes(DrawPixelInfo* dpi, PaintStruct* ps, I
const auto screenCoordBackBottom = Translate3DTo2DWithZ(rotation, backBottom);
// bottom square
GfxDrawLine(dpi, { screenCoordFrontBottom, screenCoordLeftBottom }, colour);
GfxDrawLine(dpi, { screenCoordBackBottom, screenCoordLeftBottom }, colour);
GfxDrawLine(dpi, { screenCoordBackBottom, screenCoordRightBottom }, colour);
GfxDrawLine(dpi, { screenCoordFrontBottom, screenCoordRightBottom }, colour);
GfxDrawLine(&dpi, { screenCoordFrontBottom, screenCoordLeftBottom }, colour);
GfxDrawLine(&dpi, { screenCoordBackBottom, screenCoordLeftBottom }, colour);
GfxDrawLine(&dpi, { screenCoordBackBottom, screenCoordRightBottom }, colour);
GfxDrawLine(&dpi, { screenCoordFrontBottom, screenCoordRightBottom }, colour);
// vertical back + sides
GfxDrawLine(dpi, { screenCoordBackTop, screenCoordBackBottom }, colour);
GfxDrawLine(dpi, { screenCoordLeftTop, screenCoordLeftBottom }, colour);
GfxDrawLine(dpi, { screenCoordRightTop, screenCoordRightBottom }, colour);
GfxDrawLine(&dpi, { screenCoordBackTop, screenCoordBackBottom }, colour);
GfxDrawLine(&dpi, { screenCoordLeftTop, screenCoordLeftBottom }, colour);
GfxDrawLine(&dpi, { screenCoordRightTop, screenCoordRightBottom }, colour);
// top square back
GfxDrawLine(dpi, { screenCoordBackTop, screenCoordLeftTop }, colour);
GfxDrawLine(dpi, { screenCoordBackTop, screenCoordRightTop }, colour);
GfxDrawLine(&dpi, { screenCoordBackTop, screenCoordLeftTop }, colour);
GfxDrawLine(&dpi, { screenCoordBackTop, screenCoordRightTop }, colour);
GfxDrawSprite(*dpi, imageId, { x, y });
GfxDrawSprite(dpi, imageId, { x, y });
// vertical front
GfxDrawLine(dpi, { screenCoordFrontTop, screenCoordFrontBottom }, colour);
GfxDrawLine(&dpi, { screenCoordFrontTop, screenCoordFrontBottom }, colour);
// top square
GfxDrawLine(dpi, { screenCoordFrontTop, screenCoordLeftTop }, colour);
GfxDrawLine(dpi, { screenCoordFrontTop, screenCoordRightTop }, colour);
GfxDrawLine(&dpi, { screenCoordFrontTop, screenCoordLeftTop }, colour);
GfxDrawLine(&dpi, { screenCoordFrontTop, screenCoordRightTop }, colour);
}
static ImageId PaintPSColourifyImage(const PaintStruct* ps, ImageId imageId, uint32_t viewFlags)
@ -664,7 +662,7 @@ static ImageId PaintPSColourifyImage(const PaintStruct* ps, ImageId imageId, uin
}
}
PaintSession* PaintSessionAlloc(DrawPixelInfo* dpi, uint32_t viewFlags)
PaintSession* PaintSessionAlloc(DrawPixelInfo& dpi, uint32_t viewFlags)
{
return GetContext()->GetPainter()->CreateSession(dpi, viewFlags);
}
@ -877,7 +875,7 @@ void PaintFloatingMoneyEffect(
*
* rct2: 0x006860C3
*/
void PaintDrawMoneyStructs(DrawPixelInfo* dpi, PaintStringStruct* ps)
void PaintDrawMoneyStructs(DrawPixelInfo& dpi, PaintStringStruct* ps)
{
do
{
@ -893,7 +891,7 @@ void PaintDrawMoneyStructs(DrawPixelInfo* dpi, PaintStringStruct* ps)
}
GfxDrawStringWithYOffsets(
*dpi, buffer, COLOUR_BLACK, { ps->x, ps->y }, reinterpret_cast<int8_t*>(ps->y_offsets), forceSpriteFont,
dpi, buffer, COLOUR_BLACK, { ps->x, ps->y }, reinterpret_cast<int8_t*>(ps->y_offsets), forceSpriteFont,
FontStyle::Medium);
} while ((ps = ps->next) != nullptr);
}

View File

@ -344,9 +344,9 @@ void PaintFloatingMoneyEffect(
PaintSession& session, money64 amount, StringId string_id, int32_t y, int32_t z, int8_t y_offsets[], int32_t offset_x,
uint32_t rotation);
PaintSession* PaintSessionAlloc(DrawPixelInfo* dpi, uint32_t viewFlags);
PaintSession* PaintSessionAlloc(DrawPixelInfo& dpi, uint32_t viewFlags);
void PaintSessionFree(PaintSession* session);
void PaintSessionGenerate(PaintSession& session);
void PaintSessionArrange(PaintSessionCore& session);
void PaintDrawStructs(PaintSession& session);
void PaintDrawMoneyStructs(DrawPixelInfo* dpi, PaintStringStruct* ps);
void PaintDrawMoneyStructs(DrawPixelInfo& dpi, PaintStringStruct* ps);

View File

@ -74,16 +74,16 @@ void Painter::Paint(IDrawingEngine& de)
text = "Normalising...";
if (text != nullptr)
PaintReplayNotice(dpi, text);
PaintReplayNotice(*dpi, text);
if (gConfigGeneral.ShowFPS)
{
PaintFPS(dpi);
PaintFPS(*dpi);
}
gCurrentDrawCount++;
}
void Painter::PaintReplayNotice(DrawPixelInfo* dpi, const char* text)
void Painter::PaintReplayNotice(DrawPixelInfo& dpi, const char* text)
{
ScreenCoordsXY screenCoords(_uiContext->GetWidth() / 2, _uiContext->GetHeight() - 44);
@ -94,13 +94,13 @@ void Painter::PaintReplayNotice(DrawPixelInfo* dpi, const char* text)
screenCoords.x = screenCoords.x - stringWidth;
if (((gCurrentTicks >> 1) & 0xF) > 4)
GfxDrawString(*dpi, screenCoords, buffer, { COLOUR_SATURATED_RED });
GfxDrawString(dpi, screenCoords, buffer, { COLOUR_SATURATED_RED });
// Make area dirty so the text doesn't get drawn over the last
GfxSetDirtyBlocks({ screenCoords, screenCoords + ScreenCoordsXY{ stringWidth, 16 } });
}
void Painter::PaintFPS(DrawPixelInfo* dpi)
void Painter::PaintFPS(DrawPixelInfo& dpi)
{
ScreenCoordsXY screenCoords(_uiContext->GetWidth() / 2, 2);
@ -112,10 +112,10 @@ void Painter::PaintFPS(DrawPixelInfo* dpi)
// Draw Text
int32_t stringWidth = GfxGetStringWidth(buffer, FontStyle::Medium);
screenCoords.x = screenCoords.x - (stringWidth / 2);
GfxDrawString(*dpi, screenCoords, buffer);
GfxDrawString(dpi, screenCoords, buffer);
// Make area dirty so the text doesn't get drawn over the last
GfxSetDirtyBlocks({ { screenCoords - ScreenCoordsXY{ 16, 4 } }, { dpi->lastStringPos.x + 16, 16 } });
GfxSetDirtyBlocks({ { screenCoords - ScreenCoordsXY{ 16, 4 } }, { dpi.lastStringPos.x + 16, 16 } });
}
void Painter::MeasureFPS()
@ -131,7 +131,7 @@ void Painter::MeasureFPS()
_lastSecond = currentTime;
}
PaintSession* Painter::CreateSession(DrawPixelInfo* dpi, uint32_t viewFlags)
PaintSession* Painter::CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags)
{
PROFILED_FUNCTION();
@ -152,7 +152,7 @@ PaintSession* Painter::CreateSession(DrawPixelInfo* dpi, uint32_t viewFlags)
session = _paintSessionPool.back().get();
}
session->DPI = *dpi;
session->DPI = dpi;
session->ViewFlags = viewFlags;
session->QuadrantBackIndex = std::numeric_limits<uint32_t>::max();
session->QuadrantFrontIndex = 0;

View File

@ -47,13 +47,13 @@ namespace OpenRCT2
explicit Painter(const std::shared_ptr<Ui::IUiContext>& uiContext);
void Paint(Drawing::IDrawingEngine& de);
PaintSession* CreateSession(DrawPixelInfo* dpi, uint32_t viewFlags);
PaintSession* CreateSession(DrawPixelInfo& dpi, uint32_t viewFlags);
void ReleaseSession(PaintSession* session);
~Painter();
private:
void PaintReplayNotice(DrawPixelInfo* dpi, const char* text);
void PaintFPS(DrawPixelInfo* dpi);
void PaintReplayNotice(DrawPixelInfo& dpi, const char* text);
void PaintFPS(DrawPixelInfo& dpi);
void MeasureFPS();
};
} // namespace Paint

View File

@ -274,9 +274,9 @@ static void PathBitBenchesPaint(
/* rct2: 0x006A6008 */
static void PathBitJumpingFountainsPaint(
PaintSession& session, const PathBitEntry& pathBitEntry, int32_t height, ImageId imageTemplate, DrawPixelInfo* dpi)
PaintSession& session, const PathBitEntry& pathBitEntry, int32_t height, ImageId imageTemplate, DrawPixelInfo& dpi)
{
if (dpi->zoom_level > ZoomLevel{ 0 })
if (dpi.zoom_level > ZoomLevel{ 0 })
return;
auto imageId = imageTemplate.WithIndex(pathBitEntry.image);
@ -781,9 +781,7 @@ static void Sub6A3F61(
// Probably drawing benches etc.
PROFILED_FUNCTION();
DrawPixelInfo* dpi = &session.DPI;
if (dpi->zoom_level <= ZoomLevel{ 1 })
if (session.DPI.zoom_level <= ZoomLevel{ 1 })
{
if (!gTrackDesignSaveMode)
{
@ -826,7 +824,7 @@ static void Sub6A3F61(
sceneryImageTemplate);
break;
case PathBitDrawType::JumpingFountain:
PathBitJumpingFountainsPaint(session, *pathAddEntry, height, sceneryImageTemplate, dpi);
PathBitJumpingFountainsPaint(session, *pathAddEntry, height, sceneryImageTemplate, session.DPI);
break;
}

View File

@ -1023,12 +1023,11 @@ void PaintSurface(PaintSession& session, uint8_t direction, uint16_t height, con
{
PROFILED_FUNCTION();
DrawPixelInfo* dpi = &session.DPI;
session.InteractionType = ViewportInteractionItem::Terrain;
session.Flags |= PaintSessionFlags::PassedSurface;
session.Surface = &tileElement;
const auto zoomLevel = dpi->zoom_level;
const auto zoomLevel = session.DPI.zoom_level;
const uint8_t rotation = session.CurrentRotation;
const auto terrain_type = tileElement.GetSurfaceStyle();
const uint8_t surfaceShape = ViewportSurfacePaintSetupGetRelativeSlope(tileElement, rotation);

View File

@ -94,12 +94,11 @@ static void BlankTilesPaint(PaintSession& session, int32_t x, int32_t y)
dx -= 16;
int32_t bx = dx + 32;
DrawPixelInfo* dpi = &session.DPI;
if (bx <= dpi->y)
if (bx <= session.DPI.y)
return;
dx -= 20;
dx -= dpi->height;
if (dx >= dpi->y)
dx -= session.DPI.height;
if (dx >= session.DPI.y)
return;
session.SpritePosition.x = x;
@ -119,7 +118,6 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor
PROFILED_FUNCTION();
CoordsXY coords = origCoords;
DrawPixelInfo* dpi = &session.DPI;
if ((session.ViewFlags & VIEWPORT_FLAG_CLIP_VIEW))
{
@ -184,7 +182,7 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor
PaintAddImageAsParent(session, imageId, { 0, 0, arrowZ }, { { 0, 0, arrowZ + 18 }, { 32, 32, -1 } });
}
if (screenMinY + 52 <= dpi->y)
if (screenMinY + 52 <= session.DPI.y)
return;
const TileElement* element = tile_element; // push tile_element
@ -208,7 +206,7 @@ static void PaintTileElementBase(PaintSession& session, const CoordsXY& origCoor
max_height = std::max(max_height, VirtualFloorGetHeight());
}
if (screenMinY - (max_height + 32) >= dpi->y + dpi->height)
if (screenMinY - (max_height + 32) >= session.DPI.y + session.DPI.height)
return;
session.SpritePosition.x = coords.x;