# HG changeset patch # User frosch # Date 2011-02-19 14:57:15 # Node ID 4fbd86e6412fa53aba1868846e701c10bda6385f # Parent 9a6d0d5833d59935dedf6ce53cd4b0a74cca16e0 (svn r22110) -Codechange: Remove WaterDrawTileStruct and use DrawTileSprites/DrawTileSeqStruct instead. diff --git a/src/table/water_land.h b/src/table/water_land.h --- a/src/table/water_land.h +++ b/src/table/water_land.h @@ -9,154 +9,146 @@ /** @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 diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -617,23 +617,23 @@ static void DrawCanalWater(TileIndex til * 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)); } } @@ -642,10 +642,10 @@ static void DrawWaterTileStruct(const Ti 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) { @@ -674,15 +674,14 @@ static void DrawWaterLock(const TileInfo 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) @@ -776,14 +775,10 @@ static void DrawTile_Water(TileInfo *ti) 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)); }