]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/signal.h
Fix logic with signals and train direction check
[r2c2.git] / source / libr2c2 / signal.h
1 #ifndef LIBR2C2_SIGNAL_H_
2 #define LIBR2C2_SIGNAL_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include <msp/time/timedelta.h>
6 #include "geometry.h"
7
8 namespace R2C2 {
9
10 class Block;
11 class Layout;
12 class SignalType;
13 class Track;
14 class Train;
15
16 class Signal
17 {
18 public:
19         class Loader: public Msp::DataFile::ObjectLoader<Signal>
20         {
21         public:
22                 Loader(Signal &);
23
24         private:
25                 void address(unsigned);
26                 void direction(float);
27                 void position(float, float, float);
28         };
29
30 private:
31         Layout &layout;
32         const SignalType &type;
33         unsigned address;
34         Vector position;
35         float direction;
36         Track *track;
37         Block *block;
38         unsigned entry;
39         Train *train;
40         sigc::connection train_conn;
41         bool check_allocated_blocks;
42         bool passing;
43
44 public:
45         Signal(Layout &, const SignalType &);
46         ~Signal();
47
48         const SignalType &get_type() const { return type; }
49
50         void set_address(unsigned);
51         void set_position(const Vector &);
52         void set_direction(float);
53 private:
54         void normalize_location();
55 public:
56         const Vector &get_position() const { return position; }
57         float get_direction() const { return direction; }
58
59         void tick(const Msp::Time::TimeDelta &);
60
61 private:
62         void block_reserved(const Block &, Train *);
63         void train_advanced(Block &);
64         void reset();
65
66 public:
67         void save(std::list<Msp::DataFile::Statement> &) const;
68 };
69 } // namespace R2C2
70
71
72 #endif