(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.

This commit is contained in:
rubidium 2007-04-20 08:00:30 +00:00
parent a8350e5fdf
commit fdf86bb4a2
5 changed files with 27 additions and 7 deletions

View File

@ -1331,7 +1331,6 @@ static int32 DeliverGoods(int num_pieces, CargoID cargo_type, StationID source,
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 @@ static bool LoadWait(const Vehicle* v, const Vehicle* u)
}
}
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;

View File

@ -1926,6 +1926,18 @@ bool AfterLoadGame()
}
}
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;
}

View File

@ -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 @@ struct Station {
StationID index;
byte last_vehicle_type;
std::list<Vehicle *> loading_vehicles;
GoodsEntry goods[NUM_CARGO];
uint16 random_bits;

View File

@ -2795,6 +2795,8 @@ static const SaveLoad _station_desc[] = {
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),

View File

@ -570,6 +570,10 @@ bool IsEngineCountable(const Vehicle *v)
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 @@ void Vehicle::BeginLoading()
{
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 @@ void Vehicle::LeaveStation()
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);
}