(svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
authorbjarni
Thu, 05 Oct 2006 13:11:17 +0000
changeset 4740 e562a2cde601
parent 4739 bd535b408617
child 4741 7e0ebb20950d
(svn r6652) -Feature: [depot window] depot lists are now sorted, so vehicle 1 is always first and so on
This should not be a big slowdown as it's only called each time the list is generated and will normally be much faster than the list generation itself (only a small % of the total number of vehicles is in the depot)
depot_gui.c
vehicle_gui.c
--- a/depot_gui.c	Thu Oct 05 12:59:28 2006 +0000
+++ b/depot_gui.c	Thu Oct 05 13:11:17 2006 +0000
@@ -614,6 +614,8 @@
 	}
 }
 
+void DepotSortList(Vehicle **v, uint16 length);
+
 static void DepotWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
@@ -637,6 +639,7 @@
 					&WP(w, depot_d).vehicle_list, &WP(w, depot_d).engine_list_length, &WP(w, depot_d).engine_count,
 					&WP(w, depot_d).wagon_list,   &WP(w, depot_d).wagon_list_length,  &WP(w, depot_d).wagon_count);
 				WP(w, depot_d).generate_list = false;
+				DepotSortList(WP(w, depot_d).vehicle_list, WP(w, depot_d).engine_count);
 #ifndef NDEBUG
 			} else {
 				/* Here we got a piece of code, that only checks if we got a different number of vehicles in the depot list and the number of vehicles actually being in the depot.
--- a/vehicle_gui.c	Thu Oct 05 12:59:28 2006 +0000
+++ b/vehicle_gui.c	Thu Oct 05 13:11:17 2006 +0000
@@ -158,6 +158,11 @@
 	vl->l.flags &= ~VL_RESORT;
 }
 
+void DepotSortList(Vehicle **v, uint16 length)
+{
+	_internal_sort_order = 0;
+	qsort((void*)v, length, sizeof(v[0]), _vehicle_sorter[0]);
+}
 
 /* General Vehicle GUI based procedures that are independent of vehicle types */
 void InitializeVehiclesGuiList(void)