(svn r17816) -Codechange: move the CargoList invalidation-after-saveload to the function that handles the CargoPackets instead of spreading it around over the saveload files. Also add some code to validate whether the caches are valid; to be removed later when no problems turn up
This commit is contained in:
@@ -535,6 +535,14 @@ bool AfterLoadGame()
|
||||
/* Connect front and rear engines of multiheaded trains */
|
||||
ConnectMultiheadedTrains();
|
||||
|
||||
/* Fix the CargoPackets *and* fix the caches of CargoLists.
|
||||
* If this isn't done before Stations and especially Vehicles are
|
||||
* running their AfterLoad we might get in trouble. In the case of
|
||||
* vehicles we could give the wrong (cached) count of items in a
|
||||
* vehicle which causes different results when getting their caches
|
||||
* filled; and that could eventually lead to desyncs. */
|
||||
CargoPacket::AfterLoad();
|
||||
|
||||
/* Update all vehicles */
|
||||
AfterLoadVehicles(true);
|
||||
|
||||
@@ -1226,8 +1234,6 @@ bool AfterLoadGame()
|
||||
}
|
||||
}
|
||||
|
||||
CargoPacket::AfterLoad();
|
||||
|
||||
if (CheckSavegameVersion(45)) {
|
||||
Vehicle *v;
|
||||
/* Originally just the fact that some cargo had been paid for was
|
||||
@@ -1237,7 +1243,6 @@ bool AfterLoadGame()
|
||||
* amount that has been paid is stored. */
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
ClrBit(v->vehicle_flags, 2);
|
||||
v->cargo.InvalidateCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,6 @@
|
||||
cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
|
||||
cp->loaded_at_xy = cp->source_xy;
|
||||
}
|
||||
v->cargo.InvalidateCache();
|
||||
}
|
||||
|
||||
/* Store position of the station where the goods come from, so there
|
||||
@@ -63,6 +62,19 @@
|
||||
if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
|
||||
}
|
||||
}
|
||||
|
||||
if (!CheckSavegameVersion(68)) {
|
||||
/* Only since version 68 we have cargo packets. Savegames from before used
|
||||
* 'new CargoPacket' + cargolist.Append so their caches are already
|
||||
* correct and do not need rebuilding. */
|
||||
Vehicle *v;
|
||||
FOR_ALL_VEHICLES(v) v->cargo.InvalidateCache();
|
||||
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -98,10 +98,6 @@ void AfterLoadStations()
|
||||
st->speclist[i].spec = GetCustomStationSpecByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
|
||||
}
|
||||
|
||||
if (Station::IsExpected(st)) {
|
||||
for (CargoID c = 0; c < NUM_CARGO; c++) Station::From(st)->goods[c].cargo.InvalidateCache();
|
||||
}
|
||||
|
||||
StationUpdateAnimTriggers(st);
|
||||
}
|
||||
}
|
||||
|
@@ -252,8 +252,6 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
v->first = NULL;
|
||||
if (v->type == VEH_TRAIN) Train::From(v)->tcache.first_engine = INVALID_ENGINE;
|
||||
if (v->type == VEH_ROAD) RoadVehicle::From(v)->rcache.first_engine = INVALID_ENGINE;
|
||||
|
||||
v->cargo.InvalidateCache();
|
||||
}
|
||||
|
||||
/* AfterLoadVehicles may also be called in case of NewGRF reload, in this
|
||||
|
Reference in New Issue
Block a user