From 0d32cd3cc83fda6ad3726b3dedc5ad096beaac9d Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 11 Dec 2010 11:00:42 +0000 Subject: (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) --- src/economy.cpp | 28 ++++++++++++++++++++++++---- 1 file 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::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::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 */ -- cgit v1.2.3-70-g09d2