File diff r10232:40f71efe145b → r10233:f4b6f7cfa2ac
src/viewport.cpp
Show inline comments
 
@@ -74,67 +74,69 @@ struct TileSpriteToDraw {
 
	byte z;
 
};
 

	
 
struct ChildScreenSpriteToDraw {
 
	SpriteID image;
 
	SpriteID pal;
 
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
 
	int32 x;
 
	int32 y;
 
	int next;                       ///< next child to draw (-1 at the end)
 
};
 

	
 
/** Parent sprite that should be drawn */
 
struct ParentSpriteToDraw {
 
	SpriteID image;                 ///< sprite to draw
 
	SpriteID pal;                   ///< palette to use
 
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
 

	
 
	int32 x;                        ///< screen X coordinate of sprite
 
	int32 y;                        ///< screen Y coordinate of sprite
 

	
 
	int32 left;                     ///< minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
 
	int32 top;                      ///< minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
 

	
 
	int32 xmin;                     ///< minimal world X coordinate of bounding box
 
	int32 xmax;                     ///< maximal world X coordinate of bounding box
 
	int32 ymin;                     ///< minimal world Y coordinate of bounding box
 
	int32 ymax;                     ///< maximal world Y coordinate of bounding box
 
	int zmin;                       ///< minimal world Z coordinate of bounding box
 
	int zmax;                       ///< maximal world Z coordinate of bounding box
 

	
 
	int first_child;                ///< the first child to draw.
 
	bool comparison_done;           ///< Used during sprite sorting: true if sprite has been compared with all other sprites
 
};
 

	
 
/* Enumeration of multi-part foundations */
 
/** Enumeration of multi-part foundations */
 
enum FoundationPart {
 
	FOUNDATION_PART_NONE     = 0xFF,  ///< Neither foundation nor groundsprite drawn yet.
 
	FOUNDATION_PART_NORMAL   = 0,     ///< First part (normal foundation or no foundation)
 
	FOUNDATION_PART_HALFTILE = 1,     ///< Second part (halftile foundation)
 
	FOUNDATION_PART_END
 
};
 

	
 
typedef SmallVector<TileSpriteToDraw, 64> TileSpriteToDrawVector;
 
typedef SmallVector<StringSpriteToDraw, 4> StringSpriteToDrawVector;
 
typedef SmallVector<ParentSpriteToDraw, 64> ParentSpriteToDrawVector;
 
typedef SmallVector<ParentSpriteToDraw*, 64> ParentSpriteToSortVector;
 
typedef SmallVector<ChildScreenSpriteToDraw, 16> ChildScreenSpriteToDrawVector;
 

	
 
/** Data structure storing rendering information */
 
struct ViewportDrawer {
 
	DrawPixelInfo dpi;
 

	
 
	StringSpriteToDrawVector string_sprites_to_draw;
 
	TileSpriteToDrawVector tile_sprites_to_draw;
 
	ParentSpriteToDrawVector parent_sprites_to_draw;
 
	ParentSpriteToSortVector parent_sprites_to_sort;
 
	ParentSpriteToSortVector parent_sprites_to_sort; ///< Parent sprite pointer array used for sorting
 
	ChildScreenSpriteToDrawVector child_screen_sprites_to_draw;
 

	
 
	int *last_child;
 

	
 
	byte combine_sprites;
 

	
 
	int foundation[FOUNDATION_PART_END];             ///< Foundation sprites (index into parent_sprites_to_draw).
 
	FoundationPart foundation_part;                  ///< Currently active foundation for ground sprite drawing.
 
	int *last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw)
 
	Point foundation_offset[FOUNDATION_PART_END];    ///< Pixeloffset for ground sprites on the foundations.
 
};
 

	
 
@@ -347,24 +349,30 @@ static void SetViewportPosition(Window *
 
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
 
{
 
	ViewPort *vp = w->viewport;
 

	
 
	if (vp != NULL &&
 
			IsInsideMM(x, vp->left, vp->left + vp->width) &&
 
			IsInsideMM(y, vp->top, vp->top + vp->height))
 
		return vp;
 

	
 
	return NULL;
 
}
 

	
 
/**
 
 * Translate screen coordinate in a viewport to a tile coordinate
 
 * @param vp  Viewport that contains the (\a x, \a y) screen coordinate
 
 * @param x   Screen x coordinate
 
 * @param y   Screen y coordinate
 
 * @return Tile coordinate */
 
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
 
{
 
	Point pt;
 
	int a,b;
 
	uint z;
 

	
 
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
 
				(uint)(y -= vp->top) >= (uint)vp->height) {
 
				Point pt = {-1, -1};
 
				return pt;
 
	}
 

	
 
@@ -1277,24 +1285,25 @@ void UpdateViewportSignPos(ViewportSign 
 
}
 

	
 

	
 
static void ViewportDrawTileSprites(const TileSpriteToDrawVector *tstdv)
 
{
 
	const TileSpriteToDraw *tsend = tstdv->End();
 
	for (const TileSpriteToDraw *ts = tstdv->Begin(); ts != tsend; ++ts) {
 
		Point pt = RemapCoords(ts->x, ts->y, ts->z);
 
		DrawSprite(ts->image, ts->pal, pt.x, pt.y, ts->sub);
 
	}
 
}
 

	
 
/** Sort parent sprites pointer array */
 
static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
 
{
 
	ParentSpriteToDraw **psdvend = psdv->End();
 
	ParentSpriteToDraw **psd = psdv->Begin();
 
	while (psd != psdvend) {
 
		ParentSpriteToDraw *ps = *psd;
 

	
 
		if (ps->comparison_done) {
 
			psd++;
 
			continue;
 
		}