summaryrefslogtreecommitdiff
path: root/src/ship_cmd.cpp
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-11-06 13:03:17 +0000
committerterkhen <terkhen@openttd.org>2010-11-06 13:03:17 +0000
commit25d1b2f54b9cac01e2737848c208f6d8096a4a92 (patch)
tree37860a84857248e929612d7ed018a4e2065d31cd /src/ship_cmd.cpp
parentc8a56f17f82be7d4a8e935fc514c86a313dc7d15 (diff)
downloadopenttd-25d1b2f54b9cac01e2737848c208f6d8096a4a92.tar.xz
(svn r21098) -Codechange: Ships now store their max speed in the cache instead of recalculating it every time.
Diffstat (limited to 'src/ship_cmd.cpp')
-rw-r--r--src/ship_cmd.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 24e9eb654..f220e13a0 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -153,6 +153,11 @@ static void CheckIfShipNeedsService(Vehicle *v)
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
+void Ship::UpdateCache()
+{
+ this->vcache.cached_max_speed = GetVehicleProperty(this, PROP_SHIP_SPEED, this->max_speed);
+}
+
Money Ship::GetRunningCost() const
{
const Engine *e = Engine::Get(this->engine_type);
@@ -296,7 +301,7 @@ static bool ShipAccelerate(Vehicle *v)
uint spd;
byte t;
- spd = min(v->cur_speed + 1, GetVehicleProperty(v, PROP_SHIP_SPEED, v->max_speed));
+ spd = min(v->cur_speed + 1, v->vcache.cached_max_speed);
/* updates statusbar only if speed have changed to save CPU time */
if (spd != v->cur_speed) {
@@ -615,6 +620,8 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, u
v->cur_image = SPR_IMG_QUERY;
v->random_bits = VehicleRandomBits();
+ v->UpdateCache();
+
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
v->InvalidateNewGRFCacheOfChain();