From be824e941fbf2624efe53bae07edcc32f76d0578 Mon Sep 17 00:00:00 2001 From: Haven Kim Date: Sat, 17 Oct 2020 14:13:40 -0700 Subject: [PATCH] Fix #7518: Water isn't cut down by view clipping tool (#13205) By comparing water level and clipping height, we just remove water from rendering but keep the surface tiles at the bottom --- distribution/changelog.txt | 1 + .../paint/tile_element/Paint.Surface.cpp | 55 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 6a9b7bbf56..d1a5d273b0 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -15,6 +15,7 @@ - Fix: [#5904] Empty errors on tile inspector base height change. - Fix: [#6086] Cannot install existing track design with another name. - Fix: [#7443] Construction arrows pulse at irregular intervals. +- Fix: [#7518] Water isn't cut down by view clipping tool. - Fix: [#7748] Tooltips would not timeout for normal UI elements. - Fix: [#8015] RCT2 files are not found when put into the OpenRCT2 folder. - Fix: [#8957] Error title missing when building with insufficient funds diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index b1396ac942..60948bef0f 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -1288,45 +1288,44 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c std::memcpy(session->RightTunnels, backupRightTunnels, sizeof(tunnel_entry) * TUNNEL_MAX_COUNT); } - if (tileElement->AsSurface()->GetWaterHeight() > 0) + const uint16_t waterHeight = tileElement->AsSurface()->GetWaterHeight(); + const bool waterGetsClipped = (session->ViewFlags & VIEWPORT_FLAG_CLIP_VIEW) && (waterHeight > gClipHeight * COORDS_Z_STEP); + + if (waterHeight > 0 && !gTrackDesignSaveMode && !waterGetsClipped) { // loc_6615A9: (water height) session->InteractionType = VIEWPORT_INTERACTION_ITEM_WATER; const uint16_t localHeight = height + 16; - const uint16_t waterHeight = tileElement->AsSurface()->GetWaterHeight(); - if (!gTrackDesignSaveMode) + session->WaterHeight = waterHeight; + + int32_t image_offset = 0; + if (waterHeight <= localHeight) { - session->WaterHeight = waterHeight; + image_offset = byte_97B740[surfaceShape & 0xF]; + } - int32_t image_offset = 0; - if (waterHeight <= localHeight) - { - image_offset = byte_97B740[surfaceShape & 0xF]; - } + const int32_t image_id = (SPR_WATER_MASK + image_offset) | IMAGE_TYPE_REMAP | IMAGE_TYPE_TRANSPARENT + | PALETTE_WATER << 19; + sub_98196C(session, image_id, 0, 0, 32, 32, -1, waterHeight); - const int32_t image_id = (SPR_WATER_MASK + image_offset) | IMAGE_TYPE_REMAP | IMAGE_TYPE_TRANSPARENT - | PALETTE_WATER << 19; - sub_98196C(session, image_id, 0, 0, 32, 32, -1, waterHeight); + paint_attach_to_previous_ps(session, SPR_WATER_OVERLAY + image_offset, 0, 0); - paint_attach_to_previous_ps(session, SPR_WATER_OVERLAY + image_offset, 0, 0); + if (!(session->ViewFlags & VIEWPORT_FLAG_HIDE_VERTICAL)) + { + // This wasn't in the original, but the code depended on globals that were only set in a different conditional + const uint32_t edgeStyle = tileElement->AsSurface()->GetEdgeStyle(); + // end new code - if (!(session->ViewFlags & VIEWPORT_FLAG_HIDE_VERTICAL)) - { - // This wasn't in the original, but the code depended on globals that were only set in a different conditional - const uint32_t edgeStyle = tileElement->AsSurface()->GetEdgeStyle(); - // end new code - - viewport_surface_draw_water_side_bottom( - session, EDGE_BOTTOMLEFT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[1]); - viewport_surface_draw_water_side_bottom( - session, EDGE_BOTTOMRIGHT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[2]); - viewport_surface_draw_water_side_top( - session, EDGE_TOPLEFT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[3]); - viewport_surface_draw_water_side_top( - session, EDGE_TOPRIGHT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[4]); - } + viewport_surface_draw_water_side_bottom( + session, EDGE_BOTTOMLEFT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[1]); + viewport_surface_draw_water_side_bottom( + session, EDGE_BOTTOMRIGHT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[2]); + viewport_surface_draw_water_side_top( + session, EDGE_TOPLEFT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[3]); + viewport_surface_draw_water_side_top( + session, EDGE_TOPRIGHT, waterHeight, edgeStyle, tileDescriptors[0], tileDescriptors[4]); } }