From 25ce8b3f6e7034bbfe4dc4751f2b1d76d005bade Mon Sep 17 00:00:00 2001 From: Simon Jarrett Date: Sat, 3 Oct 2020 18:41:56 +0100 Subject: [PATCH] Fix #7443: Construction arrows pulse at irregular intervals. --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/Footpath.cpp | 12 ++++-- src/openrct2-ui/windows/RideConstruction.cpp | 39 +++++++++++--------- src/openrct2/ride/Ride.cpp | 25 +++---------- src/openrct2/ride/Ride.h | 1 - src/openrct2/windows/_legacy.cpp | 2 - 6 files changed, 36 insertions(+), 44 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 4d6e9aba2c..39a6850ebc 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -12,6 +12,7 @@ - Fix: [#5178] Lighting effects cannot be disabled in software mode - 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: [#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-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 205e4344d2..2a5a3c6499 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ static constexpr const rct_string_id WINDOW_TITLE = STR_FOOTPATHS; static constexpr const int32_t WH = 381; static constexpr const int32_t WW = 106; +static constexpr const uint16_t ARROW_PULSE_DURATION = 200; // clang-format off enum @@ -129,7 +131,7 @@ static rct_window_event_list window_footpath_events([](auto& events) // clang-format on static money32 _window_footpath_cost; -static int8_t _window_footpath_provisional_path_arrow_timer; +static uint32_t _footpathConstructionNextArrowPulse = 0; static uint8_t _lastUpdatedCameraRotation = UINT8_MAX; static bool _footpathErrorOccured; @@ -473,10 +475,13 @@ static void window_footpath_update_provisional_path_for_bridge_mode(rct_window* widget_invalidate(w, WIDX_CONSTRUCT); } + auto curTime = platform_get_ticks(); + // Update little directional arrow on provisional bridge mode path - if (--_window_footpath_provisional_path_arrow_timer < 0) + if (_footpathConstructionNextArrowPulse < curTime) { - _window_footpath_provisional_path_arrow_timer = 5; + _footpathConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; + gFootpathProvisionalFlags ^= PROVISIONAL_PATH_FLAG_SHOW_ARROW; CoordsXYZ footpathLoc; footpath_get_next_path_info(&type, footpathLoc, &slope); @@ -932,7 +937,6 @@ static void window_footpath_start_bridge_at_point(const ScreenCoordsXY& screenCo gFootpathConstructFromPosition = { mapCoords, z }; gFootpathConstructDirection = direction; gFootpathProvisionalFlags = 0; - _window_footpath_provisional_path_arrow_timer = 0; gFootpathConstructSlope = 0; gFootpathConstructionMode = PATH_CONSTRUCTION_MODE_BRIDGE_OR_TUNNEL; gFootpathConstructValidDirections = INVALID_DIRECTION; diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index d6e4fd0686..c84f53cf0d 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ static constexpr const rct_string_id WINDOW_TITLE = STR_RIDE_CONSTRUCTION_WINDOW_TITLE; static constexpr const int32_t WH = 394; static constexpr const int32_t WW = 166; +static constexpr const uint16_t ARROW_PULSE_DURATION = 200; #pragma region Widgets @@ -441,6 +443,7 @@ static uint8_t _currentlyShowingBrakeOrBoosterSpeed; static bool _boosterTrackSelected; static uint32_t _currentDisabledSpecialTrackPieces; +static uint32_t _rideConstructionNextArrowPulse = 0; static void window_ride_construction_construct(rct_window* w); static void window_ride_construction_mouseup_demolish(rct_window* w); @@ -562,7 +565,6 @@ rct_window* window_ride_construction_open() _currentTrackPieceDirection = 0; _rideConstructionState = RIDE_CONSTRUCTION_STATE_PLACE; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; _autoOpeningShop = false; _autoRotatingShop = true; _trackPlaceCtrlState = false; @@ -1708,7 +1710,6 @@ static void RideConstructPlacedForwardGameActionCallback(const GameAction* ga, c _currentTrackPieceDirection = next_track.element->GetDirection(); _currentTrackPieceType = next_track.element->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; _rideConstructionState = RIDE_CONSTRUCTION_STATE_SELECTED; ride_select_next_section(); } @@ -1752,7 +1753,6 @@ static void RideConstructPlacedBackwardGameActionCallback(const GameAction* ga, _currentTrackPieceDirection = trackBeginEnd.begin_direction; _currentTrackPieceType = trackBeginEnd.begin_element->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; _rideConstructionState = RIDE_CONSTRUCTION_STATE_SELECTED; ride_select_previous_section(); } @@ -2550,6 +2550,7 @@ void sub_6C94D8() { case RIDE_CONSTRUCTION_STATE_FRONT: case RIDE_CONSTRUCTION_STATE_BACK: + { if (!(_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_TRACK)) { if (window_ride_construction_update_state( @@ -2564,11 +2565,12 @@ void sub_6C94D8() window_ride_construction_update_active_elements(); } } - _rideConstructionArrowPulseTime--; - if (_rideConstructionArrowPulseTime >= 0) - break; - _rideConstructionArrowPulseTime = 5; + auto curTime = platform_get_ticks(); + if (_rideConstructionNextArrowPulse >= curTime) + break; + _rideConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; + _currentTrackSelectionFlags ^= TRACK_SELECTION_FLAG_ARROW; trackPos = _currentTrackBegin; direction = _currentTrackPieceDirection; @@ -2584,13 +2586,14 @@ void sub_6C94D8() gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW; map_invalidate_tile_full(trackPos); break; + } case RIDE_CONSTRUCTION_STATE_SELECTED: { - _rideConstructionArrowPulseTime--; - if (_rideConstructionArrowPulseTime >= 0) + auto curTime = platform_get_ticks(); + if (_rideConstructionNextArrowPulse >= curTime) break; + _rideConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; - _rideConstructionArrowPulseTime = 5; _currentTrackSelectionFlags ^= TRACK_SELECTION_FLAG_ARROW; direction = _currentTrackPieceDirection & 3; type = _currentTrackPieceType; @@ -2604,14 +2607,15 @@ void sub_6C94D8() } break; } - case 6: - case 7: - case 8: - _rideConstructionArrowPulseTime--; - if (_rideConstructionArrowPulseTime >= 0) + case RIDE_CONSTRUCTION_STATE_MAZE_BUILD: + case RIDE_CONSTRUCTION_STATE_MAZE_MOVE: + case RIDE_CONSTRUCTION_STATE_MAZE_FILL: + { + auto curTime = platform_get_ticks(); + if (_rideConstructionNextArrowPulse >= curTime) break; + _rideConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; - _rideConstructionArrowPulseTime = 5; _currentTrackSelectionFlags ^= TRACK_SELECTION_FLAG_ARROW; trackPos = CoordsXYZ{ _currentTrackBegin.x & 0xFFE0, _currentTrackBegin.y & 0xFFE0, _currentTrackBegin.z + 15 }; gMapSelectArrowPosition = trackPos; @@ -2631,6 +2635,7 @@ void sub_6C94D8() gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_ARROW; map_invalidate_tile_full(trackPos); break; + } } } @@ -3755,7 +3760,6 @@ void ride_construction_tooldown_construct(const ScreenCoordsXY& screenCoords) _currentTrackBegin.y = mapCoords.y; _currentTrackBegin.z = z; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; auto intent = Intent(INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION); context_broadcast_intent(&intent); w = window_find_by_class(WC_RIDE_CONSTRUCTION); @@ -3812,7 +3816,6 @@ void ride_construction_tooldown_construct(const ScreenCoordsXY& screenCoords) _currentTrackBegin.y = mapCoords.y; _currentTrackBegin.z = z; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; window_ride_construction_update_active_elements(); w = window_find_by_class(WC_RIDE_CONSTRUCTION); if (w == nullptr) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 944ee6e997..aa35143372 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -101,7 +101,6 @@ CoordsXYZ _currentTrackBegin; uint8_t _currentTrackPieceDirection; track_type_t _currentTrackPieceType; uint8_t _currentTrackSelectionFlags; -int8_t _rideConstructionArrowPulseTime; uint8_t _currentTrackSlopeEnd; uint8_t _currentTrackBankEnd; uint8_t _currentTrackLiftHill; @@ -1611,6 +1610,12 @@ void ride_select_next_section() // Set next element's height. virtual_floor_set_height(tileElement->GetBaseZ()); } + + _currentTrackBegin = *newCoords; + _currentTrackPieceDirection = tileElement->GetDirection(); + _currentTrackPieceType = tileElement->AsTrack()->GetTrackType(); + _currentTrackSelectionFlags = 0; + window_ride_construction_update_active_elements(); } else { @@ -1619,18 +1624,9 @@ void ride_select_next_section() _currentTrackPieceDirection = direction; _currentTrackPieceType = tileElement->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; ride_construction_set_default_next_piece(); window_ride_construction_update_active_elements(); - return; } - - _currentTrackBegin = *newCoords; - _currentTrackPieceDirection = tileElement->GetDirection(); - _currentTrackPieceType = tileElement->AsTrack()->GetTrackType(); - _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; - window_ride_construction_update_active_elements(); } else if (_rideConstructionState == RIDE_CONSTRUCTION_STATE_BACK) { @@ -1673,7 +1669,6 @@ void ride_select_previous_section() _currentTrackPieceDirection = trackBeginEnd.begin_direction; _currentTrackPieceType = trackBeginEnd.begin_element->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; if (!scenery_tool_is_active()) { // Set previous element's height. @@ -1690,7 +1685,6 @@ void ride_select_previous_section() _currentTrackPieceDirection = trackBeginEnd.end_direction; _currentTrackPieceType = tileElement->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; ride_construction_set_default_next_piece(); window_ride_construction_update_active_elements(); } @@ -1799,7 +1793,6 @@ static bool ride_modify_maze(const CoordsXYE& tileElement) _currentTrackBegin.y = tileElement.y; _currentTrackBegin.z = trackElement->GetBaseZ(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; auto intent = Intent(INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION); context_broadcast_intent(&intent); @@ -1880,7 +1873,6 @@ bool ride_modify(CoordsXYE* input) _currentTrackPieceDirection = direction; _currentTrackPieceType = type; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_NO_TRACK)) { @@ -1900,7 +1892,6 @@ bool ride_modify(CoordsXYE* input) _currentTrackPieceDirection = direction; _currentTrackPieceType = type; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; ride_select_previous_section(); @@ -1911,7 +1902,6 @@ bool ride_modify(CoordsXYE* input) _currentTrackPieceDirection = direction; _currentTrackPieceType = type; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; } window_ride_construction_update_active_elements(); @@ -1958,7 +1948,6 @@ int32_t ride_initialise_construction_window(Ride* ride) _currentTrackPieceDirection = 0; _rideConstructionState = RIDE_CONSTRUCTION_STATE_PLACE; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; window_ride_construction_update_active_elements(); return 1; @@ -6260,7 +6249,6 @@ bool ride_select_backwards_from_front() _currentTrackPieceDirection = trackBeginEnd.begin_direction; _currentTrackPieceType = trackBeginEnd.begin_element->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; return true; } } @@ -6286,7 +6274,6 @@ bool ride_select_forwards_from_back() _currentTrackPieceDirection = next_track.element->GetDirection(); _currentTrackPieceType = next_track.element->AsTrack()->GetTrackType(); _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; return true; } } diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 7342e16cc8..5829bea8fc 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1061,7 +1061,6 @@ extern CoordsXYZ _currentTrackBegin; extern uint8_t _currentTrackPieceDirection; extern track_type_t _currentTrackPieceType; extern uint8_t _currentTrackSelectionFlags; -extern int8_t _rideConstructionArrowPulseTime; extern uint8_t _currentTrackSlopeEnd; extern uint8_t _currentTrackBankEnd; extern uint8_t _currentTrackLiftHill; diff --git a/src/openrct2/windows/_legacy.cpp b/src/openrct2/windows/_legacy.cpp index 27a910576f..a6f914e387 100644 --- a/src/openrct2/windows/_legacy.cpp +++ b/src/openrct2/windows/_legacy.cpp @@ -434,7 +434,6 @@ void window_ride_construction_mouseup_demolish_next_piece(const CoordsXYZD& piec _currentTrackBegin.z = floor2(piecePos.z, COORDS_Z_STEP); _rideConstructionState = RIDE_CONSTRUCTION_STATE_FRONT; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; _currentTrackPieceDirection = piecePos.direction & 3; int32_t savedCurrentTrackCurve = _currentTrackCurve; int32_t savedPreviousTrackSlopeEnd = _previousTrackSlopeEnd; @@ -489,7 +488,6 @@ void window_ride_construction_mouseup_demolish_next_piece(const CoordsXYZD& piec _currentTrackPieceDirection = piecePos.direction; _currentTrackPieceType = type; _currentTrackSelectionFlags = 0; - _rideConstructionArrowPulseTime = 0; if (_rideConstructionState2 == RIDE_CONSTRUCTION_STATE_FRONT) { ride_select_next_section();