Changeset - r17354:4fbd86e6412f
[Not reviewed]
master
0 2 0
frosch - 14 years ago 2011-02-19 14:57:15
frosch@openttd.org
(svn r22110) -Codechange: Remove WaterDrawTileStruct and use DrawTileSprites/DrawTileSeqStruct instead.
2 files changed with 110 insertions and 123 deletions:
0 comments (0 inline, 0 general)
src/table/water_land.h
Show inline comments
 
@@ -6,157 +6,149 @@
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file water_land.h Sprites to use and how to display them for water tiles (depots/locks). */
 

	
 
struct WaterDrawTileStruct {
 
	byte delta_x;
 
	byte delta_y;
 
	byte delta_z;
 
	byte size_x;
 
	byte size_y;
 
	byte size_z;
 
	SpriteID image;
 
};
 
/**
 
 * Constructor macro for an image without a palette in a DrawTileSeqStruct array.
 
 * @param dx  Offset in x direction
 
 * @param dy  Offset in y direction
 
 * @param dz  Offset in z direction
 
 * @param sx  Size in x direction
 
 * @param sy  Size in y direction
 
 * @param sz  Size in z direction
 
 * @param img Sprite to draw
 
 */
 
#define TILE_SEQ_LINE(dx, dy, dz, sx, sy, sz, img) { dx, dy, dz, sx, sy, sz, {img, PAL_NONE} },
 

	
 
#define BEGIN(image) { 0, 0, 0, 0, 0, 0, image }
 
/** Constructor macro for a terminating DrawTileSeqStruct entry in an array */
 
#define TILE_SEQ_END() { (int8)0x80, 0, 0, 0, 0, 0, {0, 0} }
 

	
 
/** Constructor macro for a terminating WaterDrawTileStruct entry in an array */
 
#define TILE_SEQ_END() { 0x80, 0, 0, 0, 0, 0, 0 }
 
/**
 
 * Constructor macro of a DrawTileSprites structure
 
 * @param img   Ground sprite without palette of the tile
 
 * @param dtss  Sequence child sprites of the tile
 
 */
 
#define TILE_SPRITE_LINE(img, dtss) { {img, PAL_NONE}, dtss },
 

	
 
static const WaterDrawTileStruct _shipdepot_display_seq_1[] = {
 
	BEGIN(0xFDD),
 
	{ 0, 15, 0, 16, 1, 0x14, 0xFE8 | (1 << PALETTE_MODIFIER_COLOUR) },
 
static const DrawTileSeqStruct _shipdepot_display_seq_1[] = {
 
	TILE_SEQ_LINE( 0, 15, 0, 16, 1, 0x14, 0xFE8 | (1 << PALETTE_MODIFIER_COLOUR))
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _shipdepot_display_seq_2[] = {
 
	BEGIN(0xFDD),
 
	{ 0,  0, 0, 16, 1, 0x14, 0xFEA },
 
	{ 0, 15, 0, 16, 1, 0x14, 0xFE6 | (1 << PALETTE_MODIFIER_COLOUR) },
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _shipdepot_display_seq_3[] = {
 
	BEGIN(0xFDD),
 
	{ 15, 0, 0, 1, 0x10, 0x14, 0xFE9 | (1 << PALETTE_MODIFIER_COLOUR) },
 
static const DrawTileSeqStruct _shipdepot_display_seq_2[] = {
 
	TILE_SEQ_LINE( 0,  0, 0, 16, 1, 0x14, 0xFEA)
 
	TILE_SEQ_LINE( 0, 15, 0, 16, 1, 0x14, 0xFE6 | (1 << PALETTE_MODIFIER_COLOUR))
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _shipdepot_display_seq_4[] = {
 
	BEGIN(0xFDD),
 
	{  0, 0, 0, 1, 16, 0x14, 0xFEB },
 
	{ 15, 0, 0, 1, 16, 0x14, 0xFE7 | (1 << PALETTE_MODIFIER_COLOUR) },
 
static const DrawTileSeqStruct _shipdepot_display_seq_3[] = {
 
	TILE_SEQ_LINE( 15, 0, 0, 1, 0x10, 0x14, 0xFE9 | (1 << PALETTE_MODIFIER_COLOUR))
 
	TILE_SEQ_END()
 
};
 

	
 
static const DrawTileSeqStruct _shipdepot_display_seq_4[] = {
 
	TILE_SEQ_LINE(  0, 0, 0, 1, 16, 0x14, 0xFEB)
 
	TILE_SEQ_LINE( 15, 0, 0, 1, 16, 0x14, 0xFE7 | (1 << PALETTE_MODIFIER_COLOUR))
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct * const _shipdepot_display_seq[] = {
 
	_shipdepot_display_seq_1,
 
	_shipdepot_display_seq_2,
 
	_shipdepot_display_seq_3,
 
	_shipdepot_display_seq_4,
 
static const DrawTileSprites _shipdepot_display_data[] = {
 
	TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_1)
 
	TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_2)
 
	TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_3)
 
	TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_4)
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_0[] = {
 
	BEGIN(1),
 
	{ 0,   0, 0, 0x10, 1, 0x14, 0 + 1 },
 
	{ 0, 0xF, 0, 0x10, 1, 0x14, 4 + 1 },
 
static const DrawTileSeqStruct _lock_display_seq_0[] = {
 
	TILE_SEQ_LINE( 0,   0, 0, 0x10, 1, 0x14, 0 + 1)
 
	TILE_SEQ_LINE( 0, 0xF, 0, 0x10, 1, 0x14, 4 + 1)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_1[] = {
 
	BEGIN(0),
 
	{   0, 0, 0, 1, 0x10, 0x14, 0 },
 
	{ 0xF, 0, 0, 1, 0x10, 0x14, 4 },
 
static const DrawTileSeqStruct _lock_display_seq_1[] = {
 
	TILE_SEQ_LINE(   0, 0, 0, 1, 0x10, 0x14, 0)
 
	TILE_SEQ_LINE( 0xF, 0, 0, 1, 0x10, 0x14, 4)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_2[] = {
 
	BEGIN(2),
 
	{ 0,   0, 0, 0x10, 1, 0x14, 0 + 2 },
 
	{ 0, 0xF, 0, 0x10, 1, 0x14, 4 + 2 },
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_3[] = {
 
	BEGIN(3),
 
	{   0, 0, 0, 1, 0x10, 0x14, 0 + 3 },
 
	{ 0xF, 0, 0, 1, 0x10, 0x14, 4 + 3 },
 
static const DrawTileSeqStruct _lock_display_seq_2[] = {
 
	TILE_SEQ_LINE( 0,   0, 0, 0x10, 1, 0x14, 0 + 2)
 
	TILE_SEQ_LINE( 0, 0xF, 0, 0x10, 1, 0x14, 4 + 2)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_0b[] = {
 
	BEGIN(0xFDD),
 
	{ 0,   0, 0, 0x10, 1, 0x14, 8 + 1 },
 
	{ 0, 0xF, 0, 0x10, 1, 0x14, 12 + 1 },
 
static const DrawTileSeqStruct _lock_display_seq_3[] = {
 
	TILE_SEQ_LINE(   0, 0, 0, 1, 0x10, 0x14, 0 + 3)
 
	TILE_SEQ_LINE( 0xF, 0, 0, 1, 0x10, 0x14, 4 + 3)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_1b[] = {
 
	BEGIN(0xFDD),
 
	{   0, 0, 0, 0x1, 0x10, 0x14, 8 },
 
	{ 0xF, 0, 0, 0x1, 0x10, 0x14, 12 },
 
static const DrawTileSeqStruct _lock_display_seq_0b[] = {
 
	TILE_SEQ_LINE( 0,   0, 0, 0x10, 1, 0x14, 8 + 1)
 
	TILE_SEQ_LINE( 0, 0xF, 0, 0x10, 1, 0x14, 12 + 1)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_2b[] = {
 
	BEGIN(0xFDD),
 
	{ 0,   0, 0, 0x10, 1, 0x14, 8 + 2 },
 
	{ 0, 0xF, 0, 0x10, 1, 0x14, 12 + 2 },
 
static const DrawTileSeqStruct _lock_display_seq_1b[] = {
 
	TILE_SEQ_LINE(   0, 0, 0, 0x1, 0x10, 0x14, 8)
 
	TILE_SEQ_LINE( 0xF, 0, 0, 0x1, 0x10, 0x14, 12)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_3b[] = {
 
	BEGIN(0xFDD),
 
	{   0, 0, 0, 1, 0x10, 0x14, 8 + 3 },
 
	{ 0xF, 0, 0, 1, 0x10, 0x14, 12 + 3 },
 
static const DrawTileSeqStruct _lock_display_seq_2b[] = {
 
	TILE_SEQ_LINE( 0,   0, 0, 0x10, 1, 0x14, 8 + 2)
 
	TILE_SEQ_LINE( 0, 0xF, 0, 0x10, 1, 0x14, 12 + 2)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_0t[] = {
 
	BEGIN(0xFDD),
 
	{ 0,   0, 0, 0x10, 1, 0x14, 16 + 1 },
 
	{ 0, 0xF, 0, 0x10, 1, 0x14, 20 + 1 },
 
static const DrawTileSeqStruct _lock_display_seq_3b[] = {
 
	TILE_SEQ_LINE(   0, 0, 0, 1, 0x10, 0x14, 8 + 3)
 
	TILE_SEQ_LINE( 0xF, 0, 0, 1, 0x10, 0x14, 12 + 3)
 
	TILE_SEQ_END()
 
};
 

	
 
static const DrawTileSeqStruct _lock_display_seq_0t[] = {
 
	TILE_SEQ_LINE( 0,   0, 0, 0x10, 1, 0x14, 16 + 1)
 
	TILE_SEQ_LINE( 0, 0xF, 0, 0x10, 1, 0x14, 20 + 1)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_1t[] = {
 
	BEGIN(0xFDD),
 
	{   0, 0, 0, 0x1, 0x10, 0x14, 16 },
 
	{ 0xF, 0, 0, 0x1, 0x10, 0x14, 20 },
 
static const DrawTileSeqStruct _lock_display_seq_1t[] = {
 
	TILE_SEQ_LINE(   0, 0, 0, 0x1, 0x10, 0x14, 16)
 
	TILE_SEQ_LINE( 0xF, 0, 0, 0x1, 0x10, 0x14, 20)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_2t[] = {
 
	BEGIN(0xFDD),
 
	{ 0,   0, 0, 0x10, 1, 0x14, 16 + 2 },
 
	{ 0, 0xF, 0, 0x10, 1, 0x14, 20 + 2 },
 
static const DrawTileSeqStruct _lock_display_seq_2t[] = {
 
	TILE_SEQ_LINE( 0,   0, 0, 0x10, 1, 0x14, 16 + 2)
 
	TILE_SEQ_LINE( 0, 0xF, 0, 0x10, 1, 0x14, 20 + 2)
 
	TILE_SEQ_END()
 
};
 

	
 
static const DrawTileSeqStruct _lock_display_seq_3t[] = {
 
	TILE_SEQ_LINE(   0, 0, 0, 1, 0x10, 0x14, 16 + 3)
 
	TILE_SEQ_LINE( 0xF, 0, 0, 1, 0x10, 0x14, 20 + 3)
 
	TILE_SEQ_END()
 
};
 

	
 
static const WaterDrawTileStruct _lock_display_seq_3t[] = {
 
	BEGIN(0xFDD),
 
	{   0, 0, 0, 1, 0x10, 0x14, 16 + 3 },
 
	{ 0xF, 0, 0, 1, 0x10, 0x14, 20 + 3 },
 
	TILE_SEQ_END()
 
static const DrawTileSprites _lock_display_data[] = {
 
	TILE_SPRITE_LINE(1, _lock_display_seq_0)
 
	TILE_SPRITE_LINE(0, _lock_display_seq_1)
 
	TILE_SPRITE_LINE(2, _lock_display_seq_2)
 
	TILE_SPRITE_LINE(3, _lock_display_seq_3)
 

	
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_0b)
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_1b)
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_2b)
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_3b)
 

	
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_0t)
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_1t)
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_2t)
 
	TILE_SPRITE_LINE(0xFDD, _lock_display_seq_3t)
 
};
 

	
 
static const WaterDrawTileStruct * const _lock_display_seq[] = {
 
	_lock_display_seq_0,
 
	_lock_display_seq_1,
 
	_lock_display_seq_2,
 
	_lock_display_seq_3,
 

	
 
	_lock_display_seq_0b,
 
	_lock_display_seq_1b,
 
	_lock_display_seq_2b,
 
	_lock_display_seq_3b,
 

	
 
	_lock_display_seq_0t,
 
	_lock_display_seq_1t,
 
	_lock_display_seq_2t,
 
	_lock_display_seq_3t,
 
};
 

	
 
#undef BEGIN
 
#undef TILE_SEQ_LINE
 
#undef TILE_SEQ_END
 
#undef TILE_SPRITE_LINE
src/water_cmd.cpp
Show inline comments
 
@@ -614,41 +614,41 @@ static void DrawCanalWater(TileIndex til
 
#include "table/water_land.h"
 

	
 
/**
 
 * Draw a build sprite sequence for water tiles.
 
 * If buildings are invisible, nothing will be drawn.
 
 * @param ti      Tile info.
 
 * @param wdts    Sprite sequence to draw.
 
 * @param dtss     Sprite sequence to draw.
 
 * @param base    Base sprite.
 
 * @param offset  Additional sprite offset.
 
 * @param palette Palette to use.
 
 */
 
static void DrawWaterTileStruct(const TileInfo *ti, const WaterDrawTileStruct *wdts, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
 
static void DrawWaterTileStruct(const TileInfo *ti, const DrawTileSeqStruct *dtss, SpriteID base, uint offset, PaletteID palette, CanalFeature feature)
 
{
 
	/* Don't draw if buildings are invisible. */
 
	if (IsInvisibilitySet(TO_BUILDINGS)) return;
 

	
 
	for (; wdts->delta_x != 0x80; wdts++) {
 
		uint tile_offs = offset + wdts->image;
 
	for (; !dtss->IsTerminator(); dtss++) {
 
		uint tile_offs = offset + dtss->image.sprite;
 
		if (feature < CF_END) tile_offs = GetCanalSpriteOffset(feature, ti->tile, tile_offs);
 
		AddSortableSpriteToDraw(base + tile_offs, palette,
 
			ti->x + wdts->delta_x, ti->y + wdts->delta_y,
 
			wdts->size_x, wdts->size_y,
 
			wdts->size_z, ti->z + wdts->delta_z,
 
			ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
			dtss->size_x, dtss->size_y,
 
			dtss->size_z, ti->z + dtss->delta_z,
 
			IsTransparencySet(TO_BUILDINGS));
 
	}
 
}
 

	
 
/** Draw a lock tile. */
 
static void DrawWaterLock(const TileInfo *ti)
 
{
 
	int section = GetSection(ti->tile);
 
	const WaterDrawTileStruct *wdts = _lock_display_seq[section];
 
	const DrawTileSprites &dts = _lock_display_data[section];
 

	
 
	/* Draw ground sprite. */
 
	SpriteID image = wdts++->image;
 
	SpriteID image = dts.ground.sprite;
 

	
 
	SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
 
	if (water_base == 0) {
 
		/* Use default sprites. */
 
		water_base = SPR_CANALS_BASE;
 
	} else if (HasBit(_water_feature[CF_WATERSLOPE].flags, CFF_HAS_FLAT_SPRITE)) {
 
@@ -671,21 +671,20 @@ static void DrawWaterLock(const TileInfo
 
		/* If no custom graphics, use defaults. */
 
		base = SPR_LOCK_BASE;
 
		uint8 z_threshold = section >= 8 ? 8 : 0;
 
		zoffs = ti->z > z_threshold ? 24 : 0;
 
	}
 

	
 
	DrawWaterTileStruct(ti, wdts, base, zoffs, PAL_NONE, CF_LOCKS);
 
	DrawWaterTileStruct(ti, dts.seq, base, zoffs, PAL_NONE, CF_LOCKS);
 
}
 

	
 
/** Draw a ship depot tile. */
 
static void DrawWaterDepot(const TileInfo *ti)
 
{
 
	DrawWaterClassGround(ti);
 
	/* Skip first entry in _shipdepot_display_seq as this is the ground sprite. */
 
	DrawWaterTileStruct(ti, _shipdepot_display_seq[GetSection(ti->tile)] + 1, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END);
 
	DrawWaterTileStruct(ti, _shipdepot_display_data[GetSection(ti->tile)].seq, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END);
 
}
 

	
 
static void DrawRiverWater(const TileInfo *ti)
 
{
 
	SpriteID image = SPR_FLAT_WATER_TILE;
 
	uint     offset = 0;
 
@@ -773,20 +772,16 @@ static void DrawTile_Water(TileInfo *ti)
 
			break;
 
	}
 
}
 

	
 
void DrawShipDepotSprite(int x, int y, int image)
 
{
 
	const WaterDrawTileStruct *wdts = _shipdepot_display_seq[image];
 

	
 
	DrawSprite(wdts++->image, PAL_NONE, x, y);
 
	const DrawTileSprites &dts = _shipdepot_display_data[image];
 

	
 
	for (; wdts->delta_x != 0x80; wdts++) {
 
		Point pt = RemapCoords(wdts->delta_x, wdts->delta_y, wdts->delta_z);
 
		DrawSprite(wdts->image, COMPANY_SPRITE_COLOUR(_local_company), x + pt.x, y + pt.y);
 
	}
 
	DrawSprite(dts.ground.sprite, dts.ground.pal, x, y);
 
	DrawOrigTileSeqInGUI(x, y, &dts, COMPANY_SPRITE_COLOUR(_local_company));
 
}
 

	
 

	
 
static uint GetSlopeZ_Water(TileIndex tile, uint x, uint y)
 
{
 
	uint z;
0 comments (0 inline, 0 general)