# linkgraphschedule.h

Go to the documentation of this file.

    00001 /* $Id: linkgraphschedule.h 26347 2014-02-16 18:42:59Z fonsinchen $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef LINKGRAPHSCHEDULE_H
    00013 #define LINKGRAPHSCHEDULE_H
    00014
    00015 #include "linkgraph.h"
    00016
    00017 class LinkGraphJob;
    00018
    00023 class ComponentHandler {
    00024 public:
    00028   virtual ~ComponentHandler() {}
    00029
    00035   virtual void Run(LinkGraphJob &job) const = 0;
    00036 };
    00037
    00038 class LinkGraphSchedule {
    00039 private:
    00040   LinkGraphSchedule();
    00041   ~LinkGraphSchedule();
    00042   typedef std::list<LinkGraph *> GraphList;
    00043   typedef std::list<LinkGraphJob *> JobList;
    00044   friend const SaveLoad *GetLinkGraphScheduleDesc();
    00045
    00046 protected:
    00047   ComponentHandler *handlers[6];
    00048   GraphList schedule;
    00049   JobList running;
    00050
    00051 public:
    00052   /* This is a tick where not much else is happening, so a small lag might go unnoticed. */
    00053   static const uint SPAWN_JOIN_TICK = 21;
    00054
    00055   static LinkGraphSchedule *Instance();
    00056   static void Run(void *j);
    00057   static void Clear();
    00058
    00059   void SpawnNext();
    00060   void JoinNext();
    00061   void SpawnAll();
    00062   void ShiftDates(int interval);
    00063
    00068   void Queue(LinkGraph *lg)
    00069   {
    00070     assert(LinkGraph::Get(lg->index) == lg);
    00071     this->schedule.push_back(lg);
    00072   }
    00073
    00078   void Unqueue(LinkGraph *lg) { this->schedule.remove(lg); }
    00079 };
    00080
    00081 #endif /* LINKGRAPHSCHEDULE_H */