diff options
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r-- | src/vehicle_base.h | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h index f923c2d79..30366e5ea 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -126,6 +126,45 @@ struct VehicleCache { byte cached_vis_effect; ///< Visual effect to show (see #VisualEffect) }; +/** Sprite sequence for a vehicle part. */ +struct VehicleSpriteSeq { + SpriteID sprite; + + bool operator==(const VehicleSpriteSeq &other) const + { + return this->sprite == other.sprite; + } + + bool operator!=(const VehicleSpriteSeq &other) const + { + return !this->operator==(other); + } + + /** + * Check whether the sequence contains any sprites. + */ + bool IsValid() const + { + return this->sprite != 0; + } + + /** + * Clear all information. + */ + void Clear() + { + this->sprite = 0; + } + + /** + * Assign a single sprite to the sequence. + */ + void Set(SpriteID sprite) + { + this->sprite = sprite; + } +}; + /** A vehicle pool for a little over 1 million vehicles. */ typedef Pool<Vehicle, VehicleID, 512, 0xFF000> VehiclePool; extern VehiclePool _vehicle_pool; @@ -220,7 +259,7 @@ public: * 0xff == reserved for another custom sprite */ byte spritenum; - SpriteID cur_image; ///< sprite number for this vehicle + VehicleSpriteSeq sprite_seq; ///< Vehicle appearance. byte x_extent; ///< x-extent of vehicle bounding box byte y_extent; ///< y-extent of vehicle bounding box byte z_extent; ///< z-extent of vehicle bounding box @@ -380,9 +419,9 @@ public: /** * Gets the sprite to show for the given direction * @param direction the direction the vehicle is facing - * @return the sprite for the given vehicle in the given direction + * @param [out] result Vehicle sprite sequence. */ - virtual SpriteID GetImage(Direction direction, EngineImageType image_type) const { return 0; } + virtual void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const { result->Clear(); } const GRFFile *GetGRF() const; uint32 GetGRFID() const; @@ -1079,9 +1118,12 @@ struct SpecializedVehicle : public Vehicle { /* Explicitly choose method to call to prevent vtable dereference - * it gives ~3% runtime improvements in games with many vehicles */ if (update_delta) ((T *)this)->T::UpdateDeltaXY(this->direction); - SpriteID old_image = this->cur_image; - this->cur_image = ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP); - if (force_update || this->cur_image != old_image) this->Vehicle::UpdateViewport(true); + VehicleSpriteSeq seq; + ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP, &seq); + if (force_update || this->sprite_seq != seq) { + this->sprite_seq = seq; + this->Vehicle::UpdateViewport(true); + } } }; |