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
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 */
ComponentHandler::~ComponentHandler
virtual ~ComponentHandler()
Destroy the handler.
Definition: linkgraphschedule.h:28
LinkGraphSchedule::Queue
void Queue(LinkGraph *lg)
Queue a link graph for execution.
Definition: linkgraphschedule.h:68
Pool::PoolItem<&_link_graph_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
LinkGraphSchedule::Unqueue
void Unqueue(LinkGraph *lg)
Remove a link graph from the execution queue.
Definition: linkgraphschedule.h:78
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
ComponentHandler::Run
virtual void Run(LinkGraphJob &job) const =0
Run the handler.
LinkGraphSchedule
Definition: linkgraphschedule.h:38
LinkGraph
A connected component of a link graph.
Definition: linkgraph.h:40
LinkGraphSchedule::instance
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Definition: linkgraphschedule.h:54
GetLinkGraphScheduleDesc
const SaveLoad * GetLinkGraphScheduleDesc()
Get a SaveLoad array for the link graph schedule.
Definition: linkgraph_sl.cpp:96
LinkGraphSchedule::schedule
GraphList schedule
Queue for new jobs.
Definition: linkgraphschedule.h:48
ComponentHandler
A handler doing "something" on a link graph component.
Definition: linkgraphschedule.h:23
linkgraph.h
Declaration of link graph classes used for cargo distribution.
SaveLoad
SaveLoad type struct.
Definition: saveload.h:208
LinkGraphSchedule::running
JobList running
Currently running jobs.
Definition: linkgraphschedule.h:49
LinkGraphJob
Class for calculation jobs to be run on link graphs.
Definition: linkgraphjob.h:31