Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends

LinkGraph Class Reference

A link graph, inheriting one job. More...

#include <linkgraph.h>

Inheritance diagram for LinkGraph:
LinkGraphJob LinkGraphComponent

Public Member Functions

 LinkGraph ()
 Create a link graph.
void Init (CargoID cargo)
 (Re-)Initialize the link graph: join all jobs and set current_station_id and cargo to their start values.
void NextComponent ()
 Looks for a suitable station to create the next link graph component from.
void Join ()
 Merge the current job's results into the main game state.

Static Public Attributes

static const uint COMPONENTS_JOIN_TICK = 21
 Tick when jobs are joined every day.
static const uint COMPONENTS_SPAWN_TICK = 58
 Tick when jobs are spawned every day.

Private Member Functions

void CreateComponent (Station *first)
 1.

Private Attributes

StationID current_station_id
 ID of the last station examined while creating components.

Friends

const SaveLoadGetLinkGraphDesc ()
 Get a SaveLoad array for a link graph.

Detailed Description

A link graph, inheriting one job.

Definition at line 252 of file linkgraph.h.


Member Function Documentation

void LinkGraph::CreateComponent ( Station *  first  )  [private]

1.

Build the link graph component containing the given station by using BFS on the link stats. 2. Set every included station's last_component to the new component's ID (this->current_component_id). 3. Start a link graph job with the new component.

Parameters:
first Station to start the search at.

Definition at line 77 of file linkgraph.cpp.

References LinkGraphComponent::AddEdge(), LinkGraphComponent::AddNode(), LinkGraphComponent::cargo, LinkGraphComponent::index, and LinkGraphJob::SpawnThread().

Referenced by NextComponent().

void LinkGraph::Init ( CargoID  cargo  ) 

(Re-)Initialize the link graph: join all jobs and set current_station_id and cargo to their start values.

Parameters:
cargo New cargo ID for the link graph.

Definition at line 508 of file linkgraph.cpp.

References LinkGraphComponent::cargo, LinkGraphComponent::Clear(), current_station_id, and Join().

Referenced by NextComponent().

void LinkGraph::NextComponent (  ) 

Looks for a suitable station to create the next link graph component from.

Linearly searches all stations starting from current_station_id for one that hasn't been visited in this run over the link graph. The current run and the last run are differentiated by giving the components IDs divisible by 2 every second run and ones not divisible by 2 on the other runs.

If such a station is found current_station_id is set to that station's ID and CreateComponent is called with it.

The search wraps around and changes current_component_id to 0 or 1 accordingly. If the starting point is reached again it stops.

Definition at line 125 of file linkgraph.cpp.

References LinkGraphComponent::cargo, CreateComponent(), current_station_id, LinkGraphComponent::GetSize(), LinkGraphComponent::index, Init(), GoodsEntry::last_component, GoodsEntry::link_stats, and min().

Referenced by OnTick_LinkGraph().


Friends And Related Function Documentation

const SaveLoad* GetLinkGraphDesc (  )  [friend]

Get a SaveLoad array for a link graph.

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 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.

Returns:
Array of SaveLoad structs.

Definition at line 30 of file linkgraph_sl.cpp.


The documentation for this class was generated from the following files: