Codechange: Build station and depot vehicle lists from shared order lists. (#11676)
The brings some performance advantages: * No need to iterate all vehicles and check for primary vehicle as only vehicles that can have orders are listed. * Shared orders only need to be tested once instead of for each vehicle sharing them. * Vehicle tests only need to be performed on the first shared vehicle instead of all.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "train.h"
|
||||
#include "vehiclelist.h"
|
||||
#include "vehiclelist_func.h"
|
||||
#include "group.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
@@ -116,17 +117,11 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
|
||||
|
||||
switch (vli.type) {
|
||||
case VL_STATION_LIST:
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->type == vli.vtype && v->IsPrimaryVehicle()) {
|
||||
for (const Order *order : v->Orders()) {
|
||||
if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT))
|
||||
&& order->GetDestination() == vli.index) {
|
||||
list->push_back(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FindVehiclesWithOrder(
|
||||
[&vli](const Vehicle *v) { return v->type == vli.vtype; },
|
||||
[&vli](const Order *order) { return (order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT)) && order->GetDestination() == vli.index; },
|
||||
[&list](const Vehicle *v) { list->push_back(v); }
|
||||
);
|
||||
break;
|
||||
|
||||
case VL_SHARED_ORDERS: {
|
||||
@@ -161,16 +156,11 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli
|
||||
break;
|
||||
|
||||
case VL_DEPOT_LIST:
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->type == vli.vtype && v->IsPrimaryVehicle()) {
|
||||
for (const Order *order : v->Orders()) {
|
||||
if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index) {
|
||||
list->push_back(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FindVehiclesWithOrder(
|
||||
[&vli](const Vehicle *v) { return v->type == vli.vtype; },
|
||||
[&vli](const Order *order) { return order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index; },
|
||||
[&list](const Vehicle *v) { list->push_back(v); }
|
||||
);
|
||||
break;
|
||||
|
||||
default: return false;
|
||||
|
Reference in New Issue
Block a user