10 #include "../stdafx.h"
16 #include "../framerate_type.h"
17 #include "../command_func.h"
18 #include "../network/network.h"
19 #include "../misc_cmd.h"
21 #include "../safeguards.h"
38 while (next->
Size() < 2) {
39 this->
schedule.splice(this->
schedule.end(), this->schedule, this->schedule.begin());
41 if (next == first)
return;
60 if (this->
running.empty())
return false;
70 if (this->
running.empty())
return;
113 for (
auto &it : this->
running) {
146 this->
handlers[0] = std::make_unique<InitHandler>();
147 this->
handlers[1] = std::make_unique<DemandHandler>();
148 this->
handlers[2] = std::make_unique<MCFHandler<MCF1stPass>>();
149 this->
handlers[3] = std::make_unique<FlowMapper>(
false);
150 this->handlers[4] = std::make_unique<MCFHandler<MCF2ndPass>>();
151 this->handlers[5] = std::make_unique<FlowMapper>(
true);
173 if (!LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
Class for calculation jobs to be run on link graphs.
std::atomic< bool > job_completed
Is the job still running. This is accessed by multiple threads and reads may be stale.
LinkGraphID LinkGraphIndex() const
Get the ID of the underlying link graph.
bool IsJobAborted() const
Check if job has been aborted.
void SpawnThread()
Spawn a thread if possible and run the link graph job in the thread.
bool IsScheduledToBeJoined() const
Check if job is supposed to be finished.
bool IsJobCompleted() const
Check if job has actually finished.
LinkGraphSchedule()
Create a link graph schedule and initialize its handlers.
GraphList schedule
Queue for new jobs.
void SpawnNext()
Start the next job in the schedule.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
static void Clear()
Clear all link graphs and jobs from the schedule.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
~LinkGraphSchedule()
Delete a link graph schedule and its handlers.
bool IsJoinWithUnfinishedJobDue() const
Check if the next job is supposed to be finished, but has not yet completed.
static const uint SPAWN_JOIN_TICK
Tick when jobs are spawned or joined every day.
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
void Queue(LinkGraph *lg)
Queue a link graph for execution.
static void Run(LinkGraphJob *job)
Run all handlers for the given Job.
void JoinNext()
Join the next finished job, if available.
std::array< std::unique_ptr< ComponentHandler >, 6 > handlers
Handlers to be run for each job.
JobList running
Currently running jobs.
void SpawnAll()
Start all threads in the running list.
A connected component of a link graph.
NodeID Size() const
Get the current size of the component.
static constexpr int SECONDS_PER_DAY
approximate seconds per day, not for precise calculations
static Date date
Current date in days (day counter).
static DateFract date_fract
Fractional part of the day.
Declaration of demand calculating link graph handler.
Declaration of flow mapper; maps paths into flows at nodes.
@ PFE_GL_LINKGRAPH
Time spent waiting for link graph background jobs.
PauseMode _pause_mode
The current pause mode.
Declaration of initializing link graph handler.
void OnTick_LinkGraph()
Spawn or join a link graph job or compress a link graph if any link graph is due to do so.
void StateGameLoop_LinkGraphPauseControl()
Pause the game if in 2 TimerGameEconomy::date_fract ticks, we would do a join with the next link grap...
void AfterLoad_LinkGraphPauseControl()
Pause the game on load if we would do a join with the next link graph job, but it is still running,...
Declaration of link graph schedule used for cargo distribution.
Declaration of Multi-Commodity-Flow solver.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
@ PM_UNPAUSED
A normal unpaused game.
@ PM_PAUSED_LINK_GRAPH
A game paused due to the link graph schedule lagging.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
LinkGraphSettings linkgraph
settings for link graph calculations
uint16_t recalc_interval
time (in days) between subsequent checks for link graphs to be calculated.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.