From 639ed2161f2eed25435ebd013d916ad6065bc15f Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 13 Jun 2005 06:14:45 +0000 Subject: [PATCH] revert last patch, and do it differently: set /input/joysticks/which (int) 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 | 7 +++---- src/Input/input.hxx | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 4f8926da5..29be98dc3 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -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 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 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]; diff --git a/src/Input/input.hxx b/src/Input/input.hxx index faad8acdc..9b8b278dc 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -429,6 +429,7 @@ private: joystick _joystick_bindings[MAX_JOYSTICKS]; mouse _mouse_bindings[MAX_MICE]; + SGPropertyNode *_which_joystick; }; #endif // _INPUT_HXX -- 2.39.5