]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/train.h
Convert engineer to use mspgbase instead of SDL
[r2c2.git] / source / libmarklin / train.h
1 #ifndef LIBMARKLIN_TRAIN_H_
2 #define LIBMARKLIN_TRAIN_H_
3
4 #include <sigc++/signal.h>
5 #include <sigc++/trackable.h>
6 #include <msp/time/timestamp.h>
7 #include "block.h"
8
9 namespace Marklin {
10
11 class Locomotive;
12 class Sensor;
13 class TrafficManager;
14
15 class Train: public sigc::trackable
16 {
17 private:
18         struct BlockRef
19         {
20                 Block *block;
21                 unsigned entry;
22
23                 BlockRef(Block *s, unsigned e): block(s), entry(e) { }
24         };
25
26         TrafficManager &trfc_mgr;
27         std::string name;
28         Locomotive &loco;
29         std::list<BlockRef> cur_blocks;
30         std::list<BlockRef> rsv_blocks;
31         unsigned target_speed;
32         Msp::Time::TimeStamp try_reserve;
33
34 public:
35         sigc::signal<void, const std::string &> signal_name_changed;
36
37         Train(TrafficManager &, Locomotive &);
38         void set_name(const std::string &);
39         void set_speed(unsigned);
40         const std::string &get_name() const { return name; }
41         Locomotive &get_locomotive() const { return loco; }
42         void place(Block *, unsigned);
43         bool free_block(Block *);
44         void tick(const Msp::Time::TimeStamp &);
45 private:
46         void sensor_event(bool, Sensor *);
47         bool reserve_more();
48 };
49 typedef std::list<Train *> TrainSeq;
50
51 } // namespace Marklin
52
53 #endif