summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-10-07 14:30:13 +0000
committerbjarni <bjarni@openttd.org>2006-10-07 14:30:13 +0000
commit208e258f4ce57ade70145db297a9b62fba6964b3 (patch)
treeff7fa2247d12cb30d71d1ac2a8941d2af01165f8
parentdb665677992de73be63e68ffed09c60907423f98 (diff)
downloadopenttd-208e258f4ce57ade70145db297a9b62fba6964b3.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.c8
-rw-r--r--functions.h1
-rw-r--r--train_gui.c10
-rw-r--r--window.c16
-rw-r--r--window.h2
5 files changed, 33 insertions, 4 deletions
diff --git a/engine.c b/engine.c
index cb546c44e..ddaa6391d 100644
--- a/engine.c
+++ b/engine.c
@@ -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:
diff --git a/window.c b/window.c
index 12b6057c4..363808188 100644
--- a/window.c
+++ b/window.c
@@ -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);
}
}
diff --git a/window.h b/window.h
index e7a116e63..f7c85b929 100644
--- a/window.h
+++ b/window.h
@@ -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);