diff options
author | bjarni <bjarni@openttd.org> | 2006-10-07 14:30:13 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2006-10-07 14:30:13 +0000 |
commit | bc1070654a4187273e38fcce5361e5606f33b1d9 (patch) | |
tree | ff7fa2247d12cb30d71d1ac2a8941d2af01165f8 | |
parent | e1ad1102f2692ff4d03986f25f6880b69b6b82ec (diff) | |
download | openttd-bc1070654a4187273e38fcce5361e5606f33b1d9.tar.xz |
(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
-rw-r--r-- | engine.c | 8 | ||||
-rw-r--r-- | functions.h | 1 | ||||
-rw-r--r-- | train_gui.c | 10 | ||||
-rw-r--r-- | window.c | 16 | ||||
-rw-r--r-- | window.h | 2 |
5 files changed, 33 insertions, 4 deletions
@@ -209,8 +209,11 @@ static void AcceptEnginePreview(Engine *e, PlayerID player) 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 @@ static void NewVehicleAvailable(Engine *e) } e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE; + InvalidateWindowClassesData(WC_BUILD_VEHICLE); InvalidateWindowClasses(WC_BUILD_VEHICLE); InvalidateWindowClasses(WC_REPLACE_VEHICLE); diff --git a/functions.h b/functions.h index 352f7b962..f79e20cd8 100644 --- a/functions.h +++ b/functions.h @@ -168,6 +168,7 @@ void MarkTileDirtyByTile(TileIndex tile); 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 --git a/train_gui.c b/train_gui.c index f290df9ed..d679288dd 100644 --- a/train_gui.c +++ b/train_gui.c @@ -273,7 +273,10 @@ static void DrawTrainBuildWindow(Window *w) 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 @@ static void NewRailVehicleWndProc(Window *w, WindowEvent *e) 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: @@ -1609,12 +1609,26 @@ void InvalidateWindowClasses(WindowClass cls) } } +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); } } @@ -394,6 +394,7 @@ typedef struct { byte railtype; byte sel_index; byte show_engine_wagon; + bool data_invalidated; EngineID sel_engine; EngineID rename_engine; EngineID *engines; @@ -789,6 +790,7 @@ int GetMenuItemIndex(const Window *w, int x, int y); 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); |