(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.

This commit is contained in:
rubidium 2008-04-17 09:42:44 +00:00
parent 0cd14f9ebb
commit c31287206d
5 changed files with 34 additions and 56 deletions

View File

@ -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); }
};

View File

@ -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)

View File

@ -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);

View File

@ -1037,7 +1037,6 @@ void InitWindowSystem()
IConsoleClose();
_last_z_window = _z_windows;
InitViewports();
_no_scroll = 0;
}

View File

@ -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));