diff options
author | rubidium <rubidium@openttd.org> | 2008-04-13 19:25:14 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-04-13 19:25:14 +0000 |
commit | 8ab49198b9a5285cb5676943fe66a997d2130bc3 (patch) | |
tree | 62fb23e679baa7d7fef852eba8960e2a582d1f52 /src/window.cpp | |
parent | 1fe1b5da80e4dca34141111b84cf989dcb226a79 (diff) | |
download | openttd-8ab49198b9a5285cb5676943fe66a997d2130bc3.tar.xz |
(svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
Diffstat (limited to 'src/window.cpp')
-rw-r--r-- | src/window.cpp | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/src/window.cpp b/src/window.cpp index 082f1c302..ac5ec8022 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -25,14 +25,12 @@ static Point _drag_delta; ///< delta between mouse cursor and upper left corner of dragged window static Window *_mouseover_last_w = NULL; ///< Window of the last MOUSEOVER event -static Window _windows[MAX_NUMBER_OF_WINDOWS]; - /** * List of windows opened at the screen. * Uppermost window is at _z_windows[_last_z_window - 1], * bottom window is at _z_windows[0] */ -Window *_z_windows[lengthof(_windows)]; +Window *_z_windows[MAX_NUMBER_OF_WINDOWS]; Window **_last_z_window; ///< always points to the next free space in the z-array Point _cursorpos_drag_start; @@ -433,6 +431,8 @@ void DeleteWindow(Window *w) if (wz == NULL) return; memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz); _last_z_window--; + + delete w; } /** @@ -655,28 +655,6 @@ void AssignWidgetToWindow(Window *w, const Widget *widget) } } -static Window *FindFreeWindow() -{ - Window *w; - - for (w = _windows; w < endof(_windows); w++) { - Window* const *wz; - bool window_in_use = false; - - FOR_ALL_WINDOWS(wz) { - if (*wz == w) { - window_in_use = true; - break; - } - } - - if (!window_in_use) return w; - } - - assert(_last_z_window == endof(_z_windows)); - return NULL; -} - /** Open a new window. * This function is called from AllocateWindow() or AllocateWindowDesc() * See descriptions for those functions for usage @@ -697,17 +675,18 @@ static Window *FindFreeWindow() static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height, int def_width, int def_height, WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data) { - Window *w = FindFreeWindow(); + Window *w; /* We have run out of windows, close one and use that as the place for our new one */ - if (w == NULL) { + if (_last_z_window == endof(_z_windows)) { w = FindDeletableWindow(); if (w == NULL) w = ForceFindDeletableWindow(); DeleteWindow(w); } + w = new Window; + /* Set up window properties */ - memset(w, 0, sizeof(*w)); w->window_class = cls; w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border w->caption_color = 0xFF; @@ -1057,7 +1036,6 @@ void InitWindowSystem() { IConsoleClose(); - memset(&_windows, 0, sizeof(_windows)); _last_z_window = _z_windows; InitViewports(); _no_scroll = 0; |