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