From 0f4560598e311e90f492ff315917e2fa5e3fc66d Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Thu, 4 Oct 2018 15:40:55 +0200 Subject: [PATCH] Replace residual access to path element entry index field --- .../interface/ViewportInteraction.cpp | 12 ++-- src/openrct2-ui/windows/Footpath.cpp | 28 ++++----- src/openrct2-ui/windows/TopToolbar.cpp | 10 +-- src/openrct2/EditorObjectSelectionSession.cpp | 3 +- src/openrct2/peep/Guest.cpp | 3 +- src/openrct2/peep/Peep.cpp | 8 +-- src/openrct2/ride/TrackDesignSave.cpp | 11 ++-- src/openrct2/world/Footpath.cpp | 63 ++++++++++++------- src/openrct2/world/Map.cpp | 9 ++- src/openrct2/world/TileElement.h | 1 + src/openrct2/world/TileInspector.cpp | 6 +- 11 files changed, 86 insertions(+), 68 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index b4d9e3e58f..c7cfb2c3aa 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -504,16 +504,16 @@ static void viewport_interaction_remove_footpath(rct_tile_element* tileElement, */ static void viewport_interaction_remove_footpath_item(rct_tile_element* tileElement, int32_t x, int32_t y) { - int32_t type; - - type = tileElement->AsPath()->GetEntryIndex(); + int32_t type = tileElement->AsPath()->GetEntryIndex(); if (tileElement->AsPath()->IsQueue()) type |= 0x80; + int32_t slopeData = tileElement->AsPath()->GetSlopeDirection(); + if (tileElement->AsPath()->IsSloped()) + slopeData |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; + gGameCommandErrorTitle = STR_CANT_REMOVE_THIS; - game_do_command( - x, ((tileElement->properties.path.type & 7) << 8) | 1, y, (type << 8) | tileElement->base_height, - GAME_COMMAND_PLACE_PATH, 0, 0); + game_do_command(x, (slopeData << 8) | 1, y, (type << 8) | tileElement->base_height, GAME_COMMAND_PLACE_PATH, 0, 0); } /** diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 6e64b61454..591746e731 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -758,8 +758,9 @@ static void window_footpath_set_provisional_path_at_point(int32_t x, int32_t y) slope = DefaultPathSlope[tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; break; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - slope = tileElement->properties.path.type - & (FOOTPATH_PROPERTIES_FLAG_IS_SLOPED | FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); + slope = tileElement->AsPath()->GetSlopeDirection(); + if (tileElement->AsPath()->IsSloped()) + slope |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; break; } int32_t pathType = (gFootpathSelectedType << 7) + (gFootpathSelectedId & 0xFF); @@ -854,7 +855,7 @@ static void window_footpath_place_path_at_point(int32_t x, int32_t y) currentType = DefaultPathSlope[tileElement->AsSurface()->GetSlope() & TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK]; break; case VIEWPORT_INTERACTION_ITEM_FOOTPATH: - currentType = tileElement->properties.path.type & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + currentType = tileElement->AsPath()->GetSlopeDirection(); if (tileElement->AsPath()->IsSloped()) { currentType |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; @@ -918,9 +919,9 @@ static void window_footpath_start_bridge_at_point(int32_t screenX, int32_t scree z = tileElement->base_height; if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (tileElement->properties.path.type & 4) + if (tileElement->AsPath()->IsSloped()) { - if (direction == (tileElement->properties.path.type & 3)) + if (direction == (tileElement->AsPath()->GetSlopeDirection())) { z += 2; } @@ -1002,12 +1003,11 @@ static void footpath_remove_tile_element(rct_tile_element* tileElement) int32_t x, y, z; z = tileElement->base_height; - int32_t pathType = tileElement->properties.path.type; - if (pathType & 4) + if (tileElement->AsPath()->IsSloped()) { - pathType &= 3; - pathType ^= 2; - if (pathType == gFootpathConstructDirection) + uint8_t slopeDirection = tileElement->AsPath()->GetSlopeDirection(); + slopeDirection ^= 2; + if (slopeDirection == gFootpathConstructDirection) { z += 2; } @@ -1073,9 +1073,9 @@ static rct_tile_element* footpath_get_tile_element_to_remove() { if (tileElement->base_height == z) { - if (tileElement->properties.path.type & 4) + if (tileElement->AsPath()->IsSloped()) { - if (((tileElement->properties.path.type & 3) ^ 2) != gFootpathConstructDirection) + if (((tileElement->AsPath()->GetSlopeDirection()) ^ 2) != gFootpathConstructDirection) { continue; } @@ -1085,9 +1085,9 @@ static rct_tile_element* footpath_get_tile_element_to_remove() } else if (tileElement->base_height == zLow) { - if (!(tileElement->properties.path.type & 4)) + if (!tileElement->AsPath()->IsSloped()) { - if ((tileElement->properties.path.type & 3) == gFootpathConstructDirection) + if ((tileElement->AsPath()->GetSlopeDirection()) == gFootpathConstructDirection) { continue; } diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 3e046a255a..30fcae58ef 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -1450,9 +1450,9 @@ static void sub_6E1F34( return; } - *parameter_1 = (tile_element->properties.path.type - & (FOOTPATH_PROPERTIES_FLAG_IS_SLOPED | FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK)) - << 8; + *parameter_1 = tile_element->AsPath()->GetSlopeDirection() << 8; + 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); if (tile_element->AsPath()->IsQueue()) @@ -1606,9 +1606,9 @@ static void sub_6E1F34( int16_t z = tile_element->base_height; - if (tile_element->properties.path.type & (1 << 2)) + if (tile_element->AsPath()->IsSloped()) { - if (rotation != ((tile_element->properties.path.type & 3) ^ 2)) + if (rotation != ((tile_element->AsPath()->GetSlopeDirection()) ^ 2)) { z += 2; } diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 377006cd49..63b4cb3b40 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -131,8 +131,7 @@ void setup_in_use_selection_flags() case TILE_ELEMENT_TYPE_TRACK: break; case TILE_ELEMENT_TYPE_PATH: - type = iter.element->properties.path.type; - type >>= 4; + type = iter.element->AsPath()->GetEntryIndex(); assert(type < object_entry_group_counts[OBJECT_TYPE_PATHS]); Editor::SetSelectedObject(OBJECT_TYPE_PATHS, type, OBJECT_SELECTION_FLAG_SELECTED); diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index e3e7c3249a..4f1582c750 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -4913,7 +4913,8 @@ void rct_peep::UpdateRideLeaveExit() if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - int16_t height = map_height_from_slope({ x, y }, tileElement->properties.path.type, tileElement->AsPath()->IsSloped()); + int16_t height = map_height_from_slope( + { x, y }, tileElement->AsPath()->GetSlopeDirection(), tileElement->AsPath()->IsSloped()); height += tileElement->base_height * 8; int16_t z_diff = z - height; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index d457d680ab..b659d5a141 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1022,7 +1022,7 @@ void rct_peep::UpdateFalling() if (tile_element->GetType() == TILE_ELEMENT_TYPE_PATH) { int32_t height = map_height_from_slope( - { x, y }, tile_element->properties.path.type, tile_element->AsPath()->IsSloped()) + { x, y }, tile_element->AsPath()->GetSlopeDirection(), tile_element->AsPath()->IsSloped()) + tile_element->base_height * 8; if (height < z - 1 || height > z + 4) @@ -1099,7 +1099,7 @@ void rct_peep::UpdateFalling() } else { - SetNextFlags(saved_map->properties.path.type & 0x3, saved_map->properties.path.type & 0x4, false); + SetNextFlags(saved_map->AsPath()->GetSlopeDirection(), saved_map->AsPath()->IsSloped(), false); } SetState(PEEP_STATE_1); } @@ -2731,7 +2731,7 @@ static void peep_footpath_move_forward(rct_peep* peep, int16_t x, int16_t y, rct peep->next_x = (x & 0xFFE0); peep->next_y = (y & 0xFFE0); peep->next_z = tile_element->base_height; - peep->SetNextFlags(tile_element->properties.path.type & 3, tile_element->properties.path.type & 4, false); + peep->SetNextFlags(tile_element->AsPath()->GetSlopeDirection(), tile_element->AsPath()->IsSloped(), false); int16_t z = peep->GetZOnSlope(x, y); @@ -2926,7 +2926,7 @@ static void peep_interact_with_path(rct_peep* peep, int16_t x, int16_t y, rct_ti peep->time_lost = 0; uint8_t stationNum = tile_element->AsPath()->GetStationIndex(); - if ((tile_element->properties.path.type & (1 << 3)) // Queue has the ride sign on it + if ((tile_element->AsPath()->HasQueueBanner()) && (tile_element->AsPath()->GetQueueBannerDirection() == ((peep->direction) ^ 2)) // Ride sign is facing the direction the peep is walking ) diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 8932f32dbc..33f4cdb90f 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -370,12 +370,12 @@ static void track_design_save_add_wall(int32_t x, int32_t y, rct_tile_element* t static void track_design_save_add_footpath(int32_t x, int32_t y, rct_tile_element* tileElement) { - int32_t entryType = tileElement->properties.path.type >> 4; + int32_t entryType = tileElement->AsPath()->GetEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_PATHS, entryType); uint8_t flags = 0; flags |= tileElement->properties.path.edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; - flags |= (tileElement->properties.path.type & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) << 5; + flags |= (tileElement->AsPath()->GetSlopeDirection()) << 5; if (tileElement->AsPath()->IsSloped()) flags |= 0b00010000; if (tileElement->AsPath()->IsQueue()) @@ -557,13 +557,14 @@ static void track_design_save_remove_wall(int32_t x, int32_t y, rct_tile_element static void track_design_save_remove_footpath(int32_t x, int32_t y, rct_tile_element* tileElement) { - int32_t entryType = tileElement->properties.path.type >> 4; + int32_t entryType = tileElement->AsPath()->GetEntryIndex(); auto entry = object_entry_get_entry(OBJECT_TYPE_PATHS, entryType); uint8_t flags = 0; flags |= tileElement->properties.path.edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; - flags |= (tileElement->properties.path.type & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) << 2; - flags |= (tileElement->properties.path.type & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK) << 5; + if (tileElement->AsPath()->IsSloped()) + flags |= (1 << 4); + flags |= (tileElement->AsPath()->GetSlopeDirection()) << 5; if (tileElement->AsPath()->IsQueue()) flags |= (1 << 7); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index e543c9a863..f216d57a59 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -154,14 +154,14 @@ rct_tile_element* map_get_footpath_element(int32_t x, int32_t y, int32_t z) static rct_tile_element* map_get_footpath_element_slope(int32_t x, int32_t y, int32_t z, int32_t slope) { rct_tile_element* tileElement; + bool isSloped = slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; tileElement = map_get_first_element_at(x, y); do { if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->base_height == z - && (tileElement->properties.path.type - & (FOOTPATH_PROPERTIES_FLAG_IS_SLOPED | FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK)) - == slope) + && (tileElement->AsPath()->IsSloped() == isSloped) + && (tileElement->AsPath()->GetSlopeDirection() == (slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK))) { return tileElement; } @@ -265,17 +265,20 @@ static money32 footpath_element_insert( { tileElement = tile_element_insert(x / 32, y / 32, z, 0x0F); assert(tileElement != nullptr); - tileElement->type = TILE_ELEMENT_TYPE_PATH; - tileElement->clearance_height = z + 4 + ((slope & TILE_ELEMENT_SLOPE_NE_SIDE_UP) ? 2 : 0); - tileElement->AsPath()->SetEntryIndex(type); - tileElement->properties.path.type |= (slope & TILE_ELEMENT_SLOPE_W_CORNER_DN); + 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->SetSlopeDirection(slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); + if (slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) + pathElement->SetSloped(true); if (type & FOOTPATH_ELEMENT_INSERT_QUEUE) - tileElement->AsPath()->SetIsQueue(true); - tileElement->AsPath()->SetAddition(pathItemType); + pathElement->SetIsQueue(true); + pathElement->SetAddition(pathItemType); tileElement->properties.path.addition_status = 255; - tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; + pathElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; if (flags & GAME_COMMAND_FLAG_GHOST) - tileElement->flags |= TILE_ELEMENT_FLAG_GHOST; + pathElement->flags |= TILE_ELEMENT_FLAG_GHOST; footpath_queue_chain_reset(); @@ -646,16 +649,27 @@ static money32 footpath_place_from_track( { tileElement = tile_element_insert(x / 32, y / 32, z, 0x0F); assert(tileElement != nullptr); - tileElement->type = TILE_ELEMENT_TYPE_PATH; - tileElement->clearance_height = z + 4 + ((slope & TILE_ELEMENT_SLOPE_S_CORNER_UP) ? 2 : 0); - tileElement->properties.path.type = (type << 4) | (slope & TILE_ELEMENT_SLOPE_W_CORNER_DN); + tileElement->SetType(TILE_ELEMENT_TYPE_PATH); + PathElement* pathElement = tileElement->AsPath(); + // This can NEVER happen, but GCC does not want to believe that... + if (pathElement == nullptr) + { + assert(false); + return MONEY32_UNDEFINED; + } + pathElement->clearance_height = z + 4 + ((slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) ? 2 : 0); + pathElement->SetEntryIndex(type & 0xF); + pathElement->SetSlopeDirection(slope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); + if (slope & FOOTPATH_PROPERTIES_FLAG_IS_SLOPED) + pathElement->SetSloped(true); + tileElement->type |= type >> 7; - tileElement->AsPath()->SetAddition(0); + pathElement->SetAddition(0); tileElement->properties.path.addition_status = 255; tileElement->properties.path.edges = edges & FOOTPATH_PROPERTIES_EDGES_EDGES_MASK; - tileElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; + pathElement->flags &= ~TILE_ELEMENT_FLAG_BROKEN; if (flags & (1 << 6)) - tileElement->flags |= TILE_ELEMENT_FLAG_GHOST; + pathElement->flags |= TILE_ELEMENT_FLAG_GHOST; map_invalidate_tile_full(x, y); } @@ -1266,13 +1280,13 @@ static bool sub_footpath_disconnect_queue_from_path( rct_tile_element* otherTileElement = footpath_get_element(x1, y1, z - 2, z, direction); if (otherTileElement != nullptr && !otherTileElement->AsPath()->IsQueue()) { - tileElement->properties.path.type &= ~FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + tileElement->AsPath()->SetSlopeDirection(0); if (action > 0) { tileElement->properties.path.edges &= ~(1 << direction); otherTileElement->properties.path.edges &= ~(1 << ((direction + 2) & 3)); if (action >= 2) - tileElement->properties.path.type |= direction; + tileElement->AsPath()->SetSlopeDirection(direction); } else if (action < 0) { @@ -1667,7 +1681,7 @@ void footpath_chain_ride_queue( } } - tileElement->properties.path.type &= ~FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + tileElement->AsPath()->SetHasQueueBanner(false); tileElement->properties.path.edges |= (1 << (direction ^ 2)); tileElement->properties.path.ride_index = rideIndex; tileElement->AsPath()->SetStationIndex(entranceIndex); @@ -1697,7 +1711,7 @@ void footpath_chain_ride_queue( { if (lastPathElement->AsPath()->IsQueue()) { - lastPathElement->properties.path.type |= FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + lastPathElement->AsPath()->SetHasQueueBanner(true); lastPathElement->AsPath()->SetQueueBannerDirection(lastPathDirection); // set the ride sign direction map_animation_create(MAP_ANIMATION_TYPE_QUEUE_BANNER, lastPathX, lastPathY, lastPathElement->base_height); @@ -1993,6 +2007,13 @@ bool PathElement::HasQueueBanner() const return (entryIndex & FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER) != 0; } +void PathElement::SetHasQueueBanner(bool hasQueueBanner) +{ + entryIndex &= ~FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; + if (hasQueueBanner) + entryIndex |= FOOTPATH_PROPERTIES_FLAG_HAS_QUEUE_BANNER; +} + uint8_t PathElement::GetStationIndex() const { return (additions & FOOTPATH_PROPERTIES_ADDITIONS_STATION_INDEX_MASK) >> 4; diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index aaf0b1c7d1..77b972a052 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -629,17 +629,16 @@ bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirecti if (tileElement->GetType() != TILE_ELEMENT_TYPE_PATH) continue; - rct_tile_element_path_properties props = tileElement->properties.path; - uint8_t pathDirection = props.type & 3; + uint8_t slopeDirection = tileElement->AsPath()->GetSlopeDirection(); if (tileElement->AsPath()->IsSloped()) { - if (pathDirection == faceDirection) + if (slopeDirection == faceDirection) { if (z == tileElement->base_height + 2) return true; } - else if ((pathDirection ^ 2) == faceDirection && z == tileElement->base_height) + else if ((slopeDirection ^ 2) == faceDirection && z == tileElement->base_height) { return true; } @@ -3139,7 +3138,7 @@ void map_remove_all_rides() case TILE_ELEMENT_TYPE_PATH: if (it.element->AsPath()->IsQueue()) { - it.element->properties.path.type &= ~8; + it.element->AsPath()->SetHasQueueBanner(false); it.element->properties.path.addition_status = 255; } break; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 74b454eaaa..61da534d1f 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -220,6 +220,7 @@ public: bool IsQueue() const; void SetIsQueue(bool isQueue); bool HasQueueBanner() const; + void SetHasQueueBanner(bool hasQueueBanner); bool HasAddition() const; uint8_t GetAddition() const; diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 51dd0bfa84..322ca37d89 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -611,11 +611,7 @@ int32_t tile_inspector_path_set_sloped(int32_t x, int32_t y, int32_t elementInde if (flags & GAME_COMMAND_FLAG_APPLY) { - pathElement->properties.path.type &= ~(1 << 2); - if (sloped) - { - pathElement->properties.path.type |= (1 << 2); - } + pathElement->AsPath()->SetSloped(sloped); map_invalidate_tile_full(x << 5, y << 5);