(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.
--- a/src/core/alloc_type.hpp Thu Apr 17 06:53:52 2008 +0000
+++ b/src/core/alloc_type.hpp Thu Apr 17 09:42:44 2008 +0000
@@ -88,6 +88,9 @@
* 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 @@
* 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); }
};
--- a/src/viewport.cpp Thu Apr 17 06:53:52 2008 +0000
+++ b/src/viewport.cpp Thu Apr 17 09:42:44 2008 +0000
@@ -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 @@
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 @@
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 AssignWindowViewport(Window *w, int x, int y,
int width, int height, uint32 follow_flags, ZoomLevel zoom)
{
- ViewPort *vp;
- Point pt;
- uint32 bit;
-
- for (vp = _viewports, bit = 0; ; vp++, bit++) {
- assert(vp != endof(_viewports));
- if (vp->width == 0) break;
- }
- SetBit(_active_viewports, bit);
+ assert(w->viewport == NULL);
+
+ ViewPort *vp = &(WP(w, vp_d).vp_data);
vp->left = x + w->left;
vp->top = y + w->top;
@@ -204,6 +174,8 @@
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 @@
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)
--- a/src/viewport_func.h Thu Apr 17 06:53:52 2008 +0000
+++ b/src/viewport_func.h Thu Apr 17 09:42:44 2008 +0000
@@ -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);
--- a/src/window.cpp Thu Apr 17 06:53:52 2008 +0000
+++ b/src/window.cpp Thu Apr 17 09:42:44 2008 +0000
@@ -1037,7 +1037,6 @@
IConsoleClose();
_last_z_window = _z_windows;
- InitViewports();
_no_scroll = 0;
}
--- a/src/window_gui.h Thu Apr 17 06:53:52 2008 +0000
+++ b/src/window_gui.h Thu Apr 17 09:42:44 2008 +0000
@@ -409,6 +409,7 @@
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));