Changeset - r16373:fab42163de3d
[Not reviewed]
master
0 5 0
terkhen - 14 years ago 2010-11-06 13:05:11
terkhen@openttd.org
(svn r21099) -Codechange: Store road vehicle max speed in the vehicle cache.
5 files changed with 20 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1232,8 +1232,15 @@ static void LoadUnloadVehicle(Vehicle *v
 
			case VEH_SHIP:
 
				t = u->vcache.cached_max_speed;
 
				break;
 
			case VEH_ROAD:     t = u->max_speed / 2;        break;
 
			case VEH_AIRCRAFT: t = Aircraft::From(u)->GetSpeedOldUnits(); break; // Convert to old units.
 

	
 
			case VEH_ROAD:
 
				t = u->vcache.cached_max_speed / 2;
 
				break;
 

	
 
			case VEH_AIRCRAFT:
 
				t = Aircraft::From(u)->GetSpeedOldUnits(); // Convert to old units.
 
				break;
 

	
 
			default: NOT_REACHED();
 
		}
 

	
src/newgrf_engine.cpp
Show inline comments
 
@@ -717,17 +717,12 @@ static uint32 VehicleGetVariable(const R
 
		case 0x19: {
 
			uint max_speed;
 
			switch (v->type) {
 
				case VEH_TRAIN: /* FALL THROUGH */
 
				case VEH_SHIP:
 
					max_speed = v->vcache.cached_max_speed;
 
					break;
 

	
 
				case VEH_AIRCRAFT:
 
					max_speed = Aircraft::From(v)->GetSpeedOldUnits(); // Convert to old units.
 
					break;
 

	
 
				default:
 
					max_speed = v->max_speed;
 
					max_speed = v->vcache.cached_max_speed;
 
					break;
 
			}
 
			return (variable - 0x80) == 0x18 ? max_speed : GB(max_speed, 8, 8);
src/roadveh.h
Show inline comments
 
@@ -119,7 +119,7 @@ struct RoadVehicle : public GroundVehicl
 
	bool IsPrimaryVehicle() const { return this->IsRoadVehFront(); }
 
	SpriteID GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->cur_speed / 2; }
 
	int GetDisplayMaxSpeed() const { return this->max_speed / 2; }
 
	int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed / 2; }
 
	Money GetRunningCost() const;
 
	int GetDisplayImageWidth(Point *offset = NULL) const;
 
	bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
src/roadveh_cmd.cpp
Show inline comments
 
@@ -191,6 +191,8 @@ void RoadVehUpdateCache(RoadVehicle *v)
 
		/* Invalidate the vehicle colour map */
 
		u->colourmap = PAL_NONE;
 
	}
 

	
 
	v->vcache.cached_max_speed = RoadVehInfo(v->engine_type)->max_speed;
 
}
 

	
 
/**
 
@@ -384,17 +386,17 @@ void RoadVehicle::UpdateDeltaXY(Directio
 
 */
 
FORCEINLINE int RoadVehicle::GetCurrentMaxSpeed() const
 
{
 
	if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) return this->max_speed;
 
	if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) return this->vcache.cached_max_speed;
 

	
 
	int max_speed = this->max_speed;
 
	int max_speed = this->vcache.cached_max_speed;
 

	
 
	/* Limit speed to 50% while reversing, 75% in curves. */
 
	for (const RoadVehicle *u = this; u != NULL; u = u->Next()) {
 
		if (this->state <= RVSB_TRACKDIR_MASK && IsReversingRoadTrackdir((Trackdir)this->state)) {
 
			max_speed = this->max_speed / 2;
 
			max_speed = this->vcache.cached_max_speed / 2;
 
			break;
 
		} else if ((u->direction & 1) == 0) {
 
			max_speed = this->max_speed * 3 / 4;
 
			max_speed = this->vcache.cached_max_speed * 3 / 4;
 
		}
 
	}
 

	
 
@@ -753,7 +755,7 @@ static void RoadVehCheckOvertake(RoadVeh
 
	od.v = v;
 
	od.u = u;
 

	
 
	if (u->max_speed >= v->max_speed &&
 
	if (u->max_speed >= v->vcache.cached_max_speed &&
 
			!(u->vehstatus & VS_STOPPED) &&
 
			u->cur_speed != 0) {
 
		return;
 
@@ -806,7 +808,7 @@ static void RoadZPosAffectSpeed(RoadVehi
 
		v->cur_speed = v->cur_speed * 232 / 256; // slow down by ~10%
 
	} else {
 
		uint16 spd = v->cur_speed + 2;
 
		if (spd <= v->max_speed) v->cur_speed = spd;
 
		if (spd <= v->vcache.cached_max_speed) v->cur_speed = spd;
 
	}
 
}
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -806,12 +806,7 @@ static int CDECL VehicleReliabilitySorte
 
/** Sort vehicles by their max speed */
 
static int CDECL VehicleMaxSpeedSorter(const Vehicle * const *a, const Vehicle * const *b)
 
{
 
	int r = 0;
 
	if ((*a)->type != VEH_ROAD && (*b)->type != VEH_ROAD) {
 
		r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed;
 
	} else {
 
		r = (*a)->max_speed - (*b)->max_speed;
 
	}
 
	int r = (*a)->vcache.cached_max_speed - (*b)->vcache.cached_max_speed;
 
	return (r != 0) ? r : VehicleNumberSorter(a, b);
 
}
 

	
0 comments (0 inline, 0 general)