* Update the bounding box co-ordinates of the vehicle * @param update_cache Update the cached values for previous co-ordinate values */
| 1669 | * @param update_cache Update the cached values for previous co-ordinate values |
| 1670 | */ |
| 1671 | void Vehicle::UpdateBoundingBoxCoordinates(bool update_cache) const |
| 1672 | { |
| 1673 | Rect new_coord; |
| 1674 | this->sprite_cache.sprite_seq.GetBounds(&new_coord); |
| 1675 | |
| 1676 | /* z-bounds are not used. */ |
| 1677 | Point pt = RemapCoords(this->x_pos + this->bounds.origin.x + this->bounds.offset.x, this->y_pos + this->bounds.origin.y + this->bounds.offset.y, this->z_pos); |
| 1678 | new_coord.left += pt.x; |
| 1679 | new_coord.top += pt.y; |
| 1680 | new_coord.right += pt.x + 2 * ZOOM_BASE; |
| 1681 | new_coord.bottom += pt.y + 2 * ZOOM_BASE; |
| 1682 | |
| 1683 | extern bool _draw_bounding_boxes; |
| 1684 | if (_draw_bounding_boxes) { |
| 1685 | int x = this->x_pos + this->bounds.origin.x; |
| 1686 | int y = this->y_pos + this->bounds.origin.y; |
| 1687 | int z = this->z_pos + this->bounds.origin.z; |
| 1688 | new_coord.left = std::min(new_coord.left, RemapCoords(x + bounds.extent.x, y, z).x); |
| 1689 | new_coord.right = std::max(new_coord.right, RemapCoords(x, y + bounds.extent.y, z).x + 1); |
| 1690 | new_coord.top = std::min(new_coord.top, RemapCoords(x, y, z + bounds.extent.z).y); |
| 1691 | new_coord.bottom = std::max(new_coord.bottom, RemapCoords(x + bounds.extent.x, y + bounds.extent.y, z).y + 1); |
| 1692 | } |
| 1693 | |
| 1694 | if (update_cache) { |
| 1695 | /* |
| 1696 | * If the old coordinates are invalid, set the cache to the new coordinates for correct |
| 1697 | * behaviour the next time the coordinate cache is checked. |
| 1698 | */ |
| 1699 | this->sprite_cache.old_coord = this->coord.left == INVALID_COORD ? new_coord : this->coord; |
| 1700 | } |
| 1701 | else { |
| 1702 | /* Extend the bounds of the existing cached bounding box so the next dirty window is correct */ |
| 1703 | this->sprite_cache.old_coord.left = std::min(this->sprite_cache.old_coord.left, this->coord.left); |
| 1704 | this->sprite_cache.old_coord.top = std::min(this->sprite_cache.old_coord.top, this->coord.top); |
| 1705 | this->sprite_cache.old_coord.right = std::max(this->sprite_cache.old_coord.right, this->coord.right); |
| 1706 | this->sprite_cache.old_coord.bottom = std::max(this->sprite_cache.old_coord.bottom, this->coord.bottom); |
| 1707 | } |
| 1708 | |
| 1709 | this->coord = new_coord; |
| 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * Update the vehicle on the viewport, updating the right hash and setting the new coordinates. |
no test coverage detected