(svn r9755) -Codechange: refactor some more of the begin loading stuff.
authorrubidium
Sun, 29 Apr 2007 22:33:51 +0000
changeset 7049 01825af2ce90
parent 7048 06b931095b26
child 7050 6120cd416583
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
src/aircraft.h
src/aircraft_cmd.cpp
src/roadveh.h
src/roadveh_cmd.cpp
src/ship.h
src/ship_cmd.cpp
src/train.h
src/train_cmd.cpp
src/vehicle.cpp
src/vehicle.h
--- a/src/aircraft.h	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/aircraft.h	Sun Apr 29 22:33:51 2007 +0000
@@ -131,6 +131,7 @@
 	virtual ~Aircraft() {}
 
 	const char *GetTypeString() { return "aircraft"; }
+	void MarkDirty();
 };
 
 #endif /* AIRCRAFT_H */
--- a/src/aircraft_cmd.cpp	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/aircraft_cmd.cpp	Sun Apr 29 22:33:51 2007 +0000
@@ -1385,14 +1385,11 @@
 	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
 }
 
-/** Mark all views dirty for an aircraft.
- * @param v vehicle to be redrawn.
- */
-static void MarkAircraftDirty(Vehicle *v)
+void Aircraft::MarkDirty()
 {
-		v->cur_image = GetAircraftImage(v, v->direction);
-		if (v->subtype == AIR_HELICOPTER) v->next->next->cur_image = GetRotorImage(v);
-		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
+		this->cur_image = GetAircraftImage(this, 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);
 }
 
 static void HandleAircraftLoading(Vehicle *v, int mode)
@@ -1409,7 +1406,7 @@
 				SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
 				if (LoadUnloadVehicle(v, false)) {
 					InvalidateWindow(WC_AIRCRAFT_LIST, v->owner);
-					MarkAircraftDirty(v);
+					v->MarkDirty();
 				}
 				return;
 			}
@@ -1417,7 +1414,7 @@
 			Order b = v->current_order;
 			v->LeaveStation();
 			v->current_order.Free();
-			MarkAircraftDirty(v);
+			v->MarkDirty();
 			if (!(b.flags & OF_NON_STOP)) return;
 			break;
 		}
@@ -1511,12 +1508,6 @@
 	}
 
 	v->BeginLoading();
-
-	SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC);
-	LoadUnloadVehicle(v, true);
-	MarkAircraftDirty(v);
-	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
-	InvalidateWindowClasses(WC_AIRCRAFT_LIST);
 }
 
 static void AircraftLand(Vehicle *v)
--- a/src/roadveh.h	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/roadveh.h	Sun Apr 29 22:33:51 2007 +0000
@@ -39,6 +39,7 @@
 	virtual ~RoadVehicle() {}
 
 	const char *GetTypeString() { return "road vehicle"; }
+	void MarkDirty();
 };
 
 #endif /* ROADVEH_H */
--- a/src/roadveh_cmd.cpp	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/roadveh_cmd.cpp	Sun Apr 29 22:33:51 2007 +0000
@@ -486,10 +486,10 @@
 }
 
 
-static void MarkRoadVehDirty(Vehicle *v)
+void RoadVehicle::MarkDirty()
 {
-	v->cur_image = GetRoadVehImage(v, v->direction);
-	MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
+	this->cur_image = GetRoadVehImage(this, this->direction);
+	MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
 }
 
 static void UpdateRoadVehDeltaXY(Vehicle *v)
@@ -765,7 +765,7 @@
 				SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
 				if (LoadUnloadVehicle(v, false)) {
 					InvalidateWindow(WC_ROADVEH_LIST, v->owner);
-					MarkRoadVehDirty(v);
+					v->MarkDirty();
 				}
 				return;
 			}
@@ -1598,15 +1598,8 @@
 			v->last_station_visited = GetStationIndex(v->tile);
 
 			RoadVehArrivesAt(v, st);
-
 			v->BeginLoading();
 
-			SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
-			if (LoadUnloadVehicle(v, true)) {
-				InvalidateWindow(WC_ROADVEH_LIST, v->owner);
-				MarkRoadVehDirty(v);
-			}
-			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 			return;
 		}
 
--- a/src/ship.h	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/ship.h	Sun Apr 29 22:33:51 2007 +0000
@@ -40,6 +40,7 @@
 	virtual ~Ship() {}
 
 	const char *GetTypeString() { return "ship"; }
+	void MarkDirty();
 };
 
 #endif /* SHIP_H */
--- a/src/ship_cmd.cpp	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/ship_cmd.cpp	Sun Apr 29 22:33:51 2007 +0000
@@ -229,10 +229,10 @@
 	}
 }
 
-static void MarkShipDirty(Vehicle *v)
+void Ship::MarkDirty()
 {
-	v->cur_image = GetShipImage(v, v->direction);
-	MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
+	this->cur_image = GetShipImage(this, this->direction);
+	MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
 }
 
 static void PlayShipSound(Vehicle *v)
@@ -313,7 +313,7 @@
 				SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
 				if (LoadUnloadVehicle(v, false)) {
 					InvalidateWindow(WC_SHIPS_LIST, v->owner);
-					MarkShipDirty(v);
+					v->MarkDirty();
 				}
 				return;
 			}
@@ -359,7 +359,7 @@
 {
 	UpdateShipDeltaXY(v, v->direction);
 	v->cur_image = GetShipImage(v, v->direction);
-	MarkShipDirty(v);
+	v->MarkDirty();
 	InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 }
 
@@ -735,15 +735,8 @@
 							/* Process station in the orderlist. */
 							st = GetStation(v->current_order.dest);
 							if (st->facilities & FACIL_DOCK) { // ugly, ugly workaround for problem with ships able to drop off cargo at wrong stations
-								v->BeginLoading();
 								ShipArrivesAt(v, st);
-
-								SET_EXPENSES_TYPE(EXPENSES_SHIP_INC);
-								if (LoadUnloadVehicle(v, true)) {
-									InvalidateWindow(WC_SHIPS_LIST, v->owner);
-									MarkShipDirty(v);
-								}
-								InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
+								v->BeginLoading();
 							} else { // leave stations without docks right aways
 								v->current_order.type = OT_LEAVESTATION;
 								v->cur_order_index++;
--- a/src/train.h	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/train.h	Sun Apr 29 22:33:51 2007 +0000
@@ -244,6 +244,7 @@
 	virtual ~Train() {}
 
 	const char *GetTypeString() { return "train"; }
+	void MarkDirty();
 };
 
 #endif /* TRAIN_H */
--- a/src/train_cmd.cpp	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/train_cmd.cpp	Sun Apr 29 22:33:51 2007 +0000
@@ -2522,12 +2522,17 @@
 	return !at_waypoint && CheckReverseTrain(v);
 }
 
-static void MarkTrainDirty(Vehicle *v)
+void Train::MarkDirty()
 {
+	Vehicle *v = this;
 	do {
 		v->cur_image = GetTrainImage(v, v->direction);
 		MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
 	} while ((v = v->next) != NULL);
+
+	/* need to update acceleration and cached values since the goods on the train changed. */
+	TrainCargoChanged(this);
+	UpdateTrainAcceleration(this);
 }
 
 static void HandleTrainLoading(Vehicle *v, bool mode)
@@ -2551,11 +2556,7 @@
 				SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
 				if (LoadUnloadVehicle(v, false)) {
 					InvalidateWindow(WC_TRAINS_LIST, v->owner);
-					MarkTrainDirty(v);
-
-					/* need to update acceleration and cached values since the goods on the train changed. */
-					TrainCargoChanged(v);
-					UpdateTrainAcceleration(v);
+					v->MarkDirty();
 				}
 				return;
 			}
@@ -2636,15 +2637,6 @@
 
 	v->BeginLoading();
 	v->current_order.dest = 0;
-
-	SET_EXPENSES_TYPE(EXPENSES_TRAIN_INC);
-	if (LoadUnloadVehicle(v, true) != 0) {
-		InvalidateWindow(WC_TRAINS_LIST, v->owner);
-		TrainCargoChanged(v);
-		UpdateTrainAcceleration(v);
-	}
-	MarkTrainDirty(v);
-	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 }
 
 static byte AfterSetTrainPos(Vehicle *v, bool new_tile)
--- a/src/vehicle.cpp	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/vehicle.cpp	Sun Apr 29 22:33:51 2007 +0000
@@ -2980,6 +2980,17 @@
 
 	current_order.type = OT_LOADING;
 	GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
+
+	static const int expense_type[] = { EXPENSES_TRAIN_INC, EXPENSES_ROADVEH_INC, EXPENSES_SHIP_INC, EXPENSES_AIRCRAFT_INC };
+	SET_EXPENSES_TYPE(expense_type[this->type]);
+
+	if (LoadUnloadVehicle(this, true) != 0) {
+		static const WindowClass invalidate_windows[] = { WC_TRAINS_LIST, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_AIRCRAFT_LIST };
+		InvalidateWindow(invalidate_windows[this->type], this->owner);
+
+		this->MarkDirty();
+	}
+	InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, STATUS_BAR);
 }
 
 void Vehicle::LeaveStation()
--- a/src/vehicle.h	Sun Apr 29 21:24:08 2007 +0000
+++ b/src/vehicle.h	Sun Apr 29 22:33:51 2007 +0000
@@ -353,6 +353,11 @@
 	 * @return the string representation.
 	 */
 	virtual const char* GetTypeString() = 0;
+
+	/**
+	 * Marks the vehicles to be redrawn and updates cached variables
+	 */
+	virtual void MarkDirty() {}
 };
 
 /**
@@ -417,6 +422,7 @@
 	virtual ~InvalidVehicle() {}
 
 	const char *GetTypeString() { return "invalid vehicle"; }
+	void MarkDirty() { NOT_REACHED(); }
 };
 
 #define is_custom_sprite(x) (x >= 0xFD)