From 398004901bee21e17cb8bda2f79deb3e7c9ed52c Mon Sep 17 00:00:00 2001 From: rwjuk Date: Sun, 2 Jul 2017 20:49:39 +0100 Subject: [PATCH 1/2] Only refresh ride list window every 64 ticks for perf. --- src/openrct2/windows/ride_list.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/openrct2/windows/ride_list.c b/src/openrct2/windows/ride_list.c index b35021025c..9621c3edff 100644 --- a/src/openrct2/windows/ride_list.c +++ b/src/openrct2/windows/ride_list.c @@ -228,6 +228,7 @@ void window_ride_list_open() window->min_height = 240; window->max_width = 400; window->max_height = 700; + window_ride_list_refresh_list(window); } _window_ride_list_information_type = INFORMATION_TYPE_STATUS; window->list_information_type = 0; @@ -298,7 +299,12 @@ static void window_ride_list_resize(rct_window *w) w->height = w->min_height; } - window_ride_list_refresh_list(w); + // Refreshing the list can be a very intensive operation + // owing to its use of ride_has_any_track_elements(). + // This makes sure it's only refreshed every 64 ticks. + if (!(gCurrentTicks & 0x3f)) { + window_ride_list_refresh_list(w); + } } /** @@ -513,7 +519,7 @@ static void window_ride_list_invalidate(rct_window *w) sint32 i; rct_ride *ride; FOR_ALL_RIDES(i, ride) { - if (w->page != gRideClassifications[ride->type] || !ride_has_any_track_elements(i)) + if (w->page != gRideClassifications[ride->type]) continue; if (ride->status == RIDE_STATUS_OPEN) { if (allOpen == -1) allOpen = true; @@ -737,7 +743,7 @@ static void window_ride_list_refresh_list(rct_window *w) countA = countB = 0; FOR_ALL_RIDES(i, ride) { - if (w->page != gRideClassifications[ride->type] || !ride_has_any_track_elements(i)) + if (w->page != gRideClassifications[ride->type] || (ride->status == RIDE_STATUS_CLOSED && !ride_has_any_track_elements(i))) continue; countA++; @@ -756,7 +762,7 @@ static void window_ride_list_refresh_list(rct_window *w) w->no_list_items = countA; sint32 list_index = 0; FOR_ALL_RIDES(i, ride) { - if (w->page != gRideClassifications[ride->type] || !ride_has_any_track_elements(i)) + if (w->page != gRideClassifications[ride->type] || (ride->status == RIDE_STATUS_CLOSED && !ride_has_any_track_elements(i))) continue; w->list_item_positions[list_index] = i; @@ -914,7 +920,7 @@ static void window_ride_list_close_all(rct_window *w) rct_ride *ride; FOR_ALL_RIDES(i, ride) { - if (w->page != gRideClassifications[ride->type] || !ride_has_any_track_elements(i)) + if (w->page != gRideClassifications[ride->type]) continue; if (ride->status == RIDE_STATUS_CLOSED) continue; @@ -933,7 +939,7 @@ static void window_ride_list_open_all(rct_window *w) rct_ride *ride; FOR_ALL_RIDES(i, ride) { - if (w->page != gRideClassifications[ride->type] || !ride_has_any_track_elements(i)) + if (w->page != gRideClassifications[ride->type]) continue; if (ride->status == RIDE_STATUS_OPEN) continue; From a94140040320fc2b713631081eb59443decb5de1 Mon Sep 17 00:00:00 2001 From: rwjuk Date: Sun, 2 Jul 2017 21:32:20 +0100 Subject: [PATCH 2/2] Refactor window_ride_list_refresh_list() to single loop --- src/openrct2/windows/ride_list.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/openrct2/windows/ride_list.c b/src/openrct2/windows/ride_list.c index 9621c3edff..ccc61a4442 100644 --- a/src/openrct2/windows/ride_list.c +++ b/src/openrct2/windows/ride_list.c @@ -737,33 +737,18 @@ static void window_ride_list_draw_tab_images(rct_drawpixelinfo *dpi, rct_window */ static void window_ride_list_refresh_list(rct_window *w) { - sint32 i, countA, countB; + sint32 i; rct_ride *ride, *otherRide; char bufferA[128], bufferB[128]; + sint32 list_index = 0; - countA = countB = 0; FOR_ALL_RIDES(i, ride) { if (w->page != gRideClassifications[ride->type] || (ride->status == RIDE_STATUS_CLOSED && !ride_has_any_track_elements(i))) continue; - countA++; if (ride->window_invalidate_flags & RIDE_INVALIDATE_RIDE_LIST) { ride->window_invalidate_flags &= ~RIDE_INVALIDATE_RIDE_LIST; - countB++; } - } - - if (countB != 0) - window_invalidate(w); - - if (countA == w->no_list_items) - return; - - w->no_list_items = countA; - sint32 list_index = 0; - FOR_ALL_RIDES(i, ride) { - if (w->page != gRideClassifications[ride->type] || (ride->status == RIDE_STATUS_CLOSED && !ride_has_any_track_elements(i))) - continue; w->list_item_positions[list_index] = i; sint32 current_list_position = list_index; @@ -910,6 +895,7 @@ static void window_ride_list_refresh_list(rct_window *w) list_index++; } + w->no_list_items = list_index; w->selected_list_item = -1; window_invalidate(w); }