2 #include "Thruster.hpp"
3 #include "PropEngine.hpp"
8 #include "ControlMap.hpp"
11 ControlMap::~ControlMap()
14 for(i=0; i<_inputs.size(); i++) {
15 Vector* v = (Vector*)_inputs.get(i);
17 for(j=0; j<v->size(); j++)
18 delete (MapRec*)v->get(j);
22 for(i=0; i<_outputs.size(); i++) {
23 OutRec* o = (OutRec*)_outputs.get(i);
29 int ControlMap::newInput()
31 Vector* v = new Vector();
32 return _inputs.add(v);
35 void ControlMap::addMapping(int input, int type, void* object, int options)
37 // See if the output object already exists
40 for(i=0; i<_outputs.size(); i++) {
41 OutRec* o = (OutRec*)_outputs.get(i);
42 if(o->object == object && o->type == type) {
48 // Create one if it doesn't
58 // Make space for the new input value
61 out->values = new float[out->n];
63 // Add the new option tag
64 out->options.add((void*)options);
66 // Make a new input record
67 MapRec* map = new MapRec();
71 // And add it to the approproate vector.
72 Vector* maps = (Vector*)_inputs.get(input);
76 void ControlMap::reset()
78 // Set all the values to zero
80 for(i=0; i<_outputs.size(); i++) {
81 OutRec* o = (OutRec*)_outputs.get(i);
88 void ControlMap::setInput(int input, float value)
90 Vector* maps = (Vector*)_inputs.get(input);
92 for(i=0; i<maps->size(); i++) {
93 MapRec* map = (MapRec*)maps->get(i);
94 map->out->values[map->idx] = value;
98 void ControlMap::applyControls()
101 for(outrec=0; outrec<_outputs.size(); outrec++) {
102 OutRec* o = (OutRec*)_outputs.get(outrec);
104 // Generate a summed value. Note the check for "split"
105 // control axes like ailerons.
106 float lval = 0, rval = 0;
108 for(i=0; i<o->n; i++) {
109 float val = o->values[i];
110 int opt = (int)o->options.get(i);
112 val = val * Math::abs(val);
122 void* obj = o->object;
124 case THROTTLE: ((Thruster*)obj)->setThrottle(lval); break;
125 case MIXTURE: ((Thruster*)obj)->setMixture(lval); break;
126 case ADVANCE: ((PropEngine*)obj)->setAdvance(lval); break;
127 case REHEAT: ((Jet*)obj)->setReheat(lval); break;
128 case BRAKE: ((Gear*)obj)->setBrake(lval); break;
129 case STEER: ((Gear*)obj)->setRotation(lval); break;
130 case EXTEND: ((Gear*)obj)->setExtension(lval); break;
131 case SLAT: ((Wing*)obj)->setSlat(lval); break;
132 case FLAP0: ((Wing*)obj)->setFlap0(lval, rval); break;
133 case FLAP1: ((Wing*)obj)->setFlap1(lval, rval); break;
134 case SPOILER: ((Wing*)obj)->setSpoiler(lval, rval); break;
139 }; // namespace yasim