OpenTTD
linkgraphschedule.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef LINKGRAPHSCHEDULE_H
11 #define LINKGRAPHSCHEDULE_H
12 
13 #include "linkgraph.h"
14 
15 class LinkGraphJob;
16 
22 public:
26  virtual ~ComponentHandler() {}
27 
33  virtual void Run(LinkGraphJob &job) const = 0;
34 };
35 
37 private:
40  typedef std::list<LinkGraph *> GraphList;
41  typedef std::list<LinkGraphJob *> JobList;
42  friend const SaveLoad *GetLinkGraphScheduleDesc();
43 
44 protected:
45  ComponentHandler *handlers[6];
46  GraphList schedule;
47  JobList running;
48 
49 public:
50  /* This is a tick where not much else is happening, so a small lag might go unnoticed. */
51  static const uint SPAWN_JOIN_TICK = 21;
53 
54  static void Run(LinkGraphJob *job);
55  static void Clear();
56 
57  void SpawnNext();
58  void JoinNext();
59  void SpawnAll();
60  void ShiftDates(int interval);
61 
66  void Queue(LinkGraph *lg)
67  {
68  assert(LinkGraph::Get(lg->index) == lg);
69  this->schedule.push_back(lg);
70  }
71 
76  void Unqueue(LinkGraph *lg) { this->schedule.remove(lg); }
77 };
78 
79 #endif /* LINKGRAPHSCHEDULE_H */
virtual ~ComponentHandler()
Destroy the handler.
void Queue(LinkGraph *lg)
Queue a link graph for execution.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
virtual void Run(LinkGraphJob &job) const =0
Run the handler.
A connected component of a link graph.
Definition: linkgraph.h:38
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
const SaveLoad * GetLinkGraphScheduleDesc()
Get a SaveLoad array for the link graph schedule.
GraphList schedule
Queue for new jobs.
A handler doing "something" on a link graph component.
Declaration of link graph classes used for cargo distribution.
SaveLoad type struct.
Definition: saveload.h:496
JobList running
Currently running jobs.
Class for calculation jobs to be run on link graphs.
Definition: linkgraphjob.h:29