]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/controller.h
Add control enumeration to Controller
[r2c2.git] / source / libr2c2 / controller.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_CONTROLLER_H_
9 #define LIBR2C2_CONTROLLER_H_
10
11 #include <string>
12 #include <sigc++/signal.h>
13 #include <msp/time/timedelta.h>
14
15 namespace R2C2 {
16
17 /**
18 Interface class for train controllers.  Takes input through a uniform named
19 control interface.  Provides information about train movement on output.
20 */
21 class Controller
22 {
23 public:
24         struct Control
25         {
26                 enum Type
27                 {
28                         BINARY,
29                         DISCRETE,
30                         CONTINUOUS
31                 };
32
33                 std::string name;
34                 Type type;
35                 float min_value;
36                 float max_value;
37                 float step;
38                 float value;
39
40         private:
41                 Control() { }
42
43         public:
44                 void set(float);
45
46                 static Control binary(const std::string &);
47                 static Control discrete(const std::string &, float, float, float);
48                 static Control continuous(const std::string &, float, float);
49         };
50
51         sigc::signal<void, const Control &> signal_control_changed;
52
53 protected:
54         Controller() { }
55 public:
56         virtual ~Controller() { }
57
58         virtual const char *enumerate_controls(unsigned) const = 0;
59         virtual void set_control(const std::string &, float) = 0;
60         virtual const Control &get_control(const std::string &) const = 0;
61
62         /** Returns the current speed.  Always non-negative. */
63         virtual float get_speed() const = 0;
64
65         /** Returns true if traveling in reverse. */
66         virtual bool get_reverse() const = 0;
67
68         /** Determines the distance required to come to a full stop. */
69         virtual float get_braking_distance() const = 0;
70
71         virtual void tick(const Msp::Time::TimeDelta &) = 0;
72 };
73
74 } // namespace R2C2
75
76 #endif