Codechange: Define Date/Year/Month/Day within TimerGameCalendar class

This commit is contained in:
Tyler Trahan
2023-04-24 14:33:18 -04:00
parent 20d2558f1b
commit 930f0a16d8
68 changed files with 216 additions and 182 deletions

View File

@@ -89,8 +89,8 @@ void LinkGraph::Compress()
*/
void LinkGraph::Merge(LinkGraph *other)
{
Date age = TimerGameCalendar::date - this->last_compression + 1;
Date other_age = TimerGameCalendar::date - other->last_compression + 1;
TimerGameCalendar::Date age = TimerGameCalendar::date - this->last_compression + 1;
TimerGameCalendar::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);

View File

@@ -14,6 +14,7 @@
#include "../core/smallmap_type.hpp"
#include "../station_base.h"
#include "../cargotype.h"
#include "../date_type.h"
#include "../timer/timer_game_calendar.h"
#include "../saveload/saveload.h"
#include "linkgraph_type.h"
@@ -44,8 +45,8 @@ public:
uint capacity; ///< Capacity of the link.
uint usage; ///< Usage of the link.
uint64 travel_time_sum; ///< Sum of the travel times of the link, in ticks.
Date last_unrestricted_update; ///< When the unrestricted part of the link was last updated.
Date last_restricted_update; ///< When the restricted part of the link was last updated.
TimerGameCalendar::Date last_unrestricted_update; ///< When the unrestricted part of the link was last updated.
TimerGameCalendar::Date last_restricted_update; ///< When the restricted part of the link was last updated.
NodeID dest_node; ///< Destination of the edge.
BaseEdge(NodeID dest_node = INVALID_NODE);
@@ -60,7 +61,7 @@ public:
* Get the date of the last update to any part of the edge's capacity.
* @return Last update.
*/
Date LastUpdate() const { return std::max(this->last_unrestricted_update, this->last_restricted_update); }
TimerGameCalendar::Date LastUpdate() const { return std::max(this->last_unrestricted_update, this->last_restricted_update); }
void Update(uint capacity, uint usage, uint32 time, EdgeUpdateMode mode);
void Restrict() { this->last_unrestricted_update = INVALID_DATE; }
@@ -93,7 +94,7 @@ public:
uint demand; ///< Acceptance at the station.
StationID station; ///< Station ID.
TileIndex xy; ///< Location of the station referred to by the node.
Date last_update; ///< When the supply was last updated.
TimerGameCalendar::Date last_update; ///< When the supply was last updated.
std::vector<BaseEdge> edges; ///< Sorted list of outgoing edges from this node.
@@ -234,7 +235,7 @@ public:
* Get date of last compression.
* @return Date of last compression.
*/
inline Date LastCompression() const { return this->last_compression; }
inline TimerGameCalendar::Date LastCompression() const { return this->last_compression; }
/**
* Get the cargo ID this component's link graph refers to.
@@ -263,7 +264,7 @@ protected:
friend class LinkGraphJob;
CargoID cargo; ///< Cargo of this component's link graph.
Date last_compression; ///< Last time the capacities and supplies were compressed.
TimerGameCalendar::Date last_compression; ///< Last time the capacities and supplies were compressed.
NodeVector nodes; ///< Nodes in the component.
};

View File

@@ -161,13 +161,13 @@ private:
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.
std::thread thread; ///< Thread the job is running in or a default-constructed thread if it's running in the main thread.
Date join_date; ///< Date when the job is to be joined.
NodeAnnotationVector nodes; ///< Extra node data necessary for link graph calculation.
std::atomic<bool> job_completed; ///< Is the job still running. This is accessed by multiple threads and reads may be stale.
std::atomic<bool> job_aborted; ///< Has the job been aborted. This is accessed by multiple threads and reads may be stale.
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.
std::thread thread; ///< Thread the job is running in or a default-constructed thread if it's running in the main thread.
TimerGameCalendar::Date join_date; ///< Date when the job is to be joined.
NodeAnnotationVector nodes; ///< Extra node data necessary for link graph calculation.
std::atomic<bool> job_completed; ///< Is the job still running. This is accessed by multiple threads and reads may be stale.
std::atomic<bool> job_aborted; ///< Has the job been aborted. This is accessed by multiple threads and reads may be stale.
void EraseFlows(NodeID from);
void JoinThread();
@@ -218,7 +218,7 @@ public:
* Get the date when the job should be finished.
* @return Join date.
*/
inline Date JoinDate() const { return join_date; }
inline TimerGameCalendar::Date JoinDate() const { return join_date; }
/**
* Change the join date on date cheating.
@@ -255,7 +255,7 @@ public:
* Get the date when the underlying link graph was last compressed.
* @return Compression date.
*/
inline Date LastCompression() const { return this->link_graph.LastCompression(); }
inline TimerGameCalendar::Date LastCompression() const { return this->link_graph.LastCompression(); }
/**
* Get the ID of the underlying link graph.

View File

@@ -205,7 +205,7 @@ void AfterLoad_LinkGraphPauseControl()
void OnTick_LinkGraph()
{
if (TimerGameCalendar::date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
Date offset = TimerGameCalendar::date % (_settings_game.linkgraph.recalc_interval / SECONDS_PER_DAY);
TimerGameCalendar::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) {