Codechange: move all date-related variables inside the timer (#10706)
This commit is contained in:
@@ -65,7 +65,7 @@ void LinkGraph::ShiftDates(int interval)
|
||||
|
||||
void LinkGraph::Compress()
|
||||
{
|
||||
this->last_compression = (_date + this->last_compression) / 2;
|
||||
this->last_compression = (TimerGameCalendar::date + this->last_compression) / 2;
|
||||
for (NodeID node1 = 0; node1 < this->Size(); ++node1) {
|
||||
this->nodes[node1].supply /= 2;
|
||||
for (BaseEdge &edge : this->nodes[node1].edges) {
|
||||
@@ -89,8 +89,8 @@ void LinkGraph::Compress()
|
||||
*/
|
||||
void LinkGraph::Merge(LinkGraph *other)
|
||||
{
|
||||
Date age = _date - this->last_compression + 1;
|
||||
Date other_age = _date - other->last_compression + 1;
|
||||
Date age = TimerGameCalendar::date - this->last_compression + 1;
|
||||
Date other_age = TimerGameCalendar::date - other->last_compression + 1;
|
||||
NodeID first = this->Size();
|
||||
for (NodeID node1 = 0; node1 < other->Size(); ++node1) {
|
||||
Station *st = Station::Get(other->nodes[node1].station);
|
||||
@@ -172,8 +172,8 @@ void LinkGraph::BaseNode::AddEdge(NodeID to, uint capacity, uint usage, uint32 t
|
||||
edge.capacity = capacity;
|
||||
edge.usage = usage;
|
||||
edge.travel_time_sum = static_cast<uint64>(travel_time) * capacity;
|
||||
if (mode & EUM_UNRESTRICTED) edge.last_unrestricted_update = _date;
|
||||
if (mode & EUM_RESTRICTED) edge.last_restricted_update = _date;
|
||||
if (mode & EUM_UNRESTRICTED) edge.last_unrestricted_update = TimerGameCalendar::date;
|
||||
if (mode & EUM_RESTRICTED) edge.last_restricted_update = TimerGameCalendar::date;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,8 +239,8 @@ void LinkGraph::BaseEdge::Update(uint capacity, uint usage, uint32 travel_time,
|
||||
}
|
||||
this->usage = std::max(this->usage, usage);
|
||||
}
|
||||
if (mode & EUM_UNRESTRICTED) this->last_unrestricted_update = _date;
|
||||
if (mode & EUM_RESTRICTED) this->last_restricted_update = _date;
|
||||
if (mode & EUM_UNRESTRICTED) this->last_unrestricted_update = TimerGameCalendar::date;
|
||||
if (mode & EUM_RESTRICTED) this->last_restricted_update = TimerGameCalendar::date;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -14,7 +14,7 @@
|
||||
#include "../core/smallmap_type.hpp"
|
||||
#include "../station_base.h"
|
||||
#include "../cargotype.h"
|
||||
#include "../date_func.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../saveload/saveload.h"
|
||||
#include "linkgraph_type.h"
|
||||
#include <utility>
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
void UpdateSupply(uint supply)
|
||||
{
|
||||
this->supply += supply;
|
||||
this->last_update = _date;
|
||||
this->last_update = TimerGameCalendar::date;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
* Real constructor.
|
||||
* @param cargo Cargo the link graph is about.
|
||||
*/
|
||||
LinkGraph(CargoID cargo) : cargo(cargo), last_compression(_date) {}
|
||||
LinkGraph(CargoID cargo) : cargo(cargo), last_compression(TimerGameCalendar::date) {}
|
||||
|
||||
void Init(uint size);
|
||||
void ShiftDates(int interval);
|
||||
@@ -249,7 +249,7 @@ public:
|
||||
*/
|
||||
inline uint Monthly(uint base) const
|
||||
{
|
||||
return base * 30 / (_date - this->last_compression + 1);
|
||||
return base * 30 / (TimerGameCalendar::date - this->last_compression + 1);
|
||||
}
|
||||
|
||||
NodeID AddNode(const Station *st);
|
||||
|
@@ -37,7 +37,7 @@ LinkGraphJob::LinkGraphJob(const LinkGraph &orig) :
|
||||
* This is on purpose. */
|
||||
link_graph(orig),
|
||||
settings(_settings_game.linkgraph),
|
||||
join_date(_date + (_settings_game.linkgraph.recalc_time / SECONDS_PER_DAY)),
|
||||
join_date(TimerGameCalendar::date + (_settings_game.linkgraph.recalc_time / SECONDS_PER_DAY)),
|
||||
job_completed(false),
|
||||
job_aborted(false)
|
||||
{
|
||||
|
@@ -212,7 +212,7 @@ public:
|
||||
* Check if job is supposed to be finished.
|
||||
* @return True if job should be finished by now, false if not.
|
||||
*/
|
||||
inline bool IsScheduledToBeJoined() const { return this->join_date <= _date; }
|
||||
inline bool IsScheduledToBeJoined() const { return this->join_date <= TimerGameCalendar::date; }
|
||||
|
||||
/**
|
||||
* Get the date when the job should be finished.
|
||||
|
@@ -163,10 +163,10 @@ LinkGraphSchedule::~LinkGraphSchedule()
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause the game if in 2 _date_fract ticks, we would do a join with the next
|
||||
* Pause the game if in 2 TimerGameCalendar::date_fract ticks, we would do a join with the next
|
||||
* link graph job, but it is still running.
|
||||
* The check is done 2 _date_fract ticks early instead of 1, as in multiplayer
|
||||
* calls to DoCommandP are executed after a delay of 1 _date_fract tick.
|
||||
* The check is done 2 TimerGameCalendar::date_fract ticks early instead of 1, as in multiplayer
|
||||
* calls to DoCommandP are executed after a delay of 1 TimerGameCalendar::date_fract tick.
|
||||
* If we previously paused, unpause if the job is now ready to be joined with.
|
||||
*/
|
||||
void StateGameLoop_LinkGraphPauseControl()
|
||||
@@ -177,10 +177,10 @@ void StateGameLoop_LinkGraphPauseControl()
|
||||
Command<CMD_PAUSE>::Post(PM_PAUSED_LINK_GRAPH, false);
|
||||
}
|
||||
} else if (_pause_mode == PM_UNPAUSED &&
|
||||
_date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 &&
|
||||
_date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2 &&
|
||||
TimerGameCalendar::date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 &&
|
||||
TimerGameCalendar::date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2 &&
|
||||
LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
|
||||
/* Perform check two _date_fract ticks before we would join, to make
|
||||
/* Perform check two TimerGameCalendar::date_fract ticks before we would join, to make
|
||||
* sure it also works in multiplayer. */
|
||||
Command<CMD_PAUSE>::Post(PM_PAUSED_LINK_GRAPH, true);
|
||||
}
|
||||
@@ -204,8 +204,8 @@ void AfterLoad_LinkGraphPauseControl()
|
||||
*/
|
||||
void OnTick_LinkGraph()
|
||||
{
|
||||
if (_date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
|
||||
Date offset = _date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY);
|
||||
if (TimerGameCalendar::date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
|
||||
Date offset = TimerGameCalendar::date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY);
|
||||
if (offset == 0) {
|
||||
LinkGraphSchedule::instance.SpawnNext();
|
||||
} else if (offset == (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY) / 2) {
|
||||
|
Reference in New Issue
Block a user