forked from mirror/OpenTTD
(svn r21098) -Codechange: Ships now store their max speed in the cache instead of recalculating it every time.
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user