1
0
Fork 0

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 ...  :-)
This commit is contained in:
mfranz 2005-06-13 06:14:45 +00:00
parent dec07ab83e
commit 639ed2161f
2 changed files with 4 additions and 4 deletions

View 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];

View file

@ -429,6 +429,7 @@ private:
joystick _joystick_bindings[MAX_JOYSTICKS];
mouse _mouse_bindings[MAX_MICE];
SGPropertyNode *_which_joystick;
};
#endif // _INPUT_HXX