diff options
author | rubidium <rubidium@openttd.org> | 2008-04-17 09:42:44 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-04-17 09:42:44 +0000 |
commit | c31287206dd2037ba83377d09d529d14c56a6291 (patch) | |
tree | f0e8b714d0affba2b46fcd6f85a72b4653e031e2 | |
parent | 0cd14f9ebb535ff4b30d14cb816de608fd21a40e (diff) | |
download | openttd-c31287206dd2037ba83377d09d529d14c56a6291.tar.xz |
(svn r12749) -Codechange: store the viewport information in the windows that have a viewport instead of one global array with a viewport for each window, even when they do not use the viewport.
-rw-r--r-- | src/core/alloc_type.hpp | 6 | ||||
-rw-r--r-- | src/viewport.cpp | 81 | ||||
-rw-r--r-- | src/viewport_func.h | 1 | ||||
-rw-r--r-- | src/window.cpp | 1 | ||||
-rw-r--r-- | src/window_gui.h | 1 |
5 files changed, 34 insertions, 56 deletions
diff --git a/src/core/alloc_type.hpp b/src/core/alloc_type.hpp index 4146e5ca3..872558fb3 100644 --- a/src/core/alloc_type.hpp +++ b/src/core/alloc_type.hpp @@ -88,6 +88,9 @@ public: * Memory release for a single class instance. * @param ptr the memory to free. * @param size the amount of allocated memory (unused). + * + * @warning The value of the \a size parameter can only be trusted for + * classes that have their own (virtual) destructor method. */ void operator delete(void *ptr, size_t size) { free(ptr); } @@ -95,6 +98,9 @@ public: * Memory release for an array of class instances. * @param ptr the memory to free. * @param size the amount of allocated memory (unused). + * + * @warning The value of the \a size parameter can only be trusted for + * classes that have their own (virtual) destructor method. */ void operator delete[](void *ptr, size_t size) { free(ptr); } }; diff --git a/src/viewport.cpp b/src/viewport.cpp index f53a1daa8..84378a617 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1,6 +1,22 @@ /* $Id$ */ -/** @file viewport.cpp */ +/** @file viewport.cpp + * + * \verbatim + * The in-game coordinate system looks like this * + * * + * ^ Z * + * | * + * | * + * | * + * | * + * / \ * + * / \ * + * / \ * + * / \ * + * X < > Y * + * \endverbatim + */ #include "stdafx.h" #include "openttd.h" @@ -37,39 +53,6 @@ PlaceProc *_place_proc; Point _tile_fract_coords; ZoomLevel _saved_scrollpos_zoom; -/** - * The maximum number of viewports depends on the maximum number - * of windows. Technically is could be the maximum number of - * windows, but there is always at least one window that does - * not need a viewport. Not having 'support' for that viewport - * saves some time and memory. - * For the introduction GUI and create game GUIs there is no - * need for more than one viewport, however in the normal game - * and scenario editor one can make a lot of viewports. For the - * normal game one always has a main toolbar and a status bar, - * however the statusbar does not exist on the scenario editor. - * - * This means that we can only safely assume that there is one - * window without viewport. - */ -static ViewPort _viewports[MAX_NUMBER_OF_WINDOWS - 1]; -static uint32 _active_viewports; ///< bitmasked variable where each bit signifies if a viewport is in use or not -assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8); - -/* The in-game coordiante system looks like this * - * * - * ^ Z * - * | * - * | * - * | * - * | * - * / \ * - * / \ * - * / \ * - * / \ * - * X < > Y * - */ - struct StringSpriteToDraw { uint16 string; uint16 color; @@ -168,15 +151,8 @@ static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z) return p; } -void InitViewports() -{ - memset(_viewports, 0, sizeof(_viewports)); - _active_viewports = 0; -} - void DeleteWindowViewport(Window *w) { - ClrBit(_active_viewports, w->viewport - _viewports); w->viewport->width = 0; w->viewport = NULL; } @@ -184,15 +160,9 @@ void DeleteWindowViewport(Window *w) void AssignWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom) { - ViewPort *vp; - Point pt; - uint32 bit; + assert(w->viewport == NULL); - for (vp = _viewports, bit = 0; ; vp++, bit++) { - assert(vp != endof(_viewports)); - if (vp->width == 0) break; - } - SetBit(_active_viewports, bit); + ViewPort *vp = &(WP(w, vp_d).vp_data); vp->left = x + w->left; vp->top = y + w->top; @@ -204,6 +174,8 @@ void AssignWindowViewport(Window *w, int x, int y, vp->virtual_width = ScaleByZoom(width, zoom); vp->virtual_height = ScaleByZoom(height, zoom); + Point pt; + if (follow_flags & 0x80000000) { const Vehicle *veh; @@ -1651,14 +1623,15 @@ static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, void MarkAllViewportsDirty(int left, int top, int right, int bottom) { - const ViewPort *vp = _viewports; - uint32 act = _active_viewports; - do { - if (act & 1) { + Window **wz; + + FOR_ALL_WINDOWS(wz) { + ViewPort *vp = (*wz)->viewport; + if (vp != NULL) { assert(vp->width != 0); MarkViewportDirty(vp, left, top, right, bottom); } - } while (vp++,act>>=1); + } } void MarkTileDirtyByTile(TileIndex tile) diff --git a/src/viewport_func.h b/src/viewport_func.h index 156ffaa79..a9d491b45 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -12,7 +12,6 @@ void SetSelectionRed(bool); -void InitViewports(); void DeleteWindowViewport(Window *w); void AssignWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom); ViewPort *IsPtInWindowViewport(const Window *w, int x, int y); diff --git a/src/window.cpp b/src/window.cpp index 976155644..94b006434 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1037,7 +1037,6 @@ void InitWindowSystem() IConsoleClose(); _last_z_window = _z_windows; - InitViewports(); _no_scroll = 0; } diff --git a/src/window_gui.h b/src/window_gui.h index 665bcde22..c8aa57ce3 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -409,6 +409,7 @@ struct vp_d { int32 scrollpos_y; int32 dest_scrollpos_x; int32 dest_scrollpos_y; + ViewPort vp_data; ///< Screen position and zoom of the viewport }; assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vp_d)); |