MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawCommonTileSeq

Function DrawCommonTileSeq

src/sprite.cpp:30–74  ·  view source on GitHub ↗

* Draws a tile sprite sequence. * @param ti The tile to draw on * @param dts Sprite and subsprites to draw * @param to The transparency bit that toggles drawing of these sprites * @param orig_offset Sprite-Offset for original sprites * @param newgrf_offset Sprite-Offset for NewGRF defined sprites * @param default_palette The default recolour sprite to use (typically company colour) * @param

Source from the content-addressed store, hash-verified

28 * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned
29 */
30void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
31{
32 bool parent_sprite_encountered = false;
33 bool skip_childs = false;
34 for (const DrawTileSeqStruct &dtss : dts->GetSequence()) {
35 SpriteID image = dtss.image.sprite;
36 PaletteID pal = dtss.image.pal;
37
38 if (skip_childs) {
39 if (!dtss.IsParentSprite()) continue;
40 skip_childs = false;
41 }
42
43 /* TTD sprite 0 means no sprite */
44 if ((GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) ||
45 (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE))) {
46 skip_childs = dtss.IsParentSprite();
47 continue;
48 }
49
50 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
51 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset;
52
53 pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
54
55 if (dtss.IsParentSprite()) {
56 parent_sprite_encountered = true;
57 AddSortableSpriteToDraw(image, pal, *ti, dtss, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)
58 );
59 } else {
60 int offs_x = child_offset_is_unsigned ? static_cast<uint8_t>(dtss.origin.x) : dtss.origin.x;
61 int offs_y = child_offset_is_unsigned ? static_cast<uint8_t>(dtss.origin.y) : dtss.origin.y;
62 bool transparent = !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to);
63 if (parent_sprite_encountered) {
64 AddChildSpriteScreen(image, pal, offs_x, offs_y, transparent);
65 } else {
66 if (transparent) {
67 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
68 pal = PALETTE_TO_TRANSPARENT;
69 }
70 DrawGroundSprite(image, pal, nullptr, offs_x, offs_y);
71 }
72 }
73 }
74}
75
76/**
77 * Draws a tile sprite sequence in the GUI

Callers 3

DrawRailTileSeqFunction · 0.85
DrawOrigTileSeqFunction · 0.85
DrawNewGRFTileSeqFunction · 0.85

Calls 11

GBFunction · 0.85
HasBitFunction · 0.85
IsInvisibilitySetFunction · 0.85
IsTransparencySetFunction · 0.85
AddChildSpriteScreenFunction · 0.85
SetBitFunction · 0.85
DrawGroundSpriteFunction · 0.85
IsParentSpriteMethod · 0.80
AddSortableSpriteToDrawFunction · 0.70
GetSequenceMethod · 0.45

Tested by

no test coverage detected