From 52e4688851dc55b9209b249a7e4dc4b45bcc4b62 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 18 Sep 2023 18:34:50 +0100 Subject: [PATCH] Use Window iterate instead of from front/back when no order required --- src/gfx.cpp | 4 ++-- src/openttd.cpp | 2 +- src/schdispatch_gui.cpp | 2 +- src/smallmap_gui.cpp | 2 +- src/timetable_gui.cpp | 2 +- src/vehicle_gui.cpp | 2 +- src/viewport.cpp | 10 +++++----- src/window.cpp | 22 +++++++++++----------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index e8d2ee94f7..f4abd29f67 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1717,7 +1717,7 @@ void DrawDirtyBlocks() if (_whole_screen_dirty) { RedrawScreenRect(0, 0, _screen.width, _screen.height); - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { w->flags &= ~(WF_DIRTY | WF_WIDGETS_DIRTY | WF_DRAG_DIRTIED); } _whole_screen_dirty = false; @@ -2354,7 +2354,7 @@ bool AdjustGUIZoom(AdjustGUIZoomMode mode) /* Adjust all window sizes to match the new zoom level, so that they don't appear to move around when the application is moved to a screen with different DPI. */ auto zoom_shift = old_gui_zoom - _gui_zoom; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (mode == AGZM_AUTOMATIC) { w->left = (w->left * _gui_scale) / old_scale; w->top = (w->top * _gui_scale) / old_scale; diff --git a/src/openttd.cpp b/src/openttd.cpp index 210e40dabe..ad0ab8f3e9 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -527,7 +527,7 @@ static void ShutdownGame() static void LoadIntroGame(bool load_newgrfs = true) { UnshowCriticalError(); - for (Window *w : Window::IterateFromFront()) { + for (Window *w : Window::Iterate()) { w->Close(); } diff --git a/src/schdispatch_gui.cpp b/src/schdispatch_gui.cpp index 5fd35196ff..ea6ddd4333 100644 --- a/src/schdispatch_gui.cpp +++ b/src/schdispatch_gui.cpp @@ -1251,7 +1251,7 @@ void ShowScheduledDispatchAddSlotsWindow(SchdispatchWindow *parent, int window_n void SchdispatchInvalidateWindows(const Vehicle *v) { v = v->FirstShared(); - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == WC_VEHICLE_TIMETABLE) { if (static_cast(w)->vehicle->FirstShared() == v) w->SetDirty(); } diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index c3e235f536..6e31ef978d 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -168,7 +168,7 @@ uint _company_to_list_pos[MAX_COMPANIES]; static void NotifyAllViewports(ViewportMapType map_type) { - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->viewport != nullptr) { if (w->viewport->zoom >= ZOOM_LVL_DRAW_MAP && w->viewport->map_type == map_type) { ClearViewportLandPixelCache(w->viewport); diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 71a6abfd24..a4e0b3ce07 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -1257,7 +1257,7 @@ void ShowTimetableWindow(const Vehicle *v) void SetTimetableWindowsDirty(const Vehicle *v, SetTimetableWindowsDirtyFlags flags) { v = v->FirstShared(); - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == WC_VEHICLE_TIMETABLE || ((flags & STWDF_SCHEDULED_DISPATCH) && w->window_class == WC_SCHDISPATCH_SLOTS) || ((flags & STWDF_ORDERS) && w->window_class == WC_VEHICLE_ORDERS)) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 0e16179fa5..7f908403d4 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2751,7 +2751,7 @@ void DirtyVehicleListWindowForVehicle(const Vehicle *v) { WindowClass cls = static_cast(WC_TRAINS_LIST + v->type); WindowClass cls2 = (v->type == VEH_TRAIN) ? WC_TRACE_RESTRICT_SLOTS : cls; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == cls || w->window_class == cls2) { BaseVehicleListWindow *listwin = static_cast(w); uint max = std::min(listwin->vscroll->GetPosition() + listwin->vscroll->GetCapacity(), (uint)listwin->vehgroups.size()); diff --git a/src/viewport.cpp b/src/viewport.cpp index 180419f0e8..71da7d4a1d 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -4266,7 +4266,7 @@ void ViewportRouteOverlay::MarkAllRouteStepsDirty(const Vehicle *veh) */ void MarkAllViewportMapsDirty(int left, int top, int right, int bottom) { - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { Viewport *vp = w->viewport; if (vp != nullptr && vp->zoom >= ZOOM_LVL_DRAW_MAP) { MarkViewportDirty(vp, left, top, right, bottom, VMDF_NOT_LANDSCAPE); @@ -4276,7 +4276,7 @@ void MarkAllViewportMapsDirty(int left, int top, int right, int bottom) void MarkAllViewportMapLandscapesDirty() { - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { Viewport *vp = w->viewport; if (vp != nullptr && vp->zoom >= ZOOM_LVL_DRAW_MAP) { ClearViewportLandPixelCache(vp); @@ -4287,7 +4287,7 @@ void MarkAllViewportMapLandscapesDirty() void MarkWholeNonMapViewportsDirty() { - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { Viewport *vp = w->viewport; if (vp != nullptr && vp->zoom < ZOOM_LVL_DRAW_MAP) { w->SetDirty(); @@ -4302,7 +4302,7 @@ void MarkWholeNonMapViewportsDirty() */ void MarkAllViewportOverlayStationLinksDirty(const Station *st) { - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { Viewport *vp = w->viewport; if (vp != nullptr && vp->overlay != nullptr) { vp->overlay->MarkStationViewportLinksDirty(st); @@ -4312,7 +4312,7 @@ void MarkAllViewportOverlayStationLinksDirty(const Station *st) void ConstrainAllViewportsZoom() { - for (Window *w : Window::IterateFromFront()) { + for (Window *w : Window::Iterate()) { if (w->viewport == nullptr) continue; ZoomLevel zoom = static_cast(Clamp(w->viewport->zoom, _settings_client.gui.zoom_min, _settings_client.gui.zoom_max)); diff --git a/src/window.cpp b/src/window.cpp index 53d35a552c..2845c18348 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -3289,7 +3289,7 @@ void InputLoop() */ void CallWindowRealtimeTickEvent(uint delta_ms) { - for (Window *w : Window::IterateFromFront()) { + for (Window *w : Window::Iterate()) { w->OnRealtimeTick(delta_ms); } } @@ -3322,7 +3322,7 @@ void UpdateWindows() _window_update_number++; /* Process invalidations before anything else. */ - for (Window *w : Window::IterateFromFront()) { + for (Window *w : Window::Iterate()) { w->ProcessScheduledInvalidations(); w->ProcessHighlightedInvalidations(); } @@ -3355,7 +3355,7 @@ void UpdateWindows() if (window_timer.HasElapsed()) { window_timer.SetInterval(MILLISECONDS_PER_TICK); - for (Window *w : Window::IterateFromFront()) { + for (Window *w : Window::Iterate()) { if ((w->flags & WF_WHITE_BORDER) && --w->white_border_timer == 0) { CLRBITS(w->flags, WF_WHITE_BORDER); w->SetDirty(); @@ -3365,7 +3365,7 @@ void UpdateWindows() DrawDirtyBlocks(); - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { /* Update viewport only if window is not shaded. */ if (w->viewport != nullptr && !w->IsShaded()) UpdateViewportPosition(w); } @@ -3386,7 +3386,7 @@ void SetWindowDirty(WindowClass cls, WindowNumber number) { if (cls < WC_END && !_present_window_types[cls]) return; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == cls && w->window_number == number) w->SetDirty(); } } @@ -3401,7 +3401,7 @@ void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_inde { if (cls < WC_END && !_present_window_types[cls]) return; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == cls && w->window_number == number) { w->SetWidgetDirty(widget_index); } @@ -3416,7 +3416,7 @@ void SetWindowClassesDirty(WindowClass cls) { if (cls < WC_END && !_present_window_types[cls]) return; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == cls) w->SetDirty(); } } @@ -3492,7 +3492,7 @@ void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool g { if (cls < WC_END && !_present_window_types[cls]) return; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == cls && w->window_number == number) { w->InvalidateData(data, gui_scope); } @@ -3511,7 +3511,7 @@ void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope) { if (cls < WC_END && !_present_window_types[cls]) return; - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->window_class == cls) { w->InvalidateData(data, gui_scope); } @@ -3523,7 +3523,7 @@ void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope) */ void CallWindowGameTickEvent() { - for (Window *w : Window::IterateFromFront()) { + for (Window *w : Window::Iterate()) { w->OnGameTick(); } } @@ -3723,7 +3723,7 @@ int PositionNetworkChatWindow(Window *w) */ void ChangeVehicleViewports(VehicleID from_index, VehicleID to_index) { - for (Window *w : Window::IterateFromBack()) { + for (Window *w : Window::Iterate()) { if (w->viewport != nullptr && w->viewport->follow_vehicle == from_index) { w->viewport->follow_vehicle = to_index; w->SetDirty();