From d09140aaedc55725dbeed1c0c51372e9bc6f03bb Mon Sep 17 00:00:00 2001 From: Duncan Date: Fri, 6 May 2022 06:46:50 +0100 Subject: [PATCH] Minor Paint refactor (#17144) * Tidy up masked paint code Its only used by surface elements and only then by attached ps's so no need to support it in the normal ps. * Remove unneeded function --- src/openrct2/paint/Paint.cpp | 24 +++++-------------- src/openrct2/paint/Paint.h | 11 ++------- .../paint/tile_element/Paint.Surface.cpp | 4 ++-- .../paint/tile_element/Paint.TileElement.cpp | 1 - 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 51dff01d52..7a9eb3694f 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -56,7 +56,6 @@ bool gPaintBlockedTiles; static void PaintAttachedPS(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t viewFlags); static void PaintPSImageWithBoundingBoxes(rct_drawpixelinfo* dpi, paint_struct* ps, ImageId imageId, int32_t x, int32_t y); -static void PaintPSImage(rct_drawpixelinfo* dpi, paint_struct* ps, ImageId imageId, int32_t x, int32_t y); static ImageId PaintPSColourifyImage(const paint_struct* ps, ImageId imageId, uint32_t viewFlags); static int32_t RemapPositionToQuadrant(const paint_struct& ps, uint8_t rotation) @@ -187,7 +186,6 @@ static paint_struct* CreateNormalPaintStruct( ps->bounds.x = rotBoundBoxOffset.x + session.SpritePosition.x; ps->bounds.y = rotBoundBoxOffset.y + session.SpritePosition.y; ps->bounds.z = rotBoundBoxOffset.z; - ps->flags = 0; ps->attached_ps = nullptr; ps->children = nullptr; ps->sprite_type = session.InteractionType; @@ -512,7 +510,7 @@ static void PaintDrawStruct(paint_session& session, paint_struct* ps) } else { - PaintPSImage(dpi, ps, imageId, x, y); + gfx_draw_sprite(dpi, imageId, { x, y }); } if (ps->children != nullptr) @@ -556,9 +554,9 @@ static void PaintAttachedPS(rct_drawpixelinfo* dpi, paint_struct* ps, uint32_t v auto screenCoords = ScreenCoordsXY{ attached_ps->x + ps->x, attached_ps->y + ps->y }; auto imageId = PaintPSColourifyImage(ps, attached_ps->image_id, viewFlags); - if (attached_ps->flags & PAINT_STRUCT_FLAG_IS_MASKED) + if (attached_ps->IsMasked) { - gfx_draw_sprite_raw_masked(dpi, screenCoords, imageId, attached_ps->colour_image_id); + gfx_draw_sprite_raw_masked(dpi, screenCoords, imageId, attached_ps->ColourImageId); } else { @@ -643,7 +641,7 @@ static void PaintPSImageWithBoundingBoxes(rct_drawpixelinfo* dpi, paint_struct* gfx_draw_line(dpi, { screenCoordBackTop, screenCoordLeftTop }, colour); gfx_draw_line(dpi, { screenCoordBackTop, screenCoordRightTop }, colour); - PaintPSImage(dpi, ps, imageId, x, y); + gfx_draw_sprite(dpi, imageId, { x, y }); // vertical front gfx_draw_line(dpi, { screenCoordFrontTop, screenCoordFrontBottom }, colour); @@ -653,16 +651,6 @@ static void PaintPSImageWithBoundingBoxes(rct_drawpixelinfo* dpi, paint_struct* gfx_draw_line(dpi, { screenCoordFrontTop, screenCoordRightTop }, colour); } -static void PaintPSImage(rct_drawpixelinfo* dpi, paint_struct* ps, ImageId imageId, int32_t x, int32_t y) -{ - if (ps->flags & PAINT_STRUCT_FLAG_IS_MASKED) - { - return gfx_draw_sprite_raw_masked(dpi, { x, y }, imageId, ps->colour_image_id); - } - - gfx_draw_sprite(dpi, imageId, { x, y }); -} - static ImageId PaintPSColourifyImage(const paint_struct* ps, ImageId imageId, uint32_t viewFlags) { auto visibility = GetPaintStructVisibility(ps, viewFlags); @@ -848,7 +836,7 @@ bool PaintAttachToPreviousAttach(paint_session& session, ImageId imageId, int32_ ps->image_id = imageId; ps->x = x; ps->y = y; - ps->flags = 0; + ps->IsMasked = false; ps->next = nullptr; previousAttachedPS->next = ps; @@ -886,7 +874,7 @@ bool PaintAttachToPreviousPS(paint_session& session, ImageId image_id, int32_t x ps->image_id = image_id; ps->x = x; ps->y = y; - ps->flags = 0; + ps->IsMasked = false; attached_paint_struct* oldFirstAttached = masterPs->attached_ps; masterPs->attached_ps = ps; diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 19cfde643a..269d4ca417 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -28,10 +28,10 @@ struct attached_paint_struct { attached_paint_struct* next; ImageId image_id; - ImageId colour_image_id; + ImageId ColourImageId; int32_t x; int32_t y; - uint8_t flags; + bool IsMasked; }; struct paint_struct_bound_box @@ -53,13 +53,11 @@ struct paint_struct TileElement* tileElement; EntityBase* entity; ImageId image_id; - ImageId colour_image_id; int32_t x; int32_t y; int32_t map_x; int32_t map_y; uint16_t quadrant_index; - uint8_t flags; uint8_t SortFlags; ViewportInteractionItem sprite_type; }; @@ -111,11 +109,6 @@ struct sprite_bb CoordsXYZ bb_size; }; -enum PAINT_STRUCT_FLAGS -{ - PAINT_STRUCT_FLAG_IS_MASKED = (1 << 0) -}; - struct support_height { uint16_t height; diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index 0205e83af5..c5656f1c6c 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -545,8 +545,8 @@ static void viewport_surface_smoothen_edge( { attached_paint_struct* out = session.LastAttachedPS; // set content and enable masking - out->colour_image_id = get_surface_pattern(neighbour.terrain, cl); - out->flags |= PAINT_STRUCT_FLAG_IS_MASKED; + out->ColourImageId = get_surface_pattern(neighbour.terrain, cl); + out->IsMasked = true; } } diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index d1ad543fc0..0470659ec8 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -342,7 +342,6 @@ static void PaintTileElementBase(paint_session& session, const CoordsXY& origCoo { xOffset + 1, yOffset + 16, segmentHeight }); if (ps != nullptr) { - ps->flags &= PAINT_STRUCT_FLAG_IS_MASKED; ps->image_id = ps->image_id.WithTertiary(COLOUR_BORDEAUX_RED); } }