1
0
Fork 0

(svn r22106) -Codechange: Add DrawTileSeqStruct::MakeTerminator(), DrawTileSeqStruct::IsTerminator(), DrawTileSeqStruct::IsParentSprite() to simplify stuff.

release/1.2
frosch 2011-02-19 13:16:34 +00:00
parent 72e027e4d6
commit 57dc3ed716
3 changed files with 25 additions and 7 deletions

View File

@ -1223,7 +1223,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
DrawTileSeqStruct *dtss = const_cast<DrawTileSeqStruct *>(&dts->seq[seq_count - 1]); DrawTileSeqStruct *dtss = const_cast<DrawTileSeqStruct *>(&dts->seq[seq_count - 1]);
dtss->delta_x = buf->ReadByte(); dtss->delta_x = buf->ReadByte();
if ((byte) dtss->delta_x == 0x80) break; if (dtss->IsTerminator()) break;
dtss->delta_y = buf->ReadByte(); dtss->delta_y = buf->ReadByte();
dtss->delta_z = buf->ReadByte(); dtss->delta_z = buf->ReadByte();
dtss->size_x = buf->ReadByte(); dtss->size_x = buf->ReadByte();
@ -3955,7 +3955,7 @@ static void NewSpriteGroup(ByteReader *buf)
if (type > 0) { if (type > 0) {
seq->delta_z = buf->ReadByte(); seq->delta_z = buf->ReadByte();
if ((byte)seq->delta_z == 0x80) continue; if (!seq->IsParentSprite()) continue;
} }
seq->size_x = buf->ReadByte(); seq->size_x = buf->ReadByte();
@ -3964,7 +3964,7 @@ static void NewSpriteGroup(ByteReader *buf)
} }
/* Set the terminator value. */ /* Set the terminator value. */
const_cast<DrawTileSeqStruct *>(group->dts->seq)[i].delta_x = (int8)0x80; const_cast<DrawTileSeqStruct *>(group->dts->seq)[i].MakeTerminator();
break; break;
} }

View File

@ -43,7 +43,7 @@ void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, Transpare
PaletteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette); PaletteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
if ((byte)dtss->delta_z != 0x80) { if (dtss->IsParentSprite()) {
parent_sprite_encountered = true; parent_sprite_encountered = true;
AddSortableSpriteToDraw( AddSortableSpriteToDraw(
image, pal, image, pal,
@ -94,7 +94,7 @@ void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig
PaletteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette); PaletteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
if ((byte)dtss->delta_z != 0x80) { if (dtss->IsParentSprite()) {
Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z); Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
DrawSprite(image, pal, x + pt.x, y + pt.y); DrawSprite(image, pal, x + pt.x, y + pt.y);

View File

@ -27,11 +27,29 @@
struct DrawTileSeqStruct { struct DrawTileSeqStruct {
int8 delta_x; ///< \c 0x80 is sequence terminator int8 delta_x; ///< \c 0x80 is sequence terminator
int8 delta_y; int8 delta_y;
int8 delta_z; int8 delta_z; ///< \c 0x80 identifies child sprites
byte size_x; byte size_x;
byte size_y; byte size_y;
byte size_z; byte size_z;
PalSpriteID image; PalSpriteID image;
/** Make this struct a sequence terminator. */
void MakeTerminator()
{
this->delta_x = (int8)0x80;
}
/** Check whether this is a sequence terminator. */
bool IsTerminator() const
{
return (byte)this->delta_x == 0x80;
}
/** Check whether this is a parent sprite with a boundingbox. */
bool IsParentSprite() const
{
return (byte)this->delta_z != 0x80;
}
}; };
/** Ground palette sprite of a tile, together with its child sprites */ /** Ground palette sprite of a tile, together with its child sprites */
@ -56,7 +74,7 @@ struct DrawBuildingsTileStruct {
}; };
/** Iterate through all DrawTileSeqStructs in DrawTileSprites. */ /** Iterate through all DrawTileSeqStructs in DrawTileSprites. */
#define foreach_draw_tile_seq(idx, list) for (idx = list; ((byte) idx->delta_x) != 0x80; idx++) #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned); void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned); void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);