]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/ControlMap.hpp
Maik JUSTUS: (OK'ed by Andy)
[flightgear.git] / src / FDM / YASim / ControlMap.hpp
1 #ifndef _CONTROL_MAP_HPP
2 #define _CONTROL_MAP_HPP
3
4 #include "Vector.hpp"
5
6 namespace yasim {
7
8 class ControlMap {
9 public:
10     ~ControlMap();
11
12     enum OutputType { THROTTLE, MIXTURE, CONDLEVER, STARTER, MAGNETOS,
13                       ADVANCE, REHEAT, PROP,
14                       BRAKE, STEER, EXTEND, HEXTEND, LEXTEND,
15                       INCIDENCE, FLAP0, FLAP1, SLAT, SPOILER, VECTOR,
16                       BOOST, CASTERING, PROPPITCH, PROPFEATHER,
17                       COLLECTIVE, CYCLICAIL, CYCLICELE, ROTORENGINEON,
18                       ROTORBRAKE,
19                       REVERSE_THRUST, WASTEGATE,
20                       WINCHRELSPEED, HITCHOPEN, PLACEWINCH, FINDAITOW};
21
22     enum { OPT_SPLIT  = 0x01,
23            OPT_INVERT = 0x02,
24            OPT_SQUARE = 0x04 };
25
26     // Returns a new, not-yet-used "input handle" for addMapping and
27     // setInput.  This typically corresponds to one user axis.
28     int newInput();
29
30     // Adds a mapping to between input handle and a particular setting
31     // on an output object.  The value of output MUST match the type
32     // of object!
33     void addMapping(int input, int output, void* object, int options=0);
34
35     // An additional form to specify a mapping range.  Input values
36     // outside of [src0:src1] are clamped, and are then mapped to
37     // [dst0:dst1] before being set on the object.
38     void addMapping(int input, int output, void* object, int options,
39                     float src0, float src1, float dst0, float dst1);
40
41     // Resets our accumulated input values.  Call before any
42     // setInput() invokations.
43     void reset();
44
45     // Sets the specified input (as returned by newInput) to the
46     // specified value.
47     void setInput(int input, float value);
48
49     // Calculates and applies the settings received since the last reset().
50     void applyControls(float dt);
51
52     // Returns the input/output range appropriate for the given
53     // control.  Ailerons go from -1 to 1, while throttles are never
54     // lower than zero, etc...
55     static float rangeMin(int type);
56     static float rangeMax(int type);
57
58     // Each output record is identified by both an object/type tuple
59     // and a numeric handle.
60     int getOutputHandle(void* obj, int type);
61
62     // Sets the transition time for the control output to swing
63     // through its full range.
64     void setTransitionTime(int handle, float time);
65
66     // Retrieves the current value of the control output.  Controls
67     // with OPT_SPLIT settable on inputs will have a separately
68     // computed "right side" value.
69     float getOutput(int handle);
70     float getOutputR(int handle);
71
72 private:
73     struct OutRec { int type; void* object; Vector maps;
74                     float oldL, oldR, time; };
75     struct MapRec  { OutRec* out; int idx; int opt; float val;
76                      float src0; float src1; float dst0; float dst1; };
77
78     // A list of (sub)Vectors containing a bunch of MapRec objects for
79     // each input handle.
80     Vector _inputs;
81
82     // An unordered list of output settings.
83     Vector _outputs;
84 };
85
86 }; // namespace yasim
87 #endif // _CONTROL_MAP_HPP