]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/signal.h
Properly round negative z coordinates for Terrain
[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 "blockiter.h"
7 #include "geometry.h"
8 #include "signaltype.h"
9 #include "trackattachment.h"
10
11 namespace R2C2 {
12
13 class Layout;
14 class Train;
15
16 class Signal: public TrackAttachment
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 position(float, float, float);
27                 void rotation(float);
28         };
29
30 private:
31         const SignalType &type;
32         unsigned address;
33         unsigned id;
34         BlockIter block;
35         Train *train;
36         sigc::connection train_conn;
37         bool check_allocated_blocks;
38         bool passing;
39
40 public:
41         Signal(Layout &, const SignalType &);
42         ~Signal();
43
44         virtual Signal *clone(Layout * = 0) const;
45         virtual const SignalType &get_type() const { return type; }
46
47         void set_address(unsigned);
48         unsigned get_address() const { return address; }
49         virtual void set_position(const Vector &);
50         virtual void set_rotation(const Angle &);
51         virtual void set_tilt(const Angle &) { }
52 private:
53         void update_attachment();
54 public:
55
56         virtual unsigned get_n_snap_nodes() const;
57         virtual Snap get_snap_node(unsigned) const;
58 private:
59         virtual SnapType get_default_snap_type_to(const Object &) const;
60
61 public:
62         void tick(const Msp::Time::TimeDelta &);
63
64 private:
65         void block_reserved(const Block &, Train *);
66         void train_advanced(Block &);
67         void reset();
68
69 public:
70         void save(std::list<Msp::DataFile::Statement> &) const;
71 };
72 } // namespace R2C2
73
74
75 #endif