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

Function AddSortableSpriteToDraw

src/viewport.cpp:663–744  ·  view source on GitHub ↗

* Draw a (transparent) sprite at given coordinates with a given bounding box. * The bounding box extends from (x + bb_offset_x, y + bb_offset_y, z + bb_offset_z) to (x + w - 1, y + h - 1, z + dz - 1), both corners included. * Bounding boxes with bb_offset_x == w or bb_offset_y == h or bb_offset_z == dz are allowed and produce thin slices. * * @note Bounding boxes are normally specified with bb

Source from the content-addressed store, hash-verified

661 * @param sub Only draw a part of the sprite.
662 */
663void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
664{
665 int32_t left, right, top, bottom;
666
667 assert((image & SPRITE_MASK) < MAX_SPRITES);
668
669 /* Move to bounding box. */
670 x += bounds.origin.x;
671 y += bounds.origin.y;
672 z += bounds.origin.z;
673
674 /* make the sprites transparent with the right palette */
675 if (transparent) {
676 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
677 pal = PALETTE_TO_TRANSPARENT;
678 }
679
680 if (_vd.combine_sprites == SPRITE_COMBINE_ACTIVE) {
681 AddCombinedSprite(image, pal, x + bounds.offset.x, y + bounds.offset.y, z + bounds.offset.z, sub);
682 return;
683 }
684
685 _vd.last_child = LAST_CHILD_NONE;
686
687 Point pt = RemapCoords(x + bounds.offset.x, y + bounds.offset.y, z + bounds.offset.z);
688 int tmp_left, tmp_top, tmp_x = pt.x, tmp_y = pt.y;
689
690 /* Compute screen extents of sprite */
691 if (image == SPR_EMPTY_BOUNDING_BOX) {
692 left = tmp_left = RemapCoords(x + bounds.extent.x, y, z).x;
693 right = RemapCoords(x, y + bounds.extent.y, z).x + 1;
694 top = tmp_top = RemapCoords(x, y, z + bounds.extent.z).y;
695 bottom = RemapCoords(x + bounds.extent.x, y + bounds.extent.y, z).y + 1;
696 } else {
697 const Sprite *spr = GetSprite(image & SPRITE_MASK, SpriteType::Normal);
698 left = tmp_left = (pt.x += spr->x_offs);
699 right = (pt.x + spr->width );
700 top = tmp_top = (pt.y += spr->y_offs);
701 bottom = (pt.y + spr->height);
702 }
703
704 if (_draw_bounding_boxes && (image != SPR_EMPTY_BOUNDING_BOX)) {
705 /* Compute maximal extents of sprite and its bounding box */
706 left = std::min(left , RemapCoords(x + bounds.extent.x, y, z).x);
707 right = std::max(right , RemapCoords(x, y + bounds.extent.y, z).x + 1);
708 top = std::min(top , RemapCoords(x, y, z + bounds.extent.z).y);
709 bottom = std::max(bottom, RemapCoords(x + bounds.extent.x, y + bounds.extent.y, z).y + 1);
710 }
711
712 /* Do not add the sprite to the viewport, if it is outside */
713 if (left >= _vd.dpi.left + _vd.dpi.width ||
714 right <= _vd.dpi.left ||
715 top >= _vd.dpi.top + _vd.dpi.height ||
716 bottom <= _vd.dpi.top) {
717 return;
718 }
719
720 ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.emplace_back();

Callers 15

DrawTile_IndustryFunction · 0.70
DrawWaterTileStructFunction · 0.70
DrawFoundationFunction · 0.70
DrawSingleSignalFunction · 0.70
DrawTrackFenceFunction · 0.70
DrawPillarFunction · 0.70
DrawBridgeRoadBitsFunction · 0.70
DrawTile_TunnelBridgeFunction · 0.70
DrawBridgeMiddleFunction · 0.70
DoDrawVehicleFunction · 0.70
DrawTile_ObjectFunction · 0.70
DrawRailCatenaryOnTunnelFunction · 0.70

Calls 4

SetBitFunction · 0.85
AddCombinedSpriteFunction · 0.85
RemapCoordsFunction · 0.85
GetSpriteFunction · 0.85

Tested by

no test coverage detected