Changeset - r11317:eee2a93dcbe5
[Not reviewed]
master
0 4 0
rubidium - 15 years ago 2009-03-11 17:26:58
rubidium@openttd.org
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
4 files changed with 26 insertions and 32 deletions:
0 comments (0 inline, 0 general)
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -356,13 +356,13 @@ void AfterLoadVehicles(bool part_of_load
 
					UpdateAircraftCache(v);
 
				}
 
				break;
 
			default: break;
 
		}
 

	
 
		v->left_coord = INVALID_COORD;
 
		v->coord.left = INVALID_COORD;
 
		VehiclePositionChanged(v);
 
	}
 
}
 

	
 
static uint8  _cargo_days;
 
static uint16 _cargo_source;
src/sound.cpp
Show inline comments
 
@@ -242,14 +242,14 @@ void SndPlayTileFx(SoundFx sound, TileIn
 
	SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y);
 
}
 

	
 
void SndPlayVehicleFx(SoundFx sound, const Vehicle *v)
 
{
 
	SndPlayScreenCoordFx(sound,
 
		v->left_coord, v->right_coord,
 
		v->top_coord, v->top_coord
 
		v->coord.left, v->coord.right,
 
		v->coord.top, v->coord.bottom
 
	);
 
}
 

	
 
void SndPlayFx(SoundFx sound)
 
{
 
	StartSound(sound, 0, msf.effect_vol);
src/vehicle.cpp
Show inline comments
 
@@ -194,26 +194,26 @@ void VehiclePositionChanged(Vehicle *v)
 

	
 
	pt.x += spr->x_offs;
 
	pt.y += spr->y_offs;
 

	
 
	UpdateVehiclePosHash(v, pt.x, pt.y);
 

	
 
	v->left_coord = pt.x;
 
	v->top_coord = pt.y;
 
	v->right_coord = pt.x + spr->width + 2;
 
	v->bottom_coord = pt.y + spr->height + 2;
 
	v->coord.left = pt.x;
 
	v->coord.top = pt.y;
 
	v->coord.right = pt.x + spr->width + 2;
 
	v->coord.bottom = pt.y + spr->height + 2;
 
}
 

	
 
Vehicle::Vehicle()
 
{
 
	this->type               = VEH_INVALID;
 
	this->left_coord         = INVALID_COORD;
 
	this->coord.left         = INVALID_COORD;
 
	this->group_id           = DEFAULT_GROUP;
 
	this->fill_percent_te_id = INVALID_TE_ID;
 
	this->first              = this;
 
	this->colourmap           = PAL_NONE;
 
	this->colourmap          = PAL_NONE;
 
}
 

	
 
/**
 
 * Get a value for a vehicle's random_bits.
 
 * @return A random value from 0 to 255.
 
 */
 
@@ -436,14 +436,14 @@ static Vehicle *_vehicle_position_hash[0
 

	
 
static void UpdateVehiclePosHash(Vehicle *v, int x, int y)
 
{
 
	UpdateNewVehiclePosHash(v, x == INVALID_COORD);
 

	
 
	Vehicle **old_hash, **new_hash;
 
	int old_x = v->left_coord;
 
	int old_y = v->top_coord;
 
	int old_x = v->coord.left;
 
	int old_y = v->coord.top;
 

	
 
	new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x, y)];
 
	old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(old_x, old_y)];
 

	
 
	if (old_hash == new_hash) return;
 

	
 
@@ -813,16 +813,16 @@ void ViewportAddVehicles(DrawPixelInfo *
 
	for (int y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) {
 
		for (int x = xl;; x = (x + 1) & 0x3F) {
 
			const Vehicle *v = _vehicle_position_hash[x + y]; // already masked & 0xFFF
 

	
 
			while (v != NULL) {
 
				if (!(v->vehstatus & VS_HIDDEN) &&
 
						l <= v->right_coord &&
 
						t <= v->bottom_coord &&
 
						r >= v->left_coord &&
 
						b >= v->top_coord) {
 
						l <= v->coord.right &&
 
						t <= v->coord.bottom &&
 
						r >= v->coord.left &&
 
						b >= v->coord.top) {
 
					DoDrawVehicle(v);
 
				}
 
				v = v->next_hash;
 
			}
 

	
 
			if (x == xu) break;
 
@@ -841,18 +841,18 @@ Vehicle *CheckClickOnVehicle(const ViewP
 

	
 
	x = ScaleByZoom(x, vp->zoom) + vp->virtual_left;
 
	y = ScaleByZoom(y, vp->zoom) + vp->virtual_top;
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if ((v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0 &&
 
				x >= v->left_coord && x <= v->right_coord &&
 
				y >= v->top_coord && y <= v->bottom_coord) {
 
				x >= v->coord.left && x <= v->coord.right &&
 
				y >= v->coord.top && y <= v->coord.bottom) {
 

	
 
			dist = max(
 
				abs(((v->left_coord + v->right_coord) >> 1) - x),
 
				abs(((v->top_coord + v->bottom_coord) >> 1) - y)
 
				abs(((v->coord.left + v->coord.right) >> 1) - x),
 
				abs(((v->coord.top + v->coord.bottom) >> 1) - y)
 
			);
 

	
 
			if (dist < best_dist) {
 
				found = v;
 
				best_dist = dist;
 
			}
 
@@ -1638,31 +1638,28 @@ static Rect _old_vehicle_coords; ///< co
 
 * @param v vehicle which image's coords to store
 
 * @see _old_vehicle_coords
 
 * @see EndVehicleMove()
 
 */
 
void BeginVehicleMove(const Vehicle *v)
 
{
 
	_old_vehicle_coords.left   = v->left_coord;
 
	_old_vehicle_coords.top    = v->top_coord;
 
	_old_vehicle_coords.right  = v->right_coord;
 
	_old_vehicle_coords.bottom = v->bottom_coord;
 
	_old_vehicle_coords = v->coord;
 
}
 

	
 
/**
 
 * Marks screen dirty after a vehicle has moved
 
 * @param v vehicle which is marked dirty
 
 * @see _old_vehicle_coords
 
 * @see BeginVehicleMove()
 
 */
 
void EndVehicleMove(const Vehicle *v)
 
{
 
	MarkAllViewportsDirty(
 
		min(_old_vehicle_coords.left,   v->left_coord),
 
		min(_old_vehicle_coords.top,    v->top_coord),
 
		max(_old_vehicle_coords.right,  v->right_coord) + 1,
 
		max(_old_vehicle_coords.bottom, v->bottom_coord) + 1
 
		min(_old_vehicle_coords.left,   v->coord.left),
 
		min(_old_vehicle_coords.top,    v->coord.top),
 
		max(_old_vehicle_coords.right,  v->coord.right) + 1,
 
		max(_old_vehicle_coords.bottom, v->coord.bottom) + 1
 
	);
 
}
 

	
 
/**
 
 * Marks viewports dirty where the vehicle's image is
 
 * In fact, it equals
 
@@ -1670,13 +1667,13 @@ void EndVehicleMove(const Vehicle *v)
 
 * @param v vehicle to mark dirty
 
 * @see BeginVehicleMove()
 
 * @see EndVehicleMove()
 
 */
 
void MarkSingleVehicleDirty(const Vehicle *v)
 
{
 
	MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
 
	MarkAllViewportsDirty(v->coord.left, v->coord.top, v->coord.right + 1, v->coord.bottom + 1);
 
}
 

	
 
/**
 
 * Get position information of a vehicle when moving one pixel in the direction it is facing
 
 * @param v Vehicle to move
 
 * @return Position information after the move */
src/vehicle_base.h
Show inline comments
 
@@ -228,16 +228,13 @@ public:
 
	/* Used for timetabling. */
 
	uint32 current_order_time;     ///< How many ticks have passed since this order started.
 
	int32 lateness_counter;        ///< How many ticks late (or early if negative) this vehicle is.
 

	
 
	/* Boundaries for the current position in the world and a next hash link.
 
	 * NOSAVE: All of those can be updated with VehiclePositionChanged() */
 
	int32 left_coord;
 
	int32 top_coord;
 
	int32 right_coord;
 
	int32 bottom_coord;
 
	Rect coord;
 
	Vehicle *next_hash;
 
	Vehicle *next_new_hash;
 
	Vehicle **old_new_hash;
 

	
 
	SpriteID colourmap; // NOSAVE: cached colour mapping
 

	
0 comments (0 inline, 0 general)