2 #include "Thruster.hpp"
3 #include "PropEngine.hpp"
8 #include "ControlMap.hpp"
11 ControlMap::~ControlMap()
13 for(int i=0; i<_inputs.size(); i++) {
14 Vector* v = (Vector*)_inputs.get(i);
15 for(int j=0; j<v->size(); j++)
16 delete (MapRec*)v->get(j);
20 for(int i=0; i<_outputs.size(); i++) {
21 OutRec* o = (OutRec*)_outputs.get(i);
27 int ControlMap::newInput()
29 Vector* v = new Vector();
30 return _inputs.add(v);
33 void ControlMap::addMapping(int input, int type, void* object, int options)
35 // See if the output object already exists
37 for(int i=0; i<_outputs.size(); i++) {
38 OutRec* o = (OutRec*)_outputs.get(i);
39 if(o->object == object && o->type == type) {
45 // Create one if it doesn't
55 // Make space for the new input value
58 out->values = new float[out->n];
60 // Add the new option tag
61 out->options.add((void*)options);
63 // Make a new input record
64 MapRec* map = new MapRec();
68 // And add it to the approproate vector.
69 Vector* maps = (Vector*)_inputs.get(input);
73 void ControlMap::reset()
75 // Set all the values to zero
76 for(int i=0; i<_outputs.size(); i++) {
77 OutRec* o = (OutRec*)_outputs.get(i);
78 for(int j=0; j<o->n; j++)
83 void ControlMap::setInput(int input, float value)
85 Vector* maps = (Vector*)_inputs.get(input);
86 for(int i=0; i<maps->size(); i++) {
87 MapRec* map = (MapRec*)maps->get(i);
88 map->out->values[map->idx] = value;
92 void ControlMap::applyControls()
94 for(int outrec=0; outrec<_outputs.size(); outrec++) {
95 OutRec* o = (OutRec*)_outputs.get(outrec);
97 // Generate a summed value. Note the check for "split"
98 // control axes like ailerons.
99 float lval = 0, rval = 0;
100 for(int i=0; i<o->n; i++) {
101 float val = o->values[i];
102 int opt = (int)o->options.get(i);
104 val = val * Math::abs(val);
114 void* obj = o->object;
116 case THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
117 case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
118 case ADVANCE: ((PropEngine*)obj)->setAdvance(lval); break;
119 case REHEAT: ((Jet*)obj)->setReheat(lval); break;
120 case BRAKE: ((Gear*)obj)->setBrake(lval); break;
121 case STEER: ((Gear*)obj)->setRotation(lval); break;
122 case EXTEND: ((Gear*)obj)->setExtension(lval); break;
123 case SLAT: ((Wing*)obj)->setSlat(lval); break;
124 case FLAP0: ((Wing*)obj)->setFlap0(lval, rval); break;
125 case FLAP1: ((Wing*)obj)->setFlap1(lval, rval); break;
126 case SPOILER: ((Wing*)obj)->setSpoiler(lval, rval); break;
131 }; // namespace yasim