OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

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
23 class ComponentHandler {
24 public:
28 virtual ~ComponentHandler() {}
29
35 virtual void Run(LinkGraphJob &job) const = 0;
36 };
37
38 class LinkGraphSchedule {
39 private:
40 LinkGraphSchedule();
41 ~LinkGraphSchedule();
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;
54 static LinkGraphSchedule instance;
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 */