(svn r3366) Make an unnecessarily global variable local
authortron
Thu, 05 Jan 2006 16:51:10 +0000
changeset 2818 0694b03580b0
parent 2817 58dcead3f545
child 2819 710436dd4288
(svn r3366) Make an unnecessarily global variable local
openttd.c
vehicle.h
vehicle_gui.c
--- a/openttd.c	Thu Jan 05 12:40:50 2006 +0000
+++ b/openttd.c	Thu Jan 05 16:51:10 2006 +0000
@@ -231,7 +231,6 @@
 {
 	/* Dynamic stuff needs to be initialized somewhere... */
 	_station_sort  = NULL;
-	_vehicle_sort  = NULL;
 	_town_sort     = NULL;
 	_industry_sort = NULL;
 }
@@ -247,7 +246,6 @@
 	CleanPool(&_order_pool);
 
 	free(_station_sort);
-	free(_vehicle_sort);
 	free(_town_sort);
 	free(_industry_sort);
 }
--- a/vehicle.h	Thu Jan 05 12:40:50 2006 +0000
+++ b/vehicle.h	Thu Jan 05 16:51:10 2006 +0000
@@ -341,9 +341,6 @@
 #define BEGIN_ENUM_WAGONS(v) do {
 #define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL);
 
-/* vehicle.c */
-VARDEF SortStruct *_vehicle_sort;
-
 extern MemoryPool _vehicle_pool;
 
 /**
--- a/vehicle_gui.c	Thu Jan 05 12:40:50 2006 +0000
+++ b/vehicle_gui.c	Thu Jan 05 16:51:10 2006 +0000
@@ -106,15 +106,15 @@
 
 void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station)
 {
+	SortStruct* sort_list;
 	uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
 	uint n = 0;
 	uint i;
 
 	if (!(vl->flags & VL_REBUILD)) return;
 
-	/* Create array for sorting */
-	_vehicle_sort = realloc(_vehicle_sort, GetVehiclePoolSize() * sizeof(_vehicle_sort[0]));
-	if (_vehicle_sort == NULL)
+	sort_list = malloc(GetVehiclePoolSize() * sizeof(sort_list[0]));
+	if (sort_list == NULL)
 		error("Could not allocate memory for the vehicle-sorting-list");
 
 	DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
@@ -130,8 +130,8 @@
 
 				FOR_VEHICLE_ORDERS(v, order) {
 					if (order->type == OT_GOTO_STATION && order->station == station) {
-						_vehicle_sort[n].index = v->index;
-						_vehicle_sort[n].owner = v->owner;
+						sort_list[n].index = v->index;
+						sort_list[n].owner = v->owner;
 						++n;
 						break;
 					}
@@ -144,8 +144,8 @@
 			if (v->type == type && v->owner == owner && (
 				(type == VEH_Train && IsFrontEngine(v)) ||
 				(type != VEH_Train && v->subtype <= subtype))) {
-				_vehicle_sort[n].index = v->index;
-				_vehicle_sort[n].owner = v->owner;
+				sort_list[n].index = v->index;
+				sort_list[n].owner = v->owner;
 				++n;
 			}
 		}
@@ -157,7 +157,8 @@
 		error("Could not allocate memory for the vehicle-sorting-list");
 	vl->list_length = n;
 
-	for (i = 0; i < n; ++i) vl->sort_list[i] = _vehicle_sort[i];
+	for (i = 0; i < n; ++i) vl->sort_list[i] = sort_list[i];
+	free(sort_list);
 
 	vl->flags &= ~VL_REBUILD;
 	vl->flags |= VL_RESORT;