From b5317ee9e9e78a4b289ff20ccccbea571d171f49 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 2 Jan 2019 19:52:53 +0100 Subject: [PATCH] Split drawing of path and railing --- .../interface/ViewportInteraction.cpp | 2 +- src/openrct2-ui/windows/TileInspector.cpp | 2 +- src/openrct2-ui/windows/TopToolbar.cpp | 2 +- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- .../paint/tile_element/Paint.Path.cpp | 53 ++++++++++--------- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/ride/RideRatings.cpp | 2 +- src/openrct2/ride/TrackDesignSave.cpp | 4 +- src/openrct2/world/Footpath.cpp | 31 ++++++++--- src/openrct2/world/TileElement.h | 10 ++-- 11 files changed, 68 insertions(+), 44 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index bd50241f67..45f143a74a 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -504,7 +504,7 @@ static void viewport_interaction_remove_footpath(TileElement* tileElement, int32 */ static void viewport_interaction_remove_footpath_item(TileElement* tileElement, int32_t x, int32_t y) { - int32_t type = tileElement->AsPath()->GetEntryIndex(); + int32_t type = tileElement->AsPath()->GetPathEntryIndex(); if (tileElement->AsPath()->IsQueue()) type |= 0x80; diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index b817d8a1e0..cd38411ba0 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -1804,7 +1804,7 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi) { // Details // Path name - rct_string_id pathNameId = tileElement->AsPath()->GetEntry()->string_idx; + rct_string_id pathNameId = tileElement->AsPath()->GetPathEntry()->string_idx; gfx_draw_string_left(dpi, STR_TILE_INSPECTOR_PATH_NAME, &pathNameId, COLOUR_DARK_GREEN, x, y); // Path addition diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index e9df1c03c3..b3f474f740 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1458,7 +1458,7 @@ static void sub_6E1F34( if (tile_element->AsPath()->IsSloped()) *parameter_1 |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED << 8; *parameter_2 = tile_element->base_height; - *parameter_2 |= (tile_element->AsPath()->GetEntryIndex() << 8); + *parameter_2 |= (tile_element->AsPath()->GetPathEntryIndex() << 8); if (tile_element->AsPath()->IsQueue()) { *parameter_2 |= LOCATION_NULL; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index cc651010ec..13894501e8 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -135,7 +135,7 @@ void setup_in_use_selection_flags() case TILE_ELEMENT_TYPE_TRACK: break; case TILE_ELEMENT_TYPE_PATH: - type = iter.element->AsPath()->GetEntryIndex(); + type = iter.element->AsPath()->GetPathEntryIndex(); assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 17dce36a74..5732d9c01a 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -78,11 +78,11 @@ static constexpr const uint8_t byte_98D8A4[] = { // clang-format on void path_paint_box_support( - paint_session* session, const TileElement* tileElement, int32_t height, rct_footpath_entry* footpathEntry, bool hasFences, - uint32_t imageFlags, uint32_t sceneryImageFlags); + paint_session* session, const TileElement* tileElement, int32_t height, rct_footpath_entry* footpathEntry, + rct_footpath_entry* railingEntry, bool hasFences, uint32_t imageFlags, uint32_t sceneryImageFlags); void path_paint_pole_support( - paint_session* session, const TileElement* tileElement, int16_t height, rct_footpath_entry* footpathEntry, bool hasFences, - uint32_t imageFlags, uint32_t sceneryImageFlags); + paint_session* session, const TileElement* tileElement, int16_t height, rct_footpath_entry* footpathEntry, + rct_footpath_entry* railingEntry, bool hasFences, uint32_t imageFlags, uint32_t sceneryImageFlags); /* rct2: 0x006A5AE5 */ static void path_bit_lights_paint( @@ -924,17 +924,20 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile sub_98196C(session, imageId, 16, 16, 1, 1, 0, height2); } - rct_footpath_entry* footpathEntry = tile_element->AsPath()->GetEntry(); + rct_footpath_entry* footpathEntry = tile_element->AsPath()->GetPathEntry(); + rct_footpath_entry* railingEntry = tile_element->AsPath()->GetRailingEntry(); - if (footpathEntry != nullptr) + if (footpathEntry != nullptr && railingEntry != nullptr) { - if (footpathEntry->support_type == FOOTPATH_ENTRY_SUPPORT_TYPE_POLE) + if (railingEntry->support_type == FOOTPATH_ENTRY_SUPPORT_TYPE_POLE) { - path_paint_pole_support(session, tile_element, height, footpathEntry, word_F3F038, imageFlags, sceneryImageFlags); + path_paint_pole_support( + session, tile_element, height, footpathEntry, railingEntry, word_F3F038, imageFlags, sceneryImageFlags); } else { - path_paint_box_support(session, tile_element, height, footpathEntry, word_F3F038, imageFlags, sceneryImageFlags); + path_paint_box_support( + session, tile_element, height, footpathEntry, railingEntry, word_F3F038, imageFlags, sceneryImageFlags); } } @@ -973,8 +976,8 @@ void path_paint(paint_session* session, uint16_t height, const TileElement* tile } void path_paint_box_support( - paint_session* session, const TileElement* tileElement, int32_t height, rct_footpath_entry* footpathEntry, bool hasFences, - uint32_t imageFlags, uint32_t sceneryImageFlags) + paint_session* session, const TileElement* tileElement, int32_t height, rct_footpath_entry* footpathEntry, + rct_footpath_entry* railingEntry, bool hasFences, uint32_t imageFlags, uint32_t sceneryImageFlags) { PathElement* pathElement = tileElement->AsPath(); @@ -1042,18 +1045,19 @@ void path_paint_box_support( { image_id = ((tileElement->AsPath()->GetSlopeDirection() + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) - + footpathEntry->bridge_image + 51; + + railingEntry->bridge_image + 51; } else { - image_id = byte_98D8A4[edges] + footpathEntry->bridge_image + 49; + image_id = byte_98D8A4[edges] + railingEntry->bridge_image + 49; } sub_98197C( session, image_id | imageFlags, 0, 0, boundBoxSize.x, boundBoxSize.y, 0, height, boundBoxOffset.x, boundBoxOffset.y, height + boundingBoxZOffset); - if (!pathElement->IsQueue() && !(footpathEntry->flags & FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE)) + // TODO: Revert this when path import works correctly. + if (!pathElement->IsQueue() && !(railingEntry->flags & FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE)) { // don't draw } @@ -1065,7 +1069,7 @@ void path_paint_box_support( } } - sub_6A3F61(session, tileElement, edi, height, footpathEntry, imageFlags, sceneryImageFlags, hasFences); + sub_6A3F61(session, tileElement, edi, height, railingEntry, imageFlags, sceneryImageFlags, hasFences); uint16_t ax = 0; if (tileElement->AsPath()->IsSloped()) @@ -1075,11 +1079,11 @@ void path_paint_box_support( if (byte_98D8A4[edges] == 0) { - path_a_supports_paint_setup(session, 0, ax, height, imageFlags, footpathEntry, nullptr); + path_a_supports_paint_setup(session, 0, ax, height, imageFlags, railingEntry, nullptr); } else { - path_a_supports_paint_setup(session, 1, ax, height, imageFlags, footpathEntry, nullptr); + path_a_supports_paint_setup(session, 1, ax, height, imageFlags, railingEntry, nullptr); } height += 32; @@ -1126,8 +1130,8 @@ void path_paint_box_support( } void path_paint_pole_support( - paint_session* session, const TileElement* tileElement, int16_t height, rct_footpath_entry* footpathEntry, bool hasFences, - uint32_t imageFlags, uint32_t sceneryImageFlags) + paint_session* session, const TileElement* tileElement, int16_t height, rct_footpath_entry* footpathEntry, + rct_footpath_entry* railingEntry, bool hasFences, uint32_t imageFlags, uint32_t sceneryImageFlags) { PathElement* pathElement = tileElement->AsPath(); @@ -1195,11 +1199,11 @@ void path_paint_pole_support( { bridgeImage = ((tileElement->AsPath()->GetSlopeDirection() + session->CurrentRotation) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) - + footpathEntry->bridge_image + 16; + + railingEntry->bridge_image + 16; } else { - bridgeImage = edges + footpathEntry->bridge_image; + bridgeImage = edges + railingEntry->bridge_image; bridgeImage |= imageFlags; } @@ -1207,7 +1211,8 @@ void path_paint_pole_support( session, bridgeImage | imageFlags, 0, 0, boundBoxSize.x, boundBoxSize.y, 0, height, boundBoxOffset.x, boundBoxOffset.y, height + boundingBoxZOffset); - if (pathElement->IsQueue() || (footpathEntry->flags & FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE)) + // TODO: Revert this when path import works correctly. + if (pathElement->IsQueue() || (railingEntry->flags & FOOTPATH_ENTRY_FLAG_HAS_PATH_BASE_SPRITE)) { sub_98199C( session, imageId | imageFlags, 0, 0, boundBoxSize.x, boundBoxSize.y, 0, height, boundBoxOffset.x, @@ -1215,7 +1220,7 @@ void path_paint_pole_support( } } - sub_6A3F61(session, tileElement, edi, height, footpathEntry, imageFlags, sceneryImageFlags, hasFences); // TODO: arguments + sub_6A3F61(session, tileElement, edi, height, railingEntry, imageFlags, sceneryImageFlags, hasFences); // TODO: arguments uint16_t ax = 0; if (tileElement->AsPath()->IsSloped()) @@ -1234,7 +1239,7 @@ void path_paint_pole_support( { if (!(edges & (1 << i))) { - path_b_supports_paint_setup(session, supports[i], ax, height, imageFlags, footpathEntry); + path_b_supports_paint_setup(session, supports[i], ax, height, imageFlags, railingEntry); } } diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 37db11af4e..923ed43482 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2063,7 +2063,7 @@ private: dst2->SetDirection(0); dst2->flags &= ~(TILE_ELEMENT_FLAG_BROKEN | TILE_ELEMENT_FLAG_INDESTRUCTIBLE_TRACK_PIECE); - dst2->SetEntryIndex(entryIndex); + dst2->SetPathEntryIndex(entryIndex); if (RCT1::PathIsQueue(pathType)) { dst2->SetIsQueue(true); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 82b7dd8acf..885f2184fe 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -919,7 +919,7 @@ public: auto dst2 = dst->AsPath(); auto src2 = src->AsPath(); - dst2->SetEntryIndex(src2->GetEntryIndex()); + dst2->SetPathEntryIndex(src2->GetEntryIndex()); dst2->SetQueueBannerDirection(src2->GetQueueBannerDirection()); dst2->SetSloped(src2->IsSloped()); dst2->SetSlopeDirection(src2->GetSlopeDirection()); diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index cb99a041c7..6ae9ec9eb8 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -568,7 +568,7 @@ static void ride_ratings_score_close_proximity(TileElement* inputTileElement) break; case TILE_ELEMENT_TYPE_PATH: // Bonus for normal path - if (tileElement->AsPath()->GetEntryIndex() != 0) + if (tileElement->AsPath()->GetPathEntryIndex() != 0) { if (tileElement->clearance_height == inputTileElement->base_height) { diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index e6ae1686eb..5fc028eece 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -370,7 +370,7 @@ static void track_design_save_add_wall(int32_t x, int32_t y, TileElement* tileEl static void track_design_save_add_footpath(int32_t x, int32_t y, TileElement* tileElement) { - int32_t entryType = tileElement->AsPath()->GetEntryIndex(); + int32_t entryType = tileElement->AsPath()->GetPathEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_PATHS, entryType); uint8_t flags = 0; @@ -557,7 +557,7 @@ static void track_design_save_remove_wall(int32_t x, int32_t y, TileElement* til static void track_design_save_remove_footpath(int32_t x, int32_t y, TileElement* tileElement) { - int32_t entryType = tileElement->AsPath()->GetEntryIndex(); + int32_t entryType = tileElement->AsPath()->GetPathEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_PATHS, entryType); uint8_t flags = 0; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 99b831cbe3..1a97ae6b23 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -277,7 +277,7 @@ static money32 footpath_element_insert( tileElement->SetType(TILE_ELEMENT_TYPE_PATH); PathElement* pathElement = tileElement->AsPath(); pathElement->clearance_height = z + 4 + ((slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) ? 2 : 0); - pathElement->SetEntryIndex(type); + pathElement->SetPathEntryIndex(type); pathElement->SetSlopeDirection(slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); if (slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) pathElement->SetSloped(true); @@ -315,7 +315,7 @@ static money32 footpath_element_update( const int32_t newFootpathType = (type & (FOOTPATH_PROPERTIES_TYPE_MASK >> 4)); const bool newPathIsQueue = ((type >> 7) == 1); - if (tileElement->AsPath()->GetEntryIndex() != newFootpathType || tileElement->AsPath()->IsQueue() != newPathIsQueue) + if (tileElement->AsPath()->GetPathEntryIndex() != newFootpathType || tileElement->AsPath()->IsQueue() != newPathIsQueue) { gFootpathPrice += MONEY(6, 00); } @@ -414,7 +414,7 @@ static money32 footpath_element_update( if (!(flags & GAME_COMMAND_FLAG_PATH_SCENERY)) footpath_remove_edges_at(x, y, tileElement); - tileElement->AsPath()->SetEntryIndex(type); + tileElement->AsPath()->SetPathEntryIndex(type); if (type & (1 << 7)) tileElement->AsPath()->SetIsQueue(true); else @@ -670,7 +670,7 @@ static money32 footpath_place_from_track( return MONEY32_UNDEFINED; } pathElement->clearance_height = z + 4 + ((slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) ? 2 : 0); - pathElement->SetEntryIndex(type & 0xF); + pathElement->SetPathEntryIndex(type & 0xF); pathElement->SetSlopeDirection(slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); if (slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) pathElement->SetSloped(true); @@ -2091,22 +2091,37 @@ void PathElement::SetAdditionIsGhost(bool isGhost) additions |= FOOTPATH_ADDITION_FLAG_IS_GHOST; } -uint8_t PathElement::GetEntryIndex() const +uint8_t PathElement::GetPathEntryIndex() const { return (entryIndex & FOOTPATH_PROPERTIES_TYPE_MASK) >> 4; } -rct_footpath_entry* PathElement::GetEntry() const +uint8_t PathElement::GetRailingEntryIndex() const { - return get_footpath_entry(GetEntryIndex()); + return GetPathEntryIndex(); } -void PathElement::SetEntryIndex(uint8_t newEntryIndex) +rct_footpath_entry* PathElement::GetPathEntry() const +{ + return get_footpath_entry(GetPathEntryIndex()); +} + +rct_footpath_entry* PathElement::GetRailingEntry() const +{ + return get_footpath_entry(GetRailingEntryIndex()); +} + +void PathElement::SetPathEntryIndex(uint8_t newEntryIndex) { entryIndex &= ~FOOTPATH_PROPERTIES_TYPE_MASK; entryIndex |= (newEntryIndex << 4); } +void PathElement::SetRailingEntryIndex(uint8_t newEntryIndex) +{ + log_verbose("Setting railing entry index to %d", newEntryIndex); +} + uint8_t PathElement::GetQueueBannerDirection() const { return ((type & FOOTPATH_ELEMENT_TYPE_DIRECTION_MASK) >> 6); diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index ca6f223ff8..5cfee6bf60 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -176,9 +176,13 @@ private: }; public: - uint8_t GetEntryIndex() const; - rct_footpath_entry* GetEntry() const; - void SetEntryIndex(uint8_t newIndex); + uint8_t GetPathEntryIndex() const; + rct_footpath_entry* GetPathEntry() const; + void SetPathEntryIndex(uint8_t newIndex); + + uint8_t GetRailingEntryIndex() const; + rct_footpath_entry* GetRailingEntry() const; + void SetRailingEntryIndex(uint8_t newIndex); uint8_t GetQueueBannerDirection() const; void SetQueueBannerDirection(uint8_t direction);