summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-10-16 14:58:38 +0000
committerfrosch <frosch@openttd.org>2016-10-16 14:58:38 +0000
commitc175067ed9c17d43feaf356cd575dddddd699889 (patch)
treef865fa356c59ab450aa1c93a22f024f15d675224 /src/vehicle.cpp
parentd2393b4f6c89b75a90452fe68ab8a1cfbd8c353f (diff)
downloadopenttd-c175067ed9c17d43feaf356cd575dddddd699889.tar.xz
(svn r27667) -Codechange: Add VehicleSpriteSeq::GetBounds and Draw.
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index c5261407b..54a2bfa28 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -68,6 +68,32 @@ uint16 _returned_mail_refit_capacity; ///< Stores the mail capacity after a refi
VehiclePool _vehicle_pool("Vehicle");
INSTANTIATE_POOL_METHODS(Vehicle)
+
+/**
+ * Determine shared bounds of all sprites.
+ * @param [out] bounds Shared bounds.
+ */
+void VehicleSpriteSeq::GetBounds(Rect *bounds) const
+{
+ const Sprite *spr = GetSprite(this->sprite, ST_NORMAL);
+ bounds->left = spr->x_offs;
+ bounds->top = spr->y_offs;
+ bounds->right = spr->width + spr->x_offs - 1;
+ bounds->bottom = spr->height + spr->y_offs - 1;
+}
+
+/**
+ * Draw the sprite sequence.
+ * @param x X position
+ * @param y Y position
+ * @param default_pal Vehicle palette
+ * @param force_pal Whether to ignore individual palettes, and draw everything with \a default_pal.
+ */
+void VehicleSpriteSeq::Draw(int x, int y, PaletteID default_pal, bool force_pal) const
+{
+ DrawSprite(this->sprite, default_pal, x, y);
+}
+
/**
* Function to tell if a vehicle needs to be autorenewed
* @param *c The vehicle owner
@@ -1486,19 +1512,19 @@ void Vehicle::UpdatePosition()
*/
void Vehicle::UpdateViewport(bool dirty)
{
- const Sprite *spr = GetSprite(this->sprite_seq.sprite, ST_NORMAL);
+ Rect new_coord;
+ this->sprite_seq.GetBounds(&new_coord);
Point pt = RemapCoords(this->x_pos + this->x_offs, this->y_pos + this->y_offs, this->z_pos);
- pt.x += spr->x_offs;
- pt.y += spr->y_offs;
+ new_coord.left += pt.x;
+ new_coord.top += pt.y;
+ new_coord.right += pt.x + 2 * ZOOM_LVL_BASE;
+ new_coord.bottom += pt.y + 2 * ZOOM_LVL_BASE;
- UpdateVehicleViewportHash(this, pt.x, pt.y);
+ UpdateVehicleViewportHash(this, new_coord.left, new_coord.top);
Rect old_coord = this->coord;
- this->coord.left = pt.x;
- this->coord.top = pt.y;
- this->coord.right = pt.x + spr->width + 2 * ZOOM_LVL_BASE;
- this->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE;
+ this->coord = new_coord;
if (dirty) {
if (old_coord.left == INVALID_COORD) {