summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-11-18 00:44:09 +0000
committerDarkvater <darkvater@openttd.org>2006-11-18 00:44:09 +0000
commit583c9e531b997400cedc1eb2f524785a4294a874 (patch)
treebac5c95b27ebac6a4aa144483b16d23bf0ffa5f1 /window.c
parentc4d841dcdbabb1f600dce2f5c150e66fdc432f77 (diff)
downloadopenttd-583c9e531b997400cedc1eb2f524785a4294a874.tar.xz
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Diffstat (limited to 'window.c')
-rw-r--r--window.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/window.c b/window.c
index ec3589951..47fde1a57 100644
--- a/window.c
+++ b/window.c
@@ -337,12 +337,13 @@ void DeleteWindowByClass(WindowClass cls)
{
Window *w;
- for (w = _windows; w != _last_window;) {
+restart_search:
+ /* When we find the window to delete, we need to restart the search
+ * as deleting this window could cascade in deleting (many) others */
+ for (w = _windows; w != _last_window; w++) {
if (w->window_class == cls) {
DeleteWindow(w);
- w = _windows;
- } else {
- w++;
+ goto restart_search;
}
}
}
@@ -355,12 +356,13 @@ void DeletePlayerWindows(PlayerID id)
{
Window *w;
- for (w = _windows; w != _last_window;) {
+restart_search:
+ /* When we find the window to delete, we need to restart the search
+ * as deleting this window could cascade in deleting (many) others */
+ for (w = _windows; w != _last_window; w++) {
if (w->caption_color == id) {
DeleteWindow(w);
- w = _windows;
- } else {
- w++;
+ goto restart_search;
}
}
@@ -1756,7 +1758,10 @@ void DeleteNonVitalWindows(void)
{
Window *w;
- for (w = _windows; w != _last_window;) {
+restart_search:
+ /* When we find the window to delete, we need to restart the search
+ * as deleting this window could cascade in deleting (many) others */
+ for (w = _windows; w != _last_window; w++) {
if (w->window_class != WC_MAIN_WINDOW &&
w->window_class != WC_SELECT_GAME &&
w->window_class != WC_MAIN_TOOLBAR &&
@@ -1765,9 +1770,7 @@ void DeleteNonVitalWindows(void)
w->window_class != WC_TOOLTIPS &&
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
DeleteWindow(w);
- w = _windows;
- } else {
- w++;
+ goto restart_search;
}
}
}
@@ -1781,15 +1784,15 @@ void DeleteAllNonVitalWindows(void)
{
Window *w;
- // Delete every window except for stickied ones
+ /* Delete every window except for stickied ones, then sticky ones as well */
DeleteNonVitalWindows();
- // Delete all sticked windows
- for (w = _windows; w != _last_window;) {
+restart_search:
+ /* When we find the window to delete, we need to restart the search
+ * as deleting this window could cascade in deleting (many) others */
+ for (w = _windows; w != _last_window; w++) {
if (w->flags4 & WF_STICKY) {
DeleteWindow(w);
- w = _windows;
- } else {
- w++;
+ goto restart_search;
}
}
}