summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-12-14 21:28:45 +0000
committerterkhen <terkhen@openttd.org>2010-12-14 21:28:45 +0000
commit12c86a139193ab88edb998844c2685b569430a57 (patch)
treeaaed0f6452dd7cc0898caa795d24b1b2ac498490 /src
parentd6959dcc6be6a6c6cdc94c9c249a636a2781c8e5 (diff)
downloadopenttd-12c86a139193ab88edb998844c2685b569430a57.tar.xz
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
Diffstat (limited to 'src')
-rw-r--r--src/ground_vehicle.cpp26
-rw-r--r--src/ground_vehicle.hpp16
-rw-r--r--src/newgrf_engine.cpp8
-rw-r--r--src/openttd.cpp24
-rw-r--r--src/train_cmd.cpp12
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_cmd.cpp2
-rw-r--r--src/vehicle_gui.cpp14
8 files changed, 52 insertions, 52 deletions
diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp
index 142353f7e..80a43b6a3 100644
--- a/src/ground_vehicle.cpp
+++ b/src/ground_vehicle.cpp
@@ -55,21 +55,21 @@ void GroundVehicle<T, Type>::PowerChanged()
air_drag = (air_drag_value == 1) ? 0 : air_drag_value;
}
- this->acc_cache.cached_air_drag = air_drag + 3 * air_drag * number_of_parts / 20;
+ this->gcache.cached_air_drag = air_drag + 3 * air_drag * number_of_parts / 20;
max_te *= 10000; // Tractive effort in (tonnes * 1000 * 10 =) N.
max_te /= 256; // Tractive effort is a [0-255] coefficient.
- if (this->acc_cache.cached_power != total_power || this->acc_cache.cached_max_te != max_te) {
+ if (this->gcache.cached_power != total_power || this->gcache.cached_max_te != max_te) {
/* Stop the vehicle if it has no power. */
if (total_power == 0) this->vehstatus |= VS_STOPPED;
- this->acc_cache.cached_power = total_power;
- this->acc_cache.cached_max_te = max_te;
+ this->gcache.cached_power = total_power;
+ this->gcache.cached_max_te = max_te;
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
}
- this->acc_cache.cached_max_track_speed = max_track_speed;
+ this->gcache.cached_max_track_speed = max_track_speed;
}
/**
@@ -86,13 +86,13 @@ void GroundVehicle<T, Type>::CargoChanged()
uint32 current_weight = u->GetWeight();
weight += current_weight;
/* Slope steepness is in percent, result in N. */
- u->acc_cache.cached_slope_resistance = current_weight * u->GetSlopeSteepness() * 100;
+ u->gcache.cached_slope_resistance = current_weight * u->GetSlopeSteepness() * 100;
}
/* Store consist weight in cache. */
- this->acc_cache.cached_weight = max<uint32>(1, weight);
+ this->gcache.cached_weight = max<uint32>(1, weight);
/* Friction in bearings and other mechanical parts is 0.1% of the weight (result in N). */
- this->acc_cache.cached_axle_resistance = 10 * weight;
+ this->gcache.cached_axle_resistance = 10 * weight;
/* Now update vehicle power (tractive effort is dependent on weight). */
this->PowerChanged();
@@ -110,10 +110,10 @@ int GroundVehicle<T, Type>::GetAcceleration() const
int32 speed = v->GetCurrentSpeed(); // [km/h-ish]
/* Weight is stored in tonnes. */
- int32 mass = this->acc_cache.cached_weight;
+ int32 mass = this->gcache.cached_weight;
/* Power is stored in HP, we need it in watts. */
- int32 power = this->acc_cache.cached_power * 746;
+ int32 power = this->gcache.cached_power * 746;
int32 resistance = 0;
@@ -122,19 +122,19 @@ int GroundVehicle<T, Type>::GetAcceleration() const
const int area = v->GetAirDragArea();
if (!maglev) {
/* Static resistance plus rolling friction. */
- resistance = this->acc_cache.cached_axle_resistance;
+ resistance = this->gcache.cached_axle_resistance;
resistance += mass * v->GetRollingFriction();
}
/* Air drag; the air drag coefficient is in an arbitrary NewGRF-unit,
* so we need some magic conversion factor. */
- resistance += (area * this->acc_cache.cached_air_drag * speed * speed) / 500;
+ resistance += (area * this->gcache.cached_air_drag * speed * speed) / 500;
resistance += this->GetSlopeResistance();
/* This value allows to know if the vehicle is accelerating or braking. */
AccelStatus mode = v->GetAccelerationStatus();
- const int max_te = this->acc_cache.cached_max_te; // [N]
+ const int max_te = this->gcache.cached_max_te; // [N]
int force;
if (speed > 0) {
if (!maglev) {
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp
index e518e183f..d71eb7334 100644
--- a/src/ground_vehicle.hpp
+++ b/src/ground_vehicle.hpp
@@ -22,17 +22,17 @@ enum AccelStatus {
};
/**
- * Cached acceleration values.
+ * Cached values.
* All of these values except cached_slope_resistance are set only for the first part of a vehicle.
*/
-struct AccelerationCache {
- /* Cached values, recalculated when the cargo on a vehicle changes (in addition to the conditions below) */
+struct GroundVehicleCache {
+ /* Cached acceleration values, recalculated when the cargo on a vehicle changes (in addition to the conditions below) */
uint32 cached_weight; ///< Total weight of the consist.
uint32 cached_slope_resistance; ///< Resistance caused by weight when this vehicle part is at a slope.
uint32 cached_max_te; ///< Maximum tractive effort of consist.
uint16 cached_axle_resistance; ///< Resistance caused by the axles of the vehicle.
- /* Cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
+ /* Cached acceleration values, recalculated on load and each time a vehicle is added to/removed from the consist. */
uint16 cached_max_track_speed; ///< Maximum consist speed limited by track type.
uint32 cached_power; ///< Total power of the consist.
uint32 cached_air_drag; ///< Air drag coefficient of the vehicle.
@@ -67,8 +67,8 @@ enum GroundVehicleFlags {
*/
template <class T, VehicleType Type>
struct GroundVehicle : public SpecializedVehicle<T, Type> {
- AccelerationCache acc_cache;
- uint16 gv_flags; ///< @see GroundVehicleFlags
+ GroundVehicleCache gcache; ///< Cache of often calculated values.
+ uint16 gv_flags; ///< @see GroundVehicleFlags.
/**
* The constructor at SpecializedVehicle must be called.
@@ -89,9 +89,9 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
for (const T *u = T::From(this); u != NULL; u = u->Next()) {
if (HasBit(u->gv_flags, GVF_GOINGUP_BIT)) {
- incl += u->acc_cache.cached_slope_resistance;
+ incl += u->gcache.cached_slope_resistance;
} else if (HasBit(u->gv_flags, GVF_GOINGDOWN_BIT)) {
- incl -= u->acc_cache.cached_slope_resistance;
+ incl -= u->gcache.cached_slope_resistance;
}
}
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 8e276623c..22eca8844 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -795,10 +795,10 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x62: return t->track;
case 0x66: return t->railtype;
case 0x73: return t->tcache.cached_veh_length;
- case 0x74: return t->acc_cache.cached_power;
- case 0x75: return GB(t->acc_cache.cached_power, 8, 24);
- case 0x76: return GB(t->acc_cache.cached_power, 16, 16);
- case 0x77: return GB(t->acc_cache.cached_power, 24, 8);
+ case 0x74: return t->gcache.cached_power;
+ case 0x75: return GB(t->gcache.cached_power, 8, 24);
+ case 0x76: return GB(t->gcache.cached_power, 16, 16);
+ case 0x77: return GB(t->gcache.cached_power, 24, 8);
case 0x7C: return t->First()->index;
case 0x7D: return GB(t->First()->index, 8, 8);
case 0x7F: return 0; // Used for vehicle reversing hack in TTDP
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 8b4e01363..54d0ac3c1 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1141,11 +1141,11 @@ static void CheckCaches()
uint length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) length++;
- NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
- VehicleCache *veh_cache = CallocT<VehicleCache>(length);
- AccelerationCache *acc_cache = CallocT<AccelerationCache>(length);
- TrainCache *tra_cache = CallocT<TrainCache>(length);
- RoadVehicleCache *roa_cache = CallocT<RoadVehicleCache>(length);
+ NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
+ VehicleCache *veh_cache = CallocT<VehicleCache>(length);
+ GroundVehicleCache *gro_cache = CallocT<GroundVehicleCache>(length);
+ TrainCache *tra_cache = CallocT<TrainCache>(length);
+ RoadVehicleCache *roa_cache = CallocT<RoadVehicleCache>(length);
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
@@ -1154,11 +1154,11 @@ static void CheckCaches()
veh_cache[length] = u->vcache;
switch (u->type) {
case VEH_TRAIN:
- acc_cache[length] = Train::From(u)->acc_cache;
+ gro_cache[length] = Train::From(u)->gcache;
tra_cache[length] = Train::From(u)->tcache;
break;
case VEH_ROAD:
- acc_cache[length] = RoadVehicle::From(u)->acc_cache;
+ gro_cache[length] = RoadVehicle::From(u)->gcache;
roa_cache[length] = RoadVehicle::From(u)->rcache;
break;
default:
@@ -1186,16 +1186,16 @@ static void CheckCaches()
}
switch (u->type) {
case VEH_TRAIN:
- if (memcmp(&acc_cache[length], &Train::From(u)->acc_cache, sizeof(AccelerationCache)) != 0) {
- DEBUG(desync, 2, "train acceleration cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
+ if (memcmp(&gro_cache[length], &Train::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) {
+ DEBUG(desync, 2, "train ground vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
}
if (memcmp(&tra_cache[length], &Train::From(u)->tcache, sizeof(TrainCache)) != 0) {
DEBUG(desync, 2, "train cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
}
break;
case VEH_ROAD:
- if (memcmp(&acc_cache[length], &RoadVehicle::From(u)->acc_cache, sizeof(AccelerationCache)) != 0) {
- DEBUG(desync, 2, "road vehicle acceleration cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
+ if (memcmp(&gro_cache[length], &RoadVehicle::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) {
+ DEBUG(desync, 2, "road vehicle ground vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
}
if (memcmp(&roa_cache[length], &RoadVehicle::From(u)->rcache, sizeof(RoadVehicleCache)) != 0) {
DEBUG(desync, 2, "road vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length);
@@ -1209,7 +1209,7 @@ static void CheckCaches()
free(grf_cache);
free(veh_cache);
- free(acc_cache);
+ free(gro_cache);
free(tra_cache);
free(roa_cache);
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index bb473f3c8..6e995b0a7 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -422,15 +422,15 @@ int Train::GetCurrentMaxSpeed() const
}
}
- return min(max_speed, this->acc_cache.cached_max_track_speed);
+ return min(max_speed, this->gcache.cached_max_track_speed);
}
void Train::UpdateAcceleration()
{
assert(this->IsFrontEngine());
- uint power = this->acc_cache.cached_power;
- uint weight = this->acc_cache.cached_weight;
+ uint power = this->gcache.cached_power;
+ uint weight = this->gcache.cached_weight;
assert(weight != 0);
this->acceleration = Clamp(power / weight * 4, 1, 255);
}
@@ -1968,7 +1968,7 @@ static bool CheckTrainStayInDepot(Train *v)
}
/* if the train got no power, then keep it in the depot */
- if (v->acc_cache.cached_power == 0) {
+ if (v->gcache.cached_power == 0) {
v->vehstatus |= VS_STOPPED;
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
return true;
@@ -2617,7 +2617,7 @@ int Train::UpdateSpeed()
switch (_settings_game.vehicle.train_acceleration_model) {
default: NOT_REACHED();
case AM_ORIGINAL:
- max_speed = this->acc_cache.cached_max_track_speed;
+ max_speed = this->gcache.cached_max_track_speed;
accel = this->acceleration * (this->GetAccelerationStatus() == AS_BRAKE ? -4 : 2);
break;
case AM_REALISTIC:
@@ -2708,7 +2708,7 @@ static inline void AffectSpeedByZChange(Train *v, byte old_z)
v->cur_speed -= (v->cur_speed * rsp->z_up >> 8);
} else {
uint16 spd = v->cur_speed + rsp->z_down;
- if (spd <= v->acc_cache.cached_max_track_speed) v->cur_speed = spd;
+ if (spd <= v->gcache.cached_max_track_speed) v->cur_speed = spd;
}
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 0c42fbaf0..e9630566e 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -2032,7 +2032,7 @@ void Vehicle::ShowVisualEffect() const
* - in Chance16 - the last value is 512 / 2^smoke_amount (max. smoke when 128 = smoke_amount of 2). */
int power_weight_effect = 0;
if (v->type == VEH_TRAIN) {
- power_weight_effect = (32 >> (Train::From(this)->acc_cache.cached_power >> 10)) - (32 >> (Train::From(this)->acc_cache.cached_weight >> 9));
+ power_weight_effect = (32 >> (Train::From(this)->gcache.cached_power >> 10)) - (32 >> (Train::From(this)->gcache.cached_weight >> 9));
}
if (this->cur_speed < (this->vcache.cached_max_speed >> (2 >> _settings_game.vehicle.smoke_amount)) &&
Chance16((64 - ((this->cur_speed << 5) / this->vcache.cached_max_speed) + power_weight_effect), (512 >> _settings_game.vehicle.smoke_amount))) {
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index efb6d3b92..fad93e5e8 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -395,7 +395,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
switch (v->type) {
case VEH_TRAIN:
- if ((v->vehstatus & VS_STOPPED) && Train::From(v)->acc_cache.cached_power == 0) return_cmd_error(STR_ERROR_TRAIN_START_NO_CATENARY);
+ if ((v->vehstatus & VS_STOPPED) && Train::From(v)->gcache.cached_power == 0) return_cmd_error(STR_ERROR_TRAIN_START_NO_CATENARY);
break;
case VEH_SHIP:
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index fec5c1d39..3fb6f403a 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1704,9 +1704,9 @@ struct VehicleDetailsWindow : Window {
switch (v->type) {
case VEH_TRAIN:
SetDParam(2, v->GetDisplayMaxSpeed());
- SetDParam(1, Train::From(v)->acc_cache.cached_power);
- SetDParam(0, Train::From(v)->acc_cache.cached_weight);
- SetDParam(3, Train::From(v)->acc_cache.cached_max_te / 1000);
+ SetDParam(1, Train::From(v)->gcache.cached_power);
+ SetDParam(0, Train::From(v)->gcache.cached_weight);
+ SetDParam(3, Train::From(v)->gcache.cached_max_te / 1000);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type != 2) ?
STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE : STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED);
break;
@@ -1714,9 +1714,9 @@ struct VehicleDetailsWindow : Window {
case VEH_ROAD:
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
SetDParam(2, v->GetDisplayMaxSpeed());
- SetDParam(1, RoadVehicle::From(v)->acc_cache.cached_power);
- SetDParam(0, RoadVehicle::From(v)->acc_cache.cached_weight);
- SetDParam(3, RoadVehicle::From(v)->acc_cache.cached_max_te / 1000);
+ SetDParam(1, RoadVehicle::From(v)->gcache.cached_power);
+ SetDParam(0, RoadVehicle::From(v)->gcache.cached_weight);
+ SetDParam(3, RoadVehicle::From(v)->gcache.cached_max_te / 1000);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE);
break;
}
@@ -2193,7 +2193,7 @@ public:
} else if (v->vehstatus & VS_STOPPED) {
if (v->type == VEH_TRAIN) {
if (v->cur_speed == 0) {
- if (Train::From(v)->acc_cache.cached_power == 0) {
+ if (Train::From(v)->gcache.cached_power == 0) {
str = STR_VEHICLE_STATUS_TRAIN_NO_POWER;
} else {
str = STR_VEHICLE_STATUS_STOPPED;