|
OpenTTD Source 20260206-master-g4d4e37dbf1
|
Class for calculation jobs to be run on link graphs. More...
#include <linkgraphjob.h>
Data Structures | |
| struct | DemandAnnotation |
| Demand between two nodes. More... | |
| struct | EdgeAnnotation |
| Annotation for a link graph edge. More... | |
| struct | NodeAnnotation |
| Annotation for a link graph node. More... | |
Public Member Functions | |
| LinkGraphJob (LinkGraphJobID index) | |
| Bare constructor, only for save/load. | |
| LinkGraphJob (LinkGraphJobID index, const LinkGraph &orig) | |
| Create a link graph job from a link graph. | |
| ~LinkGraphJob () | |
| Join the link graph job and destroy it. | |
| void | Init () |
| Initialize the link graph job: Resize nodes and edges and populate them. | |
| bool | IsJobCompleted () const |
| Check if job has actually finished. | |
| bool | IsJobAborted () const |
| Check if job has been aborted. | |
| void | AbortJob () |
| Abort job. | |
| bool | IsScheduledToBeJoined () const |
| Check if job is supposed to be finished. | |
| TimerGameEconomy::Date | JoinDate () const |
| Get the date when the job should be finished. | |
| void | ShiftJoinDate (TimerGameEconomy::Date interval) |
| Change the join date on date cheating. | |
| const LinkGraphSettings & | Settings () const |
| Get the link graph settings for this component. | |
| NodeAnnotation & | operator[] (NodeID num) |
| Get a node abstraction with the specified id. | |
| NodeID | Size () const |
| Get the size of the underlying link graph. | |
| CargoType | Cargo () const |
| Get the cargo of the underlying link graph. | |
| TimerGameEconomy::Date | LastCompression () const |
| Get the date when the underlying link graph was last compressed. | |
| LinkGraphID | LinkGraphIndex () const |
| Get the ID of the underlying link graph. | |
| const LinkGraph & | Graph () const |
| Get a reference to the underlying link graph. | |
Protected Member Functions | |
| void | EraseFlows (StationID from) |
| Erase all flows originating at a specific station. | |
| void | JoinThread () |
| Join the calling thread with this job's thread if threading is enabled. | |
| void | SpawnThread () |
| Spawn a thread if possible and run the link graph job in the thread. | |
Protected Attributes | |
| 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. | |
| TimerGameEconomy::Date | join_date = EconomyTime::INVALID_DATE |
| Date when the job is to be joined. | |
| NodeAnnotationVector | nodes {} |
| Extra node data necessary for link graph calculation. | |
| std::atomic< bool > | job_completed = false |
| Is the job still running. This is accessed by multiple threads and reads may be stale. | |
| std::atomic< bool > | job_aborted = false |
| Has the job been aborted. This is accessed by multiple threads and reads may be stale. | |
Private Types | |
| typedef std::vector< NodeAnnotation > | NodeAnnotationVector |
Friends | |
| class | LinkGraphSchedule |
| SaveLoadTable | GetLinkGraphJobDesc () |
| Get a SaveLoad array for a link graph job. | |
Class for calculation jobs to be run on link graphs.
Definition at line 29 of file linkgraphjob.h.
|
private |
Definition at line 159 of file linkgraphjob.h.
|
inline |
Bare constructor, only for save/load.
link_graph, join_date and actually settings have to be brutally const-casted in order to populate them.
Definition at line 182 of file linkgraphjob.h.
References _link_graph_job_pool, _settings_game, link_graph, and settings.
| LinkGraphJob::LinkGraphJob | ( | LinkGraphJobID | index, |
| const LinkGraph & | orig ) |
Create a link graph job from a link graph.
The link graph will be copied so that the calculations don't interfere with the normal operations on the original. The job is immediately started.
| index | Index into the LinkGraphJob pool. |
| orig | Original LinkGraph to be copied. |
Definition at line 36 of file linkgraphjob.cpp.
References _link_graph_job_pool, _settings_game, join_date, link_graph, and settings.
| LinkGraphJob::~LinkGraphJob | ( | ) |
Join the link graph job and destroy it.
Definition at line 88 of file linkgraphjob.cpp.
References _settings_game, LinkGraphJob::NodeAnnotation::base, Cargo(), GoodsEntry::ClearData(), FlowStatMap::DeleteFlows(), DT_MANUAL, LinkGraphJob::NodeAnnotation::edges, EraseFlows(), GoodsEntry::GoodsEntryData::flows, LinkGraphJob::NodeAnnotation::flows, GoodsEntry::GetData(), SpecializedStation< Station, false >::GetIfValid(), GoodsEntry::GetOrCreateData(), FlowStat::GetShares(), Station::goods, TimerGameConst< struct Economy >::INVALID_DATE, InvalidateWindowData(), IsJobAborted(), JoinThread(), GoodsEntry::link_graph, link_graph, GoodsEntry::node, nodes, RerouteCargo(), FlowStatMap::RestrictFlows(), Size(), LinkGraph::BaseNode::station, and WC_STATION_VIEW.
|
inline |
Abort job.
The job may exit early at the next available opportunity. After this method has been called the state of the job is undefined, and the only valid operation is to join the thread and discard the job data.
Definition at line 209 of file linkgraphjob.h.
|
inline |
Get the cargo of the underlying link graph.
Definition at line 252 of file linkgraphjob.h.
References LinkGraph::Cargo().
Referenced by DemandCalculator::DemandCalculator(), and ~LinkGraphJob().
|
protected |
Erase all flows originating at a specific station.
| from | StationID to erase flows for. |
Definition at line 50 of file linkgraphjob.cpp.
References Size().
Referenced by ~LinkGraphJob().
|
inline |
Get a reference to the underlying link graph.
Only use this for save/load.
Definition at line 270 of file linkgraphjob.h.
Referenced by SlLinkgraphJobProxy::Load(), and SlLinkgraphJobProxy::Save().
| void LinkGraphJob::Init | ( | ) |
Initialize the link graph job: Resize nodes and edges and populate them.
This is done after the constructor so that we can do it in the calculation thread without delaying the main game.
Definition at line 184 of file linkgraphjob.cpp.
References link_graph, nodes, and Size().
Referenced by InitHandler::Run().
|
inline |
Check if job has been aborted.
This is allowed to spuriously return false incorrectly, but is not allowed to incorrectly return true.
Definition at line 201 of file linkgraphjob.h.
Referenced by MCF1stPass::MCF1stPass(), LinkGraphSchedule::Run(), and ~LinkGraphJob().
|
inline |
Check if job has actually finished.
This is allowed to spuriously return an incorrect value.
Definition at line 194 of file linkgraphjob.h.
Referenced by LinkGraphSchedule::IsJoinWithUnfinishedJobDue().
|
inline |
Check if job is supposed to be finished.
Definition at line 215 of file linkgraphjob.h.
References TimerGameEconomy::date.
Referenced by LinkGraphSchedule::IsJoinWithUnfinishedJobDue(), and LinkGraphSchedule::JoinNext().
|
inline |
Get the date when the job should be finished.
Definition at line 221 of file linkgraphjob.h.
References join_date.
Referenced by FlowMapper::Run().
|
protected |
Join the calling thread with this job's thread if threading is enabled.
Definition at line 78 of file linkgraphjob.cpp.
References thread.
Referenced by ~LinkGraphJob().
|
inline |
Get the date when the underlying link graph was last compressed.
Definition at line 258 of file linkgraphjob.h.
References LinkGraph::LastCompression().
Referenced by FlowMapper::Run().
|
inline |
Get the ID of the underlying link graph.
Definition at line 264 of file linkgraphjob.h.
Referenced by LinkGraphSchedule::JoinNext().
|
inline |
Get a node abstraction with the specified id.
| num | ID of the node. |
Definition at line 240 of file linkgraphjob.h.
|
inline |
Get the link graph settings for this component.
Definition at line 233 of file linkgraphjob.h.
Referenced by DemandCalculator::DemandCalculator(), and FlowMapper::Run().
|
inline |
Change the join date on date cheating.
| interval | Number of days to add. |
Definition at line 227 of file linkgraphjob.h.
|
inline |
Get the size of the underlying link graph.
Definition at line 246 of file linkgraphjob.h.
References LinkGraph::Size().
Referenced by DemandCalculator::CalcDemand(), EraseFlows(), Init(), FlowMapper::Run(), and ~LinkGraphJob().
|
protected |
Spawn a thread if possible and run the link graph job in the thread.
If that's not possible run the job right now in the current thread.
Definition at line 61 of file linkgraphjob.cpp.
References LinkGraphSchedule::Run(), StartNewThread(), and thread.
Referenced by LinkGraphSchedule::SpawnNext().
|
friend |
Get a SaveLoad array for a link graph job.
The settings struct is derived from the global settings saveload array. The exact entries are calculated when the function is called the first time. It's necessary to keep a copy of the settings for each link graph job so that you can change the settings while in-game and still not mess with current link graph runs. Of course the settings have to be saved and loaded, too, to avoid desyncs.
Definition at line 180 of file linkgraph_sl.cpp.
|
friend |
Definition at line 162 of file linkgraphjob.h.
|
protected |
Has the job been aborted. This is accessed by multiple threads and reads may be stale.
Definition at line 171 of file linkgraphjob.h.
|
protected |
Is the job still running. This is accessed by multiple threads and reads may be stale.
Definition at line 170 of file linkgraphjob.h.
Referenced by LinkGraphSchedule::Run().
|
protected |
Date when the job is to be joined.
Definition at line 168 of file linkgraphjob.h.
Referenced by JoinDate(), and LinkGraphJob().
|
protected |
Link graph to by analyzed. Is copied when job is started and mustn't be modified later.
Definition at line 165 of file linkgraphjob.h.
Referenced by Init(), LinkGraphJob(), LinkGraphJob(), and ~LinkGraphJob().
|
protected |
Extra node data necessary for link graph calculation.
Definition at line 169 of file linkgraphjob.h.
Referenced by Init(), and ~LinkGraphJob().
|
protected |
Copy of _settings_game.linkgraph at spawn time.
Definition at line 166 of file linkgraphjob.h.
Referenced by LinkGraphJob(), and LinkGraphJob().
|
protected |
Thread the job is running in or a default-constructed thread if it's running in the main thread.
Definition at line 167 of file linkgraphjob.h.
Referenced by JoinThread(), and SpawnThread().