Changeset - r6500:e51485d4d926
[Not reviewed]
master
0 5 0
rubidium - 17 years ago 2007-04-20 08:00:30
rubidium@openttd.org
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
5 files changed with 27 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1331,7 +1331,6 @@ static int32 DeliverGoods(int num_pieces
 
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, c
 
		}
 
	}
 

	
 
	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;
src/openttd.cpp
Show inline comments
 
@@ -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;
 
}
 

	
src/station.h
Show inline comments
 
@@ -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;
src/station_cmd.cpp
Show inline comments
 
@@ -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),
 

	
src/vehicle.cpp
Show inline comments
 
@@ -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);
 
}
0 comments (0 inline, 0 general)