OpenTTD
linkgraphschedule.h
Go to the documentation of this file.
1 /* $Id: linkgraphschedule.h 27178 2015-03-07 18:27:01Z frosch $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef LINKGRAPHSCHEDULE_H
13 #define LINKGRAPHSCHEDULE_H
14 
15 #include "linkgraph.h"
16 
17 class LinkGraphJob;
18 
24 public:
28  virtual ~ComponentHandler() {}
29 
35  virtual void Run(LinkGraphJob &job) const = 0;
36 };
37 
39 private:
42  typedef std::list<LinkGraph *> GraphList;
43  typedef std::list<LinkGraphJob *> JobList;
44  friend const SaveLoad *GetLinkGraphScheduleDesc();
45 
46 protected:
47  ComponentHandler *handlers[6];
48  GraphList schedule;
49  JobList running;
50 
51 public:
52  /* This is a tick where not much else is happening, so a small lag might go unnoticed. */
53  static const uint SPAWN_JOIN_TICK = 21;
55 
56  static void Run(void *j);
57  static void Clear();
58 
59  void SpawnNext();
60  void JoinNext();
61  void SpawnAll();
62  void ShiftDates(int interval);
63 
68  void Queue(LinkGraph *lg)
69  {
70  assert(LinkGraph::Get(lg->index) == lg);
71  this->schedule.push_back(lg);
72  }
73 
78  void Unqueue(LinkGraph *lg) { this->schedule.remove(lg); }
79 };
80 
81 #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:246
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
virtual void Run(LinkGraphJob &job) const =0
Run the handler.
A connected component of a link graph.
Definition: linkgraph.h:40
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:208
JobList running
Currently running jobs.
Class for calculation jobs to be run on link graphs.
Definition: linkgraphjob.h:31