* Update the continuously changing contents of the windows, such as the viewports */
| 3125 | * Update the continuously changing contents of the windows, such as the viewports |
| 3126 | */ |
| 3127 | void UpdateWindows() |
| 3128 | { |
| 3129 | static auto last_time = std::chrono::steady_clock::now(); |
| 3130 | auto now = std::chrono::steady_clock::now(); |
| 3131 | auto delta_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_time); |
| 3132 | |
| 3133 | if (delta_ms.count() == 0) return; |
| 3134 | |
| 3135 | last_time = now; |
| 3136 | |
| 3137 | PerformanceMeasurer framerate(PFE_DRAWING); |
| 3138 | PerformanceAccumulator::Reset(PFE_DRAWWORLD); |
| 3139 | |
| 3140 | ProcessPendingPerformanceMeasurements(); |
| 3141 | |
| 3142 | TimerManager<TimerWindow>::Elapsed(delta_ms); |
| 3143 | CallWindowRealtimeTickEvent(delta_ms.count()); |
| 3144 | |
| 3145 | /* Process invalidations before anything else. */ |
| 3146 | for (Window *w : Window::Iterate()) { |
| 3147 | w->ProcessScheduledResize(); |
| 3148 | w->ProcessScheduledInvalidations(); |
| 3149 | w->ProcessHighlightedInvalidations(); |
| 3150 | } |
| 3151 | |
| 3152 | /* Skip the actual drawing on dedicated servers without screen. |
| 3153 | * But still empty the invalidation queues above. */ |
| 3154 | if (_network_dedicated) return; |
| 3155 | |
| 3156 | DrawDirtyBlocks(); |
| 3157 | |
| 3158 | for (Window *w : Window::Iterate()) { |
| 3159 | /* Update viewport only if window is not shaded. */ |
| 3160 | if (w->viewport != nullptr && !w->IsShaded()) UpdateViewportPosition(w, delta_ms.count()); |
| 3161 | } |
| 3162 | NetworkDrawChatMessage(); |
| 3163 | /* Redraw mouse cursor in case it was hidden */ |
| 3164 | DrawMouseCursor(); |
| 3165 | |
| 3166 | if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW) { |
| 3167 | /* We are done with the last draw-frame, so we know what sprites we |
| 3168 | * clicked on. Reset the picker mode and invalidate the window. */ |
| 3169 | _newgrf_debug_sprite_picker.mode = SPM_NONE; |
| 3170 | InvalidateWindowData(WC_SPRITE_ALIGNER, 0, 1); |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | /** |
| 3175 | * Mark window as dirty (in need of repainting) |
no test coverage detected