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