Add setting for linkgraph times to be in non daylength scaled days.
Savegame format change for link graph jobs. Change link graph scheduler to support more than one operation per day, on _date_fract ticks other than SPAWN_JOIN_TICK.
This commit is contained in:
@@ -54,7 +54,7 @@ void FlowMapper::Run(LinkGraphJob &job) const
|
||||
/* Scale by time the graph has been running without being compressed. Add 1 to avoid
|
||||
* division by 0 if spawn date == last compression date. This matches
|
||||
* LinkGraph::Monthly(). */
|
||||
uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression() + 1;
|
||||
uint runtime = (job.StartDateTicks() / DAY_TICKS) - job.LastCompression() + 1;
|
||||
for (FlowStatMap::iterator i = flows.begin(); i != flows.end(); ++i) {
|
||||
i->second.ScaleToMonthly(runtime);
|
||||
}
|
||||
|
@@ -28,6 +28,15 @@ INSTANTIATE_POOL_METHODS(LinkGraphJob)
|
||||
*/
|
||||
/* static */ Path *Path::invalid_path = new Path(INVALID_NODE, true);
|
||||
|
||||
static DateTicks GetLinkGraphJobJoinDateTicks()
|
||||
{
|
||||
DateTicks ticks = _settings_game.linkgraph.recalc_time * DAY_TICKS;
|
||||
if (_settings_game.linkgraph.recalc_not_scaled_by_daylength) {
|
||||
ticks /= _settings_game.economy.day_length_factor;
|
||||
}
|
||||
return ticks + (_date * DAY_TICKS) + _date_fract;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a link graph job from a link graph. The link graph will be copied so
|
||||
* that the calculations don't interfer with the normal operations on the
|
||||
@@ -40,7 +49,8 @@ LinkGraphJob::LinkGraphJob(const LinkGraph &orig) :
|
||||
link_graph(orig),
|
||||
settings(_settings_game.linkgraph),
|
||||
thread(NULL),
|
||||
join_date(_date + _settings_game.linkgraph.recalc_time),
|
||||
join_date_ticks(GetLinkGraphJobJoinDateTicks()),
|
||||
start_date_ticks((_date * DAY_TICKS) + _date_fract),
|
||||
job_completed(false)
|
||||
{
|
||||
}
|
||||
|
@@ -54,13 +54,15 @@ private:
|
||||
typedef SmallMatrix<EdgeAnnotation> EdgeAnnotationMatrix;
|
||||
|
||||
friend const SaveLoad *GetLinkGraphJobDesc();
|
||||
friend void GetLinkGraphJobDayLengthScaleAfterLoad(LinkGraphJob *lgj);
|
||||
friend class LinkGraphSchedule;
|
||||
|
||||
protected:
|
||||
const LinkGraph link_graph; ///< Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
|
||||
const LinkGraphSettings settings; ///< Copy of _settings_game.linkgraph at spawn time.
|
||||
ThreadObject *thread; ///< Thread the job is running in or NULL if it's running in the main thread.
|
||||
Date join_date; ///< Date when the job is to be joined.
|
||||
DateTicks join_date_ticks; ///< Date when the job is to be joined.
|
||||
DateTicks start_date_ticks; ///< Date when the job was started.
|
||||
NodeAnnotationVector nodes; ///< Extra node data necessary for link graph calculation.
|
||||
EdgeAnnotationMatrix edges; ///< Extra edge data necessary for link graph calculation.
|
||||
bool job_completed; ///< Is the job still running. This is accessed by multiple threads and is permitted to be spuriously incorrect.
|
||||
@@ -268,7 +270,7 @@ public:
|
||||
* settings have to be brutally const-casted in order to populate them.
|
||||
*/
|
||||
LinkGraphJob() : settings(_settings_game.linkgraph), thread(NULL),
|
||||
join_date(INVALID_DATE), job_completed(false) {}
|
||||
join_date_ticks(INVALID_DATE), start_date_ticks(INVALID_DATE), job_completed(false) {}
|
||||
|
||||
LinkGraphJob(const LinkGraph &orig);
|
||||
~LinkGraphJob();
|
||||
@@ -279,21 +281,28 @@ public:
|
||||
|
||||
/**
|
||||
* Check if job is supposed to be finished.
|
||||
* @param tick_offset Optional number of ticks to add to the current date
|
||||
* @return True if job should be finished by now, false if not.
|
||||
*/
|
||||
inline bool IsFinished() const { return this->join_date <= _date; }
|
||||
inline bool IsFinished(int tick_offset = 0) const { return this->join_date_ticks <= (_date * DAY_TICKS) + _date_fract + tick_offset; }
|
||||
|
||||
/**
|
||||
* Get the date when the job should be finished.
|
||||
* @return Join date.
|
||||
*/
|
||||
inline Date JoinDate() const { return join_date; }
|
||||
inline DateTicks JoinDateTicks() const { return join_date_ticks; }
|
||||
|
||||
/**
|
||||
* Get the date when the job was started.
|
||||
* @return Start date.
|
||||
*/
|
||||
inline DateTicks StartDateTicks() const { return start_date_ticks; }
|
||||
|
||||
/**
|
||||
* Change the join date on date cheating.
|
||||
* @param interval Number of days to add.
|
||||
*/
|
||||
inline void ShiftJoinDate(int interval) { this->join_date += interval; }
|
||||
inline void ShiftJoinDate(int interval) { this->join_date_ticks += interval * DAY_TICKS; }
|
||||
|
||||
/**
|
||||
* Get the link graph settings for this component.
|
||||
|
@@ -56,7 +56,7 @@ void LinkGraphSchedule::SpawnNext()
|
||||
bool LinkGraphSchedule::IsJoinWithUnfinishedJobDue() const
|
||||
{
|
||||
for (JobList::const_iterator it = this->running.begin(); it != this->running.end(); ++it) {
|
||||
if (!((*it)->IsFinished())) {
|
||||
if (!((*it)->IsFinished(1))) {
|
||||
/* job is not due to be joined yet */
|
||||
return false;
|
||||
}
|
||||
@@ -187,13 +187,19 @@ void StateGameLoop_LinkGraphPauseControl()
|
||||
if (!LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
|
||||
DoCommandP(0, PM_PAUSED_LINK_GRAPH, 0, CMD_PAUSE);
|
||||
}
|
||||
} else if (_pause_mode == PM_UNPAUSED && _tick_skip_counter == 0 &&
|
||||
_date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 1) {
|
||||
if (_date % _settings_game.linkgraph.recalc_interval == _settings_game.linkgraph.recalc_interval / 2) {
|
||||
/* perform check one _date_fract tick before we would join */
|
||||
if (LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
|
||||
DoCommandP(0, PM_PAUSED_LINK_GRAPH, 1, CMD_PAUSE);
|
||||
}
|
||||
} else if (_pause_mode == PM_UNPAUSED && _tick_skip_counter == 0) {
|
||||
if (!_settings_game.linkgraph.recalc_not_scaled_by_daylength || _settings_game.economy.day_length_factor == 1) {
|
||||
if (_date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK - 1) return;
|
||||
if (_date % _settings_game.linkgraph.recalc_interval != _settings_game.linkgraph.recalc_interval / 2) return;
|
||||
} else {
|
||||
int date_ticks = ((_date * DAY_TICKS) + _date_fract - (LinkGraphSchedule::SPAWN_JOIN_TICK - 1));
|
||||
int interval = (_settings_game.linkgraph.recalc_interval * DAY_TICKS / _settings_game.economy.day_length_factor);
|
||||
if (date_ticks % interval != interval / 2) return;
|
||||
}
|
||||
|
||||
/* perform check one _date_fract tick before we would join */
|
||||
if (LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
|
||||
DoCommandP(0, PM_PAUSED_LINK_GRAPH, 1, CMD_PAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,11 +210,19 @@ void StateGameLoop_LinkGraphPauseControl()
|
||||
*/
|
||||
void OnTick_LinkGraph()
|
||||
{
|
||||
if (_date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
|
||||
Date offset = _date % _settings_game.linkgraph.recalc_interval;
|
||||
int offset;
|
||||
int interval;
|
||||
if (!_settings_game.linkgraph.recalc_not_scaled_by_daylength || _settings_game.economy.day_length_factor == 1) {
|
||||
if (_date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
|
||||
interval = _settings_game.linkgraph.recalc_interval;
|
||||
offset = _date % interval;
|
||||
} else {
|
||||
interval = (_settings_game.linkgraph.recalc_interval * DAY_TICKS / _settings_game.economy.day_length_factor);
|
||||
offset = ((_date * DAY_TICKS) + _date_fract - LinkGraphSchedule::SPAWN_JOIN_TICK) % interval;
|
||||
}
|
||||
if (offset == 0) {
|
||||
LinkGraphSchedule::instance.SpawnNext();
|
||||
} else if (offset == _settings_game.linkgraph.recalc_interval / 2) {
|
||||
} else if (offset == interval / 2) {
|
||||
LinkGraphSchedule::instance.JoinNext();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user