(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
--- a/src/economy.cpp Fri Apr 20 07:51:20 2007 +0000
+++ b/src/economy.cpp Fri Apr 20 08:00:30 2007 +0000
@@ -1331,7 +1331,6 @@
static bool LoadWait(const Vehicle* v, const Vehicle* u)
{
const Vehicle *w;
- const Vehicle *x;
bool has_any_cargo = false;
if (!(u->current_order.flags & OF_FULL_LOAD)) return false;
@@ -1346,12 +1345,11 @@
}
}
- FOR_ALL_VEHICLES(x) {
- if ((x->type != VEH_TRAIN || IsFrontEngine(x)) && // for all locs
- u->last_station_visited == x->last_station_visited && // at the same station
- !(x->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
- x->current_order.type == OT_LOADING && // loading
- u != x) { // not itself
+ const Station *st = GetStation(u->last_station_visited);
+ std::list<Vehicle *>::const_iterator iter;
+ for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
+ const Vehicle *x = *iter;
+ if (!(x->vehstatus & (VS_STOPPED | VS_CRASHED)) && u != x) {
bool other_has_any_cargo = false;
bool has_space_for_same_type = false;
bool other_has_same_type = false;
--- a/src/openttd.cpp Fri Apr 20 07:51:20 2007 +0000
+++ b/src/openttd.cpp Fri Apr 20 08:00:30 2007 +0000
@@ -1926,6 +1926,18 @@
}
}
+ if (CheckSavegameVersion(57)) {
+ Vehicle *v;
+ /* Added a FIFO queue of vehicles loading at stations */
+ FOR_ALL_VEHICLES(v) {
+ if ((v->type != VEH_TRAIN || IsFrontEngine(v)) && // for all locs
+ !(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
+ v->current_order.type == OT_LOADING) { // loading
+ GetStation(v->last_station_visited)->loading_vehicles.push_back(v);
+ }
+ }
+ }
+
return true;
}
--- a/src/station.h Fri Apr 20 07:51:20 2007 +0000
+++ b/src/station.h Fri Apr 20 08:00:30 2007 +0000
@@ -11,6 +11,7 @@
#include "sprite.h"
#include "tile.h"
#include "newgrf_station.h"
+#include <list>
static const StationID INVALID_STATION = 0xFFFF;
static const byte INITIAL_STATION_RATING = 175;
@@ -157,6 +158,7 @@
StationID index;
byte last_vehicle_type;
+ std::list<Vehicle *> loading_vehicles;
GoodsEntry goods[NUM_CARGO];
uint16 random_bits;
--- a/src/station_cmd.cpp Fri Apr 20 07:51:20 2007 +0000
+++ b/src/station_cmd.cpp Fri Apr 20 08:00:30 2007 +0000
@@ -2795,6 +2795,8 @@
SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, 27, SL_MAX_VERSION),
SLE_CONDVAR(Station, num_specs, SLE_UINT8, 27, SL_MAX_VERSION),
+ SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, 57, SL_MAX_VERSION),
+
// reserve extra space in savegame here. (currently 32 bytes)
SLE_CONDNULL(32, 2, SL_MAX_VERSION),
--- a/src/vehicle.cpp Fri Apr 20 07:51:20 2007 +0000
+++ b/src/vehicle.cpp Fri Apr 20 08:00:30 2007 +0000
@@ -570,6 +570,10 @@
void DestroyVehicle(Vehicle *v)
{
+ if (v->last_station_visited != INVALID_STATION) {
+ GetStation(v->last_station_visited)->loading_vehicles.remove(v);
+ }
+
if (IsEngineCountable(v)) {
GetPlayer(v->owner)->num_engines[v->engine_type]--;
if (v->owner == _local_player) InvalidateAutoreplaceWindow(v->engine_type);
@@ -2903,6 +2907,7 @@
{
assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP);
current_order.type = OT_LOADING;
+ GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
}
void Vehicle::LeaveStation()
@@ -2911,4 +2916,5 @@
assert(current_order.type == OT_LOADING);
current_order.type = OT_LEAVESTATION;
current_order.flags = 0;
+ GetStation(this->last_station_visited)->loading_vehicles.push_back(this);
}