Codechange: Move date consts and functions to CalendarTime and TimerGameCalendar classes
This commit is contained in:
@@ -50,7 +50,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(). */
|
||||
auto runtime = job.JoinDate() - job.Settings().recalc_time / SECONDS_PER_DAY - job.LastCompression() + 1;
|
||||
auto runtime = job.JoinDate() - job.Settings().recalc_time / CalendarTime::SECONDS_PER_DAY - job.LastCompression() + 1;
|
||||
for (auto &it : flows) {
|
||||
it.second.ScaleToMonthly(static_cast<int32_t>(runtime));
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ LinkGraph::BaseNode::BaseNode(TileIndex xy, StationID st, uint demand)
|
||||
this->supply = 0;
|
||||
this->demand = demand;
|
||||
this->station = st;
|
||||
this->last_update = INVALID_DATE;
|
||||
this->last_update = CalendarTime::INVALID_DATE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,8 +40,8 @@ LinkGraph::BaseEdge::BaseEdge(NodeID dest_node)
|
||||
this->capacity = 0;
|
||||
this->usage = 0;
|
||||
this->travel_time_sum = 0;
|
||||
this->last_unrestricted_update = INVALID_DATE;
|
||||
this->last_restricted_update = INVALID_DATE;
|
||||
this->last_unrestricted_update = CalendarTime::INVALID_DATE;
|
||||
this->last_restricted_update = CalendarTime::INVALID_DATE;
|
||||
this->dest_node = dest_node;
|
||||
}
|
||||
|
||||
@@ -55,10 +55,10 @@ void LinkGraph::ShiftDates(TimerGameCalendar::Date interval)
|
||||
this->last_compression += interval;
|
||||
for (NodeID node1 = 0; node1 < this->Size(); ++node1) {
|
||||
BaseNode &source = this->nodes[node1];
|
||||
if (source.last_update != INVALID_DATE) source.last_update += interval;
|
||||
if (source.last_update != CalendarTime::INVALID_DATE) source.last_update += interval;
|
||||
for (BaseEdge &edge : this->nodes[node1].edges) {
|
||||
if (edge.last_unrestricted_update != INVALID_DATE) edge.last_unrestricted_update += interval;
|
||||
if (edge.last_restricted_update != INVALID_DATE) edge.last_restricted_update += interval;
|
||||
if (edge.last_unrestricted_update != CalendarTime::INVALID_DATE) edge.last_unrestricted_update += interval;
|
||||
if (edge.last_restricted_update != CalendarTime::INVALID_DATE) edge.last_restricted_update += interval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -63,8 +63,8 @@ public:
|
||||
TimerGameCalendar::Date LastUpdate() const { return std::max(this->last_unrestricted_update, this->last_restricted_update); }
|
||||
|
||||
void Update(uint capacity, uint usage, uint32_t time, EdgeUpdateMode mode);
|
||||
void Restrict() { this->last_unrestricted_update = INVALID_DATE; }
|
||||
void Release() { this->last_restricted_update = INVALID_DATE; }
|
||||
void Restrict() { this->last_unrestricted_update = CalendarTime::INVALID_DATE; }
|
||||
void Release() { this->last_restricted_update = CalendarTime::INVALID_DATE; }
|
||||
|
||||
/** Comparison operator based on \c dest_node. */
|
||||
bool operator <(const BaseEdge &rhs) const
|
||||
|
@@ -37,7 +37,7 @@ LinkGraphJob::LinkGraphJob(const LinkGraph &orig) :
|
||||
* This is on purpose. */
|
||||
link_graph(orig),
|
||||
settings(_settings_game.linkgraph),
|
||||
join_date(TimerGameCalendar::date + (_settings_game.linkgraph.recalc_time / SECONDS_PER_DAY)),
|
||||
join_date(TimerGameCalendar::date + (_settings_game.linkgraph.recalc_time / CalendarTime::SECONDS_PER_DAY)),
|
||||
job_completed(false),
|
||||
job_aborted(false)
|
||||
{
|
||||
@@ -131,14 +131,14 @@ LinkGraphJob::~LinkGraphJob()
|
||||
if (st2 == nullptr || st2->goods[this->Cargo()].link_graph != this->link_graph.index ||
|
||||
st2->goods[this->Cargo()].node != dest_id ||
|
||||
!(*lg)[node_id].HasEdgeTo(dest_id) ||
|
||||
(*lg)[node_id][dest_id].LastUpdate() == INVALID_DATE) {
|
||||
(*lg)[node_id][dest_id].LastUpdate() == CalendarTime::INVALID_DATE) {
|
||||
/* Edge has been removed. Delete flows. */
|
||||
StationIDStack erased = flows.DeleteFlows(to);
|
||||
/* Delete old flows for source stations which have been deleted
|
||||
* from the new flows. This avoids flow cycles between old and
|
||||
* new flows. */
|
||||
while (!erased.IsEmpty()) ge.flows.erase(erased.Pop());
|
||||
} else if ((*lg)[node_id][dest_id].last_restricted_update == INVALID_DATE) {
|
||||
} else if ((*lg)[node_id][dest_id].last_restricted_update == CalendarTime::INVALID_DATE) {
|
||||
/* Edge is fully restricted. */
|
||||
flows.RestrictFlows(to);
|
||||
}
|
||||
|
@@ -178,7 +178,7 @@ public:
|
||||
* settings have to be brutally const-casted in order to populate them.
|
||||
*/
|
||||
LinkGraphJob() : settings(_settings_game.linkgraph),
|
||||
join_date(INVALID_DATE), job_completed(false), job_aborted(false) {}
|
||||
join_date(CalendarTime::INVALID_DATE), job_completed(false), job_aborted(false) {}
|
||||
|
||||
LinkGraphJob(const LinkGraph &orig);
|
||||
~LinkGraphJob();
|
||||
|
@@ -178,7 +178,7 @@ void StateGameLoop_LinkGraphPauseControl()
|
||||
}
|
||||
} else if (_pause_mode == PM_UNPAUSED &&
|
||||
TimerGameCalendar::date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 &&
|
||||
static_cast<int32_t>(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2 &&
|
||||
static_cast<int32_t>(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2 &&
|
||||
LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
|
||||
/* Perform check two TimerGameCalendar::date_fract ticks before we would join, to make
|
||||
* sure it also works in multiplayer. */
|
||||
@@ -205,10 +205,10 @@ void AfterLoad_LinkGraphPauseControl()
|
||||
void OnTick_LinkGraph()
|
||||
{
|
||||
if (TimerGameCalendar::date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
|
||||
TimerGameCalendar::Date offset = static_cast<int32_t>(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY);
|
||||
TimerGameCalendar::Date offset = static_cast<int32_t>(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY);
|
||||
if (offset == 0) {
|
||||
LinkGraphSchedule::instance.SpawnNext();
|
||||
} else if (offset == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2) {
|
||||
} else if (offset == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2) {
|
||||
if (!_networking || _network_server) {
|
||||
PerformanceMeasurer::SetInactive(PFE_GL_LINKGRAPH);
|
||||
LinkGraphSchedule::instance.JoinNext();
|
||||
|
Reference in New Issue
Block a user