OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
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) {
160 for (
const auto &handler : this->
handlers) {
static void Clear()
Clear all link graphs and jobs from the schedule.
static Titem * Get(size_t index)
Returns Titem with given index.
void JoinNext()
Join the next finished job, if available.
A connected component of a link graph.
Stateless, thread safe demand handler.
static const uint SPAWN_JOIN_TICK
Tick when jobs are spawned or joined every day.
Class for calculation jobs to be run on link graphs.
JobList running
Currently running jobs.
bool _network_server
network-server is active
bool IsJobCompleted() const
Check if job has actually finished.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Tindex index
Index of this pool item.
std::atomic< bool > job_completed
Is the job still running. This is accessed by multiple threads and reads may be stale.
static DateFract date_fract
Fractional part of the day.
@ PFE_GL_LINKGRAPH
Time spent waiting for link graph background jobs.
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,...
NodeID Size() const
Get the current size of the component.
void SpawnAll()
Start all threads in the running list.
LinkGraphID LinkGraphIndex() const
Get the ID of the underlying link graph.
void OnTick_LinkGraph()
Spawn or join a link graph job or compress a link graph if any link graph is due to do so.
uint16_t recalc_interval
time (in days) between subsequent checks for link graphs to be calculated.
void Queue(LinkGraph *lg)
Queue a link graph for execution.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
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.
PauseMode _pause_mode
The current pause mode.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void SpawnNext()
Start the next job in the schedule.
bool _networking
are we in networking mode?
LinkGraphSchedule()
Create a link graph schedule and initialize its handlers.
LinkGraphSettings linkgraph
settings for link graph calculations
GraphList schedule
Queue for new jobs.
@ PM_PAUSED_LINK_GRAPH
A game paused due to the link graph schedule lagging.
Map the path trees generated by the MCF solver into flows.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
bool IsJobAborted() const
Check if job has been aborted.
bool IsJoinWithUnfinishedJobDue() const
Check if the next job is supposed to be finished, but has not yet completed.
Link graph handler for MCF.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static void Run(LinkGraphJob *job)
Run all handlers for the given Job.
static constexpr int SECONDS_PER_DAY
approximate seconds per day, not for precise calculations
ComponentHandler * handlers[6]
Handlers to be run for each job.
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ PM_UNPAUSED
A normal unpaused game.
~LinkGraphSchedule()
Delete a link graph schedule and its handlers.
Stateless, thread safe initialization handler.
void StateGameLoop_LinkGraphPauseControl()
Pause the game if in 2 TimerGameEconomy::date_fract ticks, we would do a join with the next link grap...
static Date date
Current date in days (day counter).