From b5d6abdd22a1833218d6bbbe6b54d5b3af3e852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 2 Jan 2022 15:45:15 +0200 Subject: [PATCH 1/3] Refactor out DidPassSurface and rename Unk141E9DB to Flags --- src/openrct2/paint/Paint.h | 6 ++++-- src/openrct2/paint/Painter.cpp | 1 + src/openrct2/paint/Supports.cpp | 12 ++++++------ src/openrct2/paint/tile_element/Paint.Path.cpp | 10 ++++++---- src/openrct2/paint/tile_element/Paint.Surface.cpp | 3 +-- .../paint/tile_element/Paint.TileElement.cpp | 5 +++-- src/openrct2/ride/TrackPaint.cpp | 2 +- src/openrct2/ride/gentle/MiniGolf.cpp | 2 +- 8 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 0dab2b06b4..508a177d12 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -210,12 +210,14 @@ struct PaintSessionCore tunnel_entry RightTunnels[TUNNEL_MAX_COUNT]; uint8_t RightTunnelCount; uint8_t VerticalTunnelHeight; - bool DidPassSurface; - uint8_t Unk141E9DB; + uint8_t Flags; uint16_t WaterHeight; uint32_t TrackColours[4]; }; +// 16544 +static constexpr size_t SizeOfPaintSessionCore = sizeof(PaintSessionCore); + struct paint_session : public PaintSessionCore { rct_drawpixelinfo DPI; diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 1615c7bf55..ab5a59349c 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -157,6 +157,7 @@ paint_session* Painter::CreateSession(rct_drawpixelinfo* dpi, uint32_t viewFlags session->QuadrantBackIndex = std::numeric_limits::max(); session->QuadrantFrontIndex = 0; session->PaintEntryChain = _paintStructPool.Create(); + session->Flags = 0; std::fill(std::begin(session->Quadrants), std::end(session->Quadrants), nullptr); session->LastPS = nullptr; diff --git a/src/openrct2/paint/Supports.cpp b/src/openrct2/paint/Supports.cpp index 04cd88d291..2cc42ef2af 100644 --- a/src/openrct2/paint/Supports.cpp +++ b/src/openrct2/paint/Supports.cpp @@ -477,7 +477,7 @@ bool wooden_a_supports_paint_setup( return false; } - if (!(session.Unk141E9DB & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { return false; } @@ -636,7 +636,7 @@ bool wooden_b_supports_paint_setup( return false; } - if (!(session.Unk141E9DB & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { return false; } @@ -806,7 +806,7 @@ bool metal_a_supports_paint_setup( return false; } - if (!(session.Unk141E9DB & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { return false; } @@ -1005,7 +1005,7 @@ bool metal_b_supports_paint_setup( return false; // AND } - if (!(session.Unk141E9DB & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { return false; // AND } @@ -1185,7 +1185,7 @@ bool path_a_supports_paint_setup( return false; } - if (!(session.Unk141E9DB & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { return false; } @@ -1335,7 +1335,7 @@ bool path_b_supports_paint_setup( return false; // AND } - if (!(session.Unk141E9DB & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { return false; // AND } diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 2d109c921c..886ee25e2c 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -1099,7 +1099,8 @@ void path_paint_box_support( surfaceBaseImageIndex += byte_98D6E0[edi]; } - if (!session.DidPassSurface) + const bool hasPassedSurface = (session.Flags & PaintSessionFlags::IsPassedSurface) != 0; + if (!hasPassedSurface) { boundBoxOffset.x = 3; boundBoxOffset.y = 3; @@ -1120,7 +1121,7 @@ void path_paint_box_support( } } - if (!hasSupports || !session.DidPassSurface) + if (!hasSupports || !hasPassedSurface) { PaintAddImageAsParent( session, imageTemplate.WithIndex(surfaceBaseImageIndex), { 0, 0, height }, { boundBoxSize, 0 }, @@ -1238,7 +1239,8 @@ void path_paint_pole_support( } // Below Surface - if (!session.DidPassSurface) + const bool hasPassedSurface = (session.Flags & PaintSessionFlags::IsPassedSurface) != 0; + if (!hasPassedSurface) { boundBoxOffset.x = 3; boundBoxOffset.y = 3; @@ -1259,7 +1261,7 @@ void path_paint_pole_support( } } - if (!hasSupports || !session.DidPassSurface) + if (!hasSupports || !hasPassedSurface) { PaintAddImageAsParent( session, imageTemplate.WithIndex(surfaceBaseImageIndex), { 0, 0, height }, { boundBoxSize.x, boundBoxSize.y, 0 }, diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index c7be8a7bd9..fa841503e6 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -978,7 +978,7 @@ void PaintSurface(paint_session& session, uint8_t direction, uint16_t height, co rct_drawpixelinfo* dpi = &session.DPI; session.InteractionType = ViewportInteractionItem::Terrain; - session.DidPassSurface = true; + session.Flags |= PaintSessionFlags::IsPassedSurface; session.SurfaceElement = reinterpret_cast(&tileElement); const auto zoomLevel = dpi->zoom_level; @@ -1414,7 +1414,6 @@ void PaintSurface(paint_session& session, uint8_t direction, uint16_t height, co } session.InteractionType = ViewportInteractionItem::Terrain; - session.Unk141E9DB |= PaintSessionFlags::IsPassedSurface; switch (surfaceShape) { diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 38c9ed9fcf..aa2fac1b0b 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -56,7 +56,7 @@ void tile_element_paint_setup(paint_session& session, const CoordsXY& mapCoords, { paint_util_set_segment_support_height(session, SEGMENTS_ALL, 0xFFFF, 0); paint_util_force_set_general_support_height(session, -1, 0); - session.Unk141E9DB = isTrackPiecePreview ? PaintSessionFlags::IsTrackPiecePreview : 0; + session.Flags = isTrackPiecePreview ? PaintSessionFlags::IsTrackPiecePreview : 0; session.WaterHeight = 0xFFFF; PaintTileElementBase(session, mapCoords); @@ -218,7 +218,8 @@ static void PaintTileElementBase(paint_session& session, const CoordsXY& origCoo session.SpritePosition.x = coords.x; session.SpritePosition.y = coords.y; - session.DidPassSurface = false; + session.Flags &= ~PaintSessionFlags::IsPassedSurface; + int32_t previousBaseZ = 0; do { diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index 9435290e54..b0093088f5 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -783,7 +783,7 @@ bool track_paint_util_draw_station_covers_2( return false; } - if (!(session.Unk141E9DB & (PaintSessionFlags::IsPassedSurface | PaintSessionFlags::IsTrackPiecePreview))) + if (!(session.Flags & (PaintSessionFlags::IsPassedSurface | PaintSessionFlags::IsTrackPiecePreview))) { return false; } diff --git a/src/openrct2/ride/gentle/MiniGolf.cpp b/src/openrct2/ride/gentle/MiniGolf.cpp index e69f5ab83a..154f828f49 100644 --- a/src/openrct2/ride/gentle/MiniGolf.cpp +++ b/src/openrct2/ride/gentle/MiniGolf.cpp @@ -462,7 +462,7 @@ static paint_struct* mini_golf_paint_util_7c( static bool mini_golf_paint_util_should_draw_fence(paint_session& session, const TrackElement& trackElement) { - if (!session.DidPassSurface) + if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) { // Should be above ground (have passed surface rendering) return false; From 9b6b5220bf8350b3a69d61d18125a0b3514c67d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sun, 2 Jan 2022 15:51:45 +0200 Subject: [PATCH 2/3] Re-order struct members of PaintSessionCore --- src/openrct2/paint/Paint.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 508a177d12..85a20e5633 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -185,6 +185,7 @@ public: struct PaintSessionCore { + paint_struct PaintHead; paint_struct* Quadrants[MaxPaintQuadrants]; paint_struct* LastPS; paint_string_struct* PSStringHead; @@ -194,30 +195,26 @@ struct PaintSessionCore const void* CurrentlyDrawnItem; const TileElement* PathElementOnSameHeight; const TileElement* TrackElementOnSameHeight; - paint_struct PaintHead; + paint_struct* WoodenSupportsPrependTo; + CoordsXY SpritePosition; + CoordsXY MapPosition; uint32_t ViewFlags; uint32_t QuadrantBackIndex; uint32_t QuadrantFrontIndex; - CoordsXY SpritePosition; - ViewportInteractionItem InteractionType; - uint8_t CurrentRotation; + uint32_t TrackColours[4]; support_height SupportSegments[9]; support_height Support; - paint_struct* WoodenSupportsPrependTo; - CoordsXY MapPosition; + uint16_t WaterHeight; tunnel_entry LeftTunnels[TUNNEL_MAX_COUNT]; - uint8_t LeftTunnelCount; tunnel_entry RightTunnels[TUNNEL_MAX_COUNT]; + uint8_t LeftTunnelCount; uint8_t RightTunnelCount; uint8_t VerticalTunnelHeight; + uint8_t CurrentRotation; uint8_t Flags; - uint16_t WaterHeight; - uint32_t TrackColours[4]; + ViewportInteractionItem InteractionType; }; -// 16544 -static constexpr size_t SizeOfPaintSessionCore = sizeof(PaintSessionCore); - struct paint_session : public PaintSessionCore { rct_drawpixelinfo DPI; From d9bdc1441f6b64120119c27c40fccffdf23c1980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 25 Feb 2022 01:21:36 +0200 Subject: [PATCH 3/3] Rename IsPassedSurface to PassedSurface and cleanup values --- src/openrct2/paint/Supports.cpp | 12 ++++++------ src/openrct2/paint/tile_element/Paint.Path.cpp | 4 ++-- src/openrct2/paint/tile_element/Paint.Surface.cpp | 2 +- .../paint/tile_element/Paint.TileElement.cpp | 2 +- src/openrct2/paint/tile_element/Paint.TileElement.h | 5 ++--- src/openrct2/ride/TrackPaint.cpp | 2 +- src/openrct2/ride/gentle/MiniGolf.cpp | 2 +- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/openrct2/paint/Supports.cpp b/src/openrct2/paint/Supports.cpp index 2cc42ef2af..a990a7bd4a 100644 --- a/src/openrct2/paint/Supports.cpp +++ b/src/openrct2/paint/Supports.cpp @@ -477,7 +477,7 @@ bool wooden_a_supports_paint_setup( return false; } - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { return false; } @@ -636,7 +636,7 @@ bool wooden_b_supports_paint_setup( return false; } - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { return false; } @@ -806,7 +806,7 @@ bool metal_a_supports_paint_setup( return false; } - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { return false; } @@ -1005,7 +1005,7 @@ bool metal_b_supports_paint_setup( return false; // AND } - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { return false; // AND } @@ -1185,7 +1185,7 @@ bool path_a_supports_paint_setup( return false; } - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { return false; } @@ -1335,7 +1335,7 @@ bool path_b_supports_paint_setup( return false; // AND } - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { return false; // AND } diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 886ee25e2c..ff5881c007 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -1099,7 +1099,7 @@ void path_paint_box_support( surfaceBaseImageIndex += byte_98D6E0[edi]; } - const bool hasPassedSurface = (session.Flags & PaintSessionFlags::IsPassedSurface) != 0; + const bool hasPassedSurface = (session.Flags & PaintSessionFlags::PassedSurface) != 0; if (!hasPassedSurface) { boundBoxOffset.x = 3; @@ -1239,7 +1239,7 @@ void path_paint_pole_support( } // Below Surface - const bool hasPassedSurface = (session.Flags & PaintSessionFlags::IsPassedSurface) != 0; + const bool hasPassedSurface = (session.Flags & PaintSessionFlags::PassedSurface) != 0; if (!hasPassedSurface) { boundBoxOffset.x = 3; diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index fa841503e6..fe4fe52d9b 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -978,7 +978,7 @@ void PaintSurface(paint_session& session, uint8_t direction, uint16_t height, co rct_drawpixelinfo* dpi = &session.DPI; session.InteractionType = ViewportInteractionItem::Terrain; - session.Flags |= PaintSessionFlags::IsPassedSurface; + session.Flags |= PaintSessionFlags::PassedSurface; session.SurfaceElement = reinterpret_cast(&tileElement); const auto zoomLevel = dpi->zoom_level; diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index aa2fac1b0b..9a3e93dc7d 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -218,7 +218,7 @@ static void PaintTileElementBase(paint_session& session, const CoordsXY& origCoo session.SpritePosition.x = coords.x; session.SpritePosition.y = coords.y; - session.Flags &= ~PaintSessionFlags::IsPassedSurface; + session.Flags &= ~PaintSessionFlags::PassedSurface; int32_t previousBaseZ = 0; do diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.h b/src/openrct2/paint/tile_element/Paint.TileElement.h index 55b2806294..264ace0807 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.h +++ b/src/openrct2/paint/tile_element/Paint.TileElement.h @@ -73,9 +73,8 @@ enum namespace PaintSessionFlags { - // Unsure as to why this exists and DidPassSurface - constexpr uint8_t IsPassedSurface = 1; - constexpr uint8_t IsTrackPiecePreview = 2; + constexpr uint8_t PassedSurface = 1u << 0; + constexpr uint8_t IsTrackPiecePreview = 1u << 1; } // namespace PaintSessionFlags #ifdef __TESTPAINT__ diff --git a/src/openrct2/ride/TrackPaint.cpp b/src/openrct2/ride/TrackPaint.cpp index b0093088f5..f0a05a7e8c 100644 --- a/src/openrct2/ride/TrackPaint.cpp +++ b/src/openrct2/ride/TrackPaint.cpp @@ -783,7 +783,7 @@ bool track_paint_util_draw_station_covers_2( return false; } - if (!(session.Flags & (PaintSessionFlags::IsPassedSurface | PaintSessionFlags::IsTrackPiecePreview))) + if (!(session.Flags & (PaintSessionFlags::PassedSurface | PaintSessionFlags::IsTrackPiecePreview))) { return false; } diff --git a/src/openrct2/ride/gentle/MiniGolf.cpp b/src/openrct2/ride/gentle/MiniGolf.cpp index 154f828f49..6e59a0cdf0 100644 --- a/src/openrct2/ride/gentle/MiniGolf.cpp +++ b/src/openrct2/ride/gentle/MiniGolf.cpp @@ -462,7 +462,7 @@ static paint_struct* mini_golf_paint_util_7c( static bool mini_golf_paint_util_should_draw_fence(paint_session& session, const TrackElement& trackElement) { - if (!(session.Flags & PaintSessionFlags::IsPassedSurface)) + if (!(session.Flags & PaintSessionFlags::PassedSurface)) { // Should be above ground (have passed surface rendering) return false;