Link graph: Fix incorrect job start/join dates when loading upstream saves
This commit is contained in:
@@ -201,39 +201,6 @@ SaveLoadTable GetLinkGraphScheduleDesc()
|
|||||||
return schedule_desc;
|
return schedule_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Spawn the threads for running link graph calculations.
|
|
||||||
* Has to be done after loading as the cargo classes might have changed.
|
|
||||||
*/
|
|
||||||
void AfterLoadLinkGraphs()
|
|
||||||
{
|
|
||||||
if (IsSavegameVersionBefore(SLV_191)) {
|
|
||||||
for (LinkGraph *lg : LinkGraph::Iterate()) {
|
|
||||||
for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
|
|
||||||
const Station *st = Station::GetIfValid((*lg)[node_id].Station());
|
|
||||||
if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
|
||||||
LinkGraph *lg = &(const_cast<LinkGraph &>(lgj->Graph()));
|
|
||||||
for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
|
|
||||||
const Station *st = Station::GetIfValid((*lg)[node_id].Station());
|
|
||||||
if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
|
||||||
GetLinkGraphJobDayLengthScaleAfterLoad(lgj);
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkGraphSchedule::instance.SpawnAll();
|
|
||||||
|
|
||||||
if (!_networking || _network_server) {
|
|
||||||
AfterLoad_LinkGraphPauseControl();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All link graphs.
|
* All link graphs.
|
||||||
*/
|
*/
|
||||||
@@ -286,6 +253,8 @@ struct LGRJChunkHandler : ChunkHandler {
|
|||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
LinkGraphJob *lgj = new (index) LinkGraphJob();
|
LinkGraphJob *lgj = new (index) LinkGraphJob();
|
||||||
SlObject(lgj, slt);
|
SlObject(lgj, slt);
|
||||||
|
|
||||||
|
GetLinkGraphJobDayLengthScaleAfterLoad(lgj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,7 +41,16 @@ void GetLinkGraphJobDayLengthScaleAfterLoad(LinkGraphJob *lgj)
|
|||||||
{
|
{
|
||||||
lgj->join_date_ticks *= DAY_TICKS;
|
lgj->join_date_ticks *= DAY_TICKS;
|
||||||
lgj->join_date_ticks += LinkGraphSchedule::SPAWN_JOIN_TICK;
|
lgj->join_date_ticks += LinkGraphSchedule::SPAWN_JOIN_TICK;
|
||||||
lgj->start_date_ticks = lgj->join_date_ticks - (lgj->Settings().recalc_time * DAY_TICKS);
|
|
||||||
|
uint recalc_scale;
|
||||||
|
if (IsSavegameVersionBefore(SLV_LINKGRAPH_SECONDS) && SlXvIsFeatureMissing(XSLFI_LINKGRAPH_DAY_SCALE, 3)) {
|
||||||
|
/* recalc time is in days */
|
||||||
|
recalc_scale = DAY_TICKS;
|
||||||
|
} else {
|
||||||
|
/* recalc time is in seconds */
|
||||||
|
recalc_scale = DAY_TICKS / SECONDS_PER_DAY;
|
||||||
|
}
|
||||||
|
lgj->start_date_ticks = lgj->join_date_ticks - (lgj->Settings().recalc_time * recalc_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user