# HG changeset patch # User bjarni # Date 1160231413 0 # Node ID aa276d0ec2ebf36d1560d29357c7a9b292f33dfd # Parent d109bfb2cc73ea1226cf41fabfbf6a0f15329cff (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw diff -r d109bfb2cc73 -r aa276d0ec2eb engine.c --- a/engine.c Sat Oct 07 13:58:08 2006 +0000 +++ b/engine.c Sat Oct 07 14:30:13 2006 +0000 @@ -209,8 +209,11 @@ SETBIT(p->avail_railtypes, e->railtype); e->preview_player = 0xFF; - InvalidateWindowClasses(WC_BUILD_VEHICLE); - InvalidateWindowClasses(WC_REPLACE_VEHICLE); + if (player == _local_player) { + InvalidateWindowClassesData(WC_BUILD_VEHICLE); + InvalidateWindowClasses(WC_BUILD_VEHICLE); + InvalidateWindowClasses(WC_REPLACE_VEHICLE); + } } static PlayerID GetBestPlayer(PlayerID pp) @@ -332,6 +335,7 @@ } e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE; + InvalidateWindowClassesData(WC_BUILD_VEHICLE); InvalidateWindowClasses(WC_BUILD_VEHICLE); InvalidateWindowClasses(WC_REPLACE_VEHICLE); diff -r d109bfb2cc73 -r aa276d0ec2eb functions.h --- a/functions.h Sat Oct 07 13:58:08 2006 +0000 +++ b/functions.h Sat Oct 07 14:30:13 2006 +0000 @@ -168,6 +168,7 @@ void InvalidateWindow(WindowClass cls, WindowNumber number); void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index); void InvalidateWindowClasses(WindowClass cls); +void InvalidateWindowClassesData(WindowClass cls); void DeleteWindowById(WindowClass cls, WindowNumber number); void DeleteWindowByClass(WindowClass cls); diff -r d109bfb2cc73 -r aa276d0ec2eb train_gui.c --- a/train_gui.c Sat Oct 07 13:58:08 2006 +0000 +++ b/train_gui.c Sat Oct 07 14:30:13 2006 +0000 @@ -273,7 +273,10 @@ SetWindowWidgetLoweredState(w, BUILD_TRAIN_WIDGET_WAGONS, WP(w,buildtrain_d).show_engine_wagon == 2); SetWindowWidgetLoweredState(w, BUILD_TRAIN_WIDGET_BOTH, WP(w,buildtrain_d).show_engine_wagon == 3); - GenerateBuildList(&WP(w,buildtrain_d).engines, &WP(w,buildtrain_d).num_engines, &WP(w,buildtrain_d).wagons, &WP(w,buildtrain_d).num_wagons, WP(w,buildtrain_d).railtype); + if (WP(w,buildtrain_d).data_invalidated) { + GenerateBuildList(&WP(w,buildtrain_d).engines, &WP(w,buildtrain_d).num_engines, &WP(w,buildtrain_d).wagons, &WP(w,buildtrain_d).num_wagons, WP(w,buildtrain_d).railtype); + WP(w,buildtrain_d).data_invalidated = false; + } if (HASBIT(WP(w,buildtrain_d).show_engine_wagon, 0)) scrollcount += WP(w,buildtrain_d).num_engines; if (HASBIT(WP(w,buildtrain_d).show_engine_wagon, 1)) scrollcount += WP(w,buildtrain_d).num_wagons; @@ -326,6 +329,11 @@ WP(w,buildtrain_d).engines = NULL; WP(w,buildtrain_d).wagons = NULL; WP(w,buildtrain_d).show_engine_wagon = 3; + WP(w,buildtrain_d).data_invalidated = true; + break; + + case WE_INVALIDATE_DATA: + WP(w,buildtrain_d).data_invalidated = true; break; case WE_DESTROY: diff -r d109bfb2cc73 -r aa276d0ec2eb window.c --- a/window.c Sat Oct 07 13:58:08 2006 +0000 +++ b/window.c Sat Oct 07 14:30:13 2006 +0000 @@ -1609,12 +1609,26 @@ } } +void InvalidateThisWindowData(Window *w) +{ + CallWindowEventNP(w, WE_INVALIDATE_DATA); +} + void InvalidateWindowData(WindowClass cls, WindowNumber number) { Window *w; for (w = _windows; w != _last_window; w++) { - if (w->window_class == cls && w->window_number == number) CallWindowEventNP(w, WE_INVALIDATE_DATA); + if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w); + } +} + +void InvalidateWindowClassesData(WindowClass cls) +{ + Window *w; + + for (w = _windows; w != _last_window; w++) { + if (w->window_class == cls) InvalidateThisWindowData(w); } } diff -r d109bfb2cc73 -r aa276d0ec2eb window.h --- a/window.h Sat Oct 07 13:58:08 2006 +0000 +++ b/window.h Sat Oct 07 14:30:13 2006 +0000 @@ -394,6 +394,7 @@ byte railtype; byte sel_index; byte show_engine_wagon; + bool data_invalidated; EngineID sel_engine; EngineID rename_engine; EngineID *engines; @@ -789,6 +790,7 @@ void InputLoop(void); void UpdateWindows(void); void InvalidateWidget(const Window *w, byte widget_index); +void InvalidateThisWindowData(Window *w); void InvalidateWindowData(WindowClass cls, WindowNumber number); void RaiseWindowButtons(Window *w); void RelocateAllWindows(int neww, int newh);