2 #include "Thruster.hpp"
7 #include "ControlMap.hpp"
10 ControlMap::~ControlMap()
12 for(int i=0; i<_inputs.size(); i++) {
13 Vector* v = (Vector*)_inputs.get(i);
14 for(int j=0; j<v->size(); j++)
15 delete (MapRec*)v->get(j);
19 for(int i=0; i<_outputs.size(); i++) {
20 OutRec* o = (OutRec*)_outputs.get(i);
26 int ControlMap::newInput()
28 Vector* v = new Vector();
29 return _inputs.add(v);
32 void ControlMap::addMapping(int input, int type, void* object, int options)
34 // See if the output object already exists
36 for(int i=0; i<_outputs.size(); i++) {
37 OutRec* o = (OutRec*)_outputs.get(i);
38 if(o->object == object && o->type == type) {
44 // Create one if it doesn't
54 // Make space for the new input value
57 out->values = new float[out->n];
59 // Add the new option tag
60 out->options.add((void*)options);
62 // Make a new input record
63 MapRec* map = new MapRec();
67 // And add it to the approproate vector.
68 Vector* maps = (Vector*)_inputs.get(input);
72 void ControlMap::reset()
74 // Set all the values to zero
75 for(int i=0; i<_outputs.size(); i++) {
76 OutRec* o = (OutRec*)_outputs.get(i);
77 for(int j=0; j<o->n; j++)
82 void ControlMap::setInput(int input, float value)
84 Vector* maps = (Vector*)_inputs.get(input);
85 for(int i=0; i<maps->size(); i++) {
86 MapRec* map = (MapRec*)maps->get(i);
87 map->out->values[map->idx] = value;
91 void ControlMap::applyControls()
93 for(int outrec=0; outrec<_outputs.size(); outrec++) {
94 OutRec* o = (OutRec*)_outputs.get(outrec);
96 // Generate a summed value. Note the check for "split"
97 // control axes like ailerons.
98 float lval = 0, rval = 0;
99 for(int i=0; i<o->n; i++) {
100 float val = o->values[i];
101 int opt = (int)o->options.get(i);
103 val = val * Math::abs(val);
113 void* obj = o->object;
115 case THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
116 case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
117 case PROP: ((Thruster*)obj)->setPropAdvance(lval); break;
118 case REHEAT: ((Jet*)obj)->setReheat(lval); break;
119 case BRAKE: ((Gear*)obj)->setBrake(lval); break;
120 case STEER: ((Gear*)obj)->setRotation(lval); break;
121 case EXTEND: ((Gear*)obj)->setExtension(lval); break;
122 case SLAT: ((Wing*)obj)->setSlat(lval); break;
123 case FLAP0: ((Wing*)obj)->setFlap0(lval, rval); break;
124 case FLAP1: ((Wing*)obj)->setFlap1(lval, rval); break;
125 case SPOILER: ((Wing*)obj)->setSpoiler(lval, rval); break;
130 }; // namespace yasim