summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-11 11:00:42 +0000
committerrubidium <rubidium@openttd.org>2010-12-11 11:00:42 +0000
commit0d32cd3cc83fda6ad3726b3dedc5ad096beaac9d (patch)
tree1e6b44adcaaaa59bba5a7ff3c454bf58423b5c89 /src
parent834f4f157a49f0d9702927cf57a4e376e0b6ece5 (diff)
downloadopenttd-0d32cd3cc83fda6ad3726b3dedc5ad096beaac9d.tar.xz
(svn r21462) -Codechange [FS#3689]: don't do unnecessary cargo reservations in while loading/unloading vehicles. It is only needed when at least one vehicle is loading; all other times it is a waste of effort. Roughly halves the time it takes to perform loading/unloading of vehicles (fonsinchen)
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 87d946f95..1e94d7387 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1110,10 +1110,8 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left)
{
assert(v->current_order.IsType(OT_LOADING));
- assert(v->load_unload_ticks != 0);
-
/* We have not waited enough time till the next round of loading/unloading */
- if (--v->load_unload_ticks != 0) {
+ if (v->load_unload_ticks != 0) {
if (_settings_game.order.improved_load && (v->current_order.GetLoadType() & OLFB_FULL_LOAD)) {
/* 'Reserve' this cargo for this vehicle, because we were first. */
for (; v != NULL; v = v->Next()) {
@@ -1423,14 +1421,36 @@ void LoadUnloadStation(Station *st)
/* No vehicle is here... */
if (st->loading_vehicles.empty()) return;
+ Vehicle *last_loading = NULL;
+ std::list<Vehicle *>::iterator iter;
+
+ /* Check if anything will be loaded at all. Otherwise we don't need to reserve either. */
+ for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
+ Vehicle *v = *iter;
+
+ if ((v->vehstatus & (VS_STOPPED | VS_CRASHED))) continue;
+
+ assert(v->load_unload_ticks != 0);
+ if (--v->load_unload_ticks == 0) last_loading = v;
+ }
+
+ /* We only need to reserve and load/unload up to the last loading vehicle.
+ * Anything else will be forgotten anyway after returning from this function.
+ *
+ * Especially this means we do _not_ need to reserve cargo for a single
+ * consist in a station which is not allowed to load yet because its
+ * load_unload_ticks is still not 0.
+ */
+ if (last_loading == NULL) return;
+
int cargo_left[NUM_CARGO];
for (uint i = 0; i < NUM_CARGO; i++) cargo_left[i] = st->goods[i].cargo.Count();
- std::list<Vehicle *>::iterator iter;
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
Vehicle *v = *iter;
if (!(v->vehstatus & (VS_STOPPED | VS_CRASHED))) LoadUnloadVehicle(v, cargo_left);
+ if (v == last_loading) break;
}
/* Call the production machinery of industries */