Mercurial > hg > openttd
changeset 8317:7ce2445db70c draft
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
author | smatz <smatz@openttd.org> |
---|---|
date | Wed, 16 Jan 2008 21:17:31 +0000 |
parents | a3f30e43d561 |
children | e2e3a8e85bdb |
files | src/aircraft_cmd.cpp src/disaster_cmd.cpp src/roadveh_cmd.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle_func.h src/water_cmd.cpp |
diffstat | 8 files changed, 55 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1288,8 +1288,7 @@ CLRBITS(st->airport_flags, RUNWAY_IN_OUT_block); // commuter airport CLRBITS(st->airport_flags, RUNWAY_IN2_block); // intercontinental - BeginVehicleMove(v); - EndVehicleMove(v); + MarkSingleVehicleDirty(v); DoDeleteAircraft(v); } @@ -1417,7 +1416,7 @@ { this->cur_image = this->GetImage(this->direction); if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this); - MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1); + MarkSingleVehicleDirty(this); } static void CrashAirplane(Vehicle *v)
--- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -138,8 +138,7 @@ DisasterVehicleUpdateImage(v); VehiclePositionChanged(v); - BeginVehicleMove(v); - EndVehicleMove(v); + MarkSingleVehicleDirty(v); } static void DeleteDisasterVeh(Vehicle *v) @@ -547,8 +546,7 @@ if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1; VehiclePositionChanged(v); - BeginVehicleMove(v); - EndVehicleMove(v); + MarkSingleVehicleDirty(v); } /** @@ -706,8 +704,7 @@ if (++v->age > 8880) { VehiclePositionChanged(v); - BeginVehicleMove(v); - EndVehicleMove(v); + MarkSingleVehicleDirty(v); delete v; return; }
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -564,7 +564,7 @@ { for (Vehicle *v = this; v != NULL; v = v->Next()) { v->cur_image = v->GetImage(v->direction); - MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); + MarkSingleVehicleDirty(v); } } @@ -615,8 +615,7 @@ if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v); - BeginVehicleMove(v); - EndVehicleMove(v); + MarkSingleVehicleDirty(v); delete v; } @@ -690,7 +689,7 @@ u->vehstatus |= VS_CRASHED; - MarkAllViewportsDirty(u->left_coord, u->top_coord, u->right_coord + 1, u->bottom_coord + 1); + MarkSingleVehicleDirty(u); } ClearSlot(v);
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -229,7 +229,7 @@ void Ship::MarkDirty() { this->cur_image = this->GetImage(this->direction); - MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1); + MarkSingleVehicleDirty(this); } static void PlayShipSound(const Vehicle *v)
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2572,7 +2572,7 @@ Vehicle *v = this; do { v->cur_image = v->GetImage(v->direction); - MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); + MarkSingleVehicleDirty(v); } while ((v = v->Next()) != NULL); /* need to update acceleration and cached values since the goods on the train changed. */ @@ -2790,7 +2790,7 @@ BEGIN_ENUM_WAGONS(v) v->vehstatus |= VS_CRASHED; - MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); + MarkSingleVehicleDirty(v); END_ENUM_WAGONS(v) } @@ -3137,8 +3137,7 @@ RebuildVehicleLists(); - BeginVehicleMove(v); - EndVehicleMove(v); + MarkSingleVehicleDirty(v); /* 'v' shouldn't be accessed after it has been deleted */ TrackBits track = v->u.rail.track;
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -596,11 +596,9 @@ do { Vehicle *u = v; - if (!(v->vehstatus & VS_HIDDEN)) { - /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, - * it may happen that vehicle chain is deleted when visible */ - MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); - } + /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, + * it may happen that vehicle chain is deleted when visible */ + if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v); v = v->Next(); delete u; } while (v != NULL); @@ -2356,26 +2354,51 @@ } -static Rect _old_vehicle_coords; - -void BeginVehicleMove(Vehicle *v) +static Rect _old_vehicle_coords; ///< coords of vehicle before it has moved + +/** + * Stores the vehicle image coords for later call to EndVehicleMove() + * @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.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; } -void EndVehicleMove(Vehicle *v) +/** + * 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->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 ); } +/** + * Marks viewports dirty where the vehicle's image is + * In fact, it equals + * BeginVehicleMove(v); EndVehicleMove(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); +} + /* returns true if staying in the same tile */ GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v) {
--- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -57,8 +57,9 @@ void AgeVehicle(Vehicle *v); void VehicleEnteredDepotThisTick(Vehicle *v); -void BeginVehicleMove(Vehicle *v); -void EndVehicleMove(Vehicle *v); +void BeginVehicleMove(const Vehicle *v); +void EndVehicleMove(const Vehicle *v); +void MarkSingleVehicleDirty(const Vehicle *v); UnitID GetFreeUnitNumber(VehicleType type);
--- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -735,7 +735,7 @@ BEGIN_ENUM_WAGONS(v) if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count(); v->vehstatus |= VS_CRASHED; - MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1); + MarkSingleVehicleDirty(v); END_ENUM_WAGONS(v) v = u;