]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/signal.h
Add basic support for signals
[r2c2.git] / source / libr2c2 / signal.h
diff --git a/source/libr2c2/signal.h b/source/libr2c2/signal.h
new file mode 100644 (file)
index 0000000..c7bb0ef
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef LIBR2C2_SIGNAL_H_
+#define LIBR2C2_SIGNAL_H_
+
+#include <msp/datafile/objectloader.h>
+#include <msp/time/timedelta.h>
+#include "geometry.h"
+
+namespace R2C2 {
+
+class Block;
+class Layout;
+class SignalType;
+class Track;
+class Train;
+
+class Signal
+{
+public:
+       class Loader: public Msp::DataFile::ObjectLoader<Signal>
+       {
+       public:
+               Loader(Signal &);
+
+       private:
+               void address(unsigned);
+               void direction(float);
+               void position(float, float, float);
+       };
+
+private:
+       Layout &layout;
+       const SignalType &type;
+       unsigned address;
+       Vector position;
+       float direction;
+       Track *track;
+       Block *block;
+       unsigned entry;
+       Train *train;
+       bool check_train_direction;
+       sigc::connection train_conn;
+       bool check_allocated_blocks;
+       bool passing;
+
+public:
+       Signal(Layout &, const SignalType &);
+       ~Signal();
+
+       const SignalType &get_type() const { return type; }
+
+       void set_address(unsigned);
+       void set_position(const Vector &);
+       void set_direction(float);
+private:
+       void normalize_location();
+public:
+       const Vector &get_position() const { return position; }
+       float get_direction() const { return direction; }
+
+       void tick(const Msp::Time::TimeDelta &);
+
+private:
+       void block_reserved(const Block &, Train *);
+       void train_advanced(Block &);
+       void reset();
+
+public:
+       void save(std::list<Msp::DataFile::Statement> &) const;
+};
+} // namespace R2C2
+
+
+#endif