]> git.mxchange.org Git - flightgear.git/commitdiff
revert last patch, and do it differently: set /input/joysticks/which (int)
authormfranz <mfranz>
Mon, 13 Jun 2005 06:14:45 +0000 (06:14 +0000)
committermfranz <mfranz>
Mon, 13 Jun 2005 06:14:45 +0000 (06:14 +0000)
to the joystick index (x in /input/joysticks/js[x]) both when initializing
nasal init blocks & whenever updating the joystick. That's the only way to
make these nasal contexts aware of the joytick for which they were called.
And that's useful if a js maintains common variables, such as modifiers or
state variables, that should be shared between the namespace-less bindings
and initialization code. And, yes, it's over-engineered ...  :-)

src/Input/input.cxx
src/Input/input.hxx

index 4f8926da5cde95103a5e434a791c92a2442e2be7..29be98dc38cb1e6044c52cc19474a7b510f1539b 100644 (file)
@@ -427,6 +427,7 @@ FGInput::_init_joystick ()
                                 // TODO: zero the old bindings first.
   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
   SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true);
+  _which_joystick = js_nodes->getNode("which", true);
 
   // read all joystick xml files into /input/joysticks/js_named[1000++]
   SGPath path(globals->get_fg_root());
@@ -607,14 +608,12 @@ FGInput::_postinit_joystick()
   SGPropertyNode *js_nodes = fgGetNode("/input/joysticks");
   vector<SGPropertyNode_ptr> js = js_nodes->getChildren("js");
   for (unsigned int i = 0; i < js.size(); i++) {
-    // leave temporary hint for the nasal init block
-    js_nodes->setStringValue("this", js[i]->getPath());
+    _which_joystick->setIntValue(i);
 
     vector<SGPropertyNode_ptr> nasal = js[i]->getChildren("nasal");
     for (unsigned int j = 0; j < nasal.size(); j++)
       ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(nasal[j]);
   }
-  js_nodes->removeChild("this", 0);
 }
 
 
@@ -755,9 +754,9 @@ FGInput::_update_joystick (double dt)
     if (js == 0 || js->notWorking())
       continue;
 
+    _which_joystick->setIntValue(i);
     js->read(&buttons, axis_values);
 
-
                                 // Fire bindings for the axes.
     for ( j = 0; j < _joystick_bindings[i].naxes; j++) {
       axis &a = _joystick_bindings[i].axes[j];
index faad8acdc2462eef1cbeffd87325306118055b87..9b8b278dc2a2d82dc6273affc29ae4088e4aac5a 100644 (file)
@@ -429,6 +429,7 @@ private:
   joystick _joystick_bindings[MAX_JOYSTICKS];
   mouse _mouse_bindings[MAX_MICE];
 
+  SGPropertyNode *_which_joystick;
 };
 
 #endif // _INPUT_HXX