Nasal provides endless possibilities for defining joystick bindings. But there are two limitations:
(1) there's no common namespace (nasal module name). Each binding is on its own. Storing all variables in property nodes and accessing them in the different bindings is one solution, albeit verbose and slow. It's preferable to hijack one of the namespaces for data interchange instead (e.g. globals.saitek.mode = 123). (2) more annoying is the fact that there's no (sane) way to initialize functions and variables. In the case of property nodes, one would have to check for their existence whenever one wanted to access them, and initialize them if they weren't already. Again: slow & verbose. A slightly better, but still ugly workaround is, to use one <mod-up> binding to initialize stuff. All <mod-up>s are fired at the beginning. I'd like to suggest to add the possibility to add a <nasal> init block to joystick *.xml files: <PropertyList> <name>SAITEK CYBORG 3D USB</name> <nasal> <script> n = props.globals.getNode("/input/joysticks/js[0]/saitek", 1); globals.saitek = {}; globals.saitek.mode = n.getNode("mode", 1); globals.saitek.mode.setIntValue(0); globals.saitek.harrier = func { ...} ... </script> </nasal> ... One could define functions here that are used in different bindings, and initialize mode and modifier values, create property nodes etc. There aren't many changes needed to implement that (see attachment), but there's one questionable requirement: the "nasal" subsystem must get initialized before the "input" subsystem. And currently, a comment to the nasal initialization says: "Do this last, so that the loaded scripts see initialized state" Does "nasal" need to be the absolute last subsystem? "input" init would need it already, while "nasal" hardly needs "input"? m.
Index: fg_init.cxx =================================================================== RCS file: /var/cvs/FlightGear-0.9/FlightGear/src/Main/fg_init.cxx,v retrieving revision 1.121 diff -u -p -r1.121 fg_init.cxx --- fg_init.cxx 6 May 2005 09:08:44 -0000 1.121 +++ fg_init.cxx 5 Jun 2005 13:42:01 -0000 @@ -54,6 +54,7 @@ #include <simgear/debug/logstream.hxx> #include <simgear/structure/exception.hxx> #include <simgear/structure/event_mgr.hxx> +#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/math/point3d.hxx> #include <simgear/math/polar3d.hxx> #include <simgear/math/sg_geodesy.hxx> @@ -1798,13 +1799,6 @@ bool fgInitSubsystems() { //////////////////////////////////////////////////////////////////// - // Initialize the input subsystem. - //////////////////////////////////////////////////////////////////// - - globals->add_subsystem("input", new FGInput); - - - //////////////////////////////////////////////////////////////////// // Initialize the replay subsystem //////////////////////////////////////////////////////////////////// globals->add_subsystem("replay", new FGReplay); @@ -1836,6 +1830,17 @@ bool fgInitSubsystems() { globals->add_subsystem("nasal", nasal); nasal->init(); + + //////////////////////////////////////////////////////////////////// + // Initialize the input subsystem. + //////////////////////////////////////////////////////////////////// + + globals->add_subsystem("input", new FGInput); + SGSubsystem *input = globals->get_subsystem("input"); + input->bind(); + input->init(); + + //////////////////////////////////////////////////////////////////// // At this point we could try and parse the waypoint options /////////////////////////////////////////////////////////////////// Index: ../Input/input.cxx =================================================================== RCS file: /var/cvs/FlightGear-0.9/FlightGear/src/Input/input.cxx,v retrieving revision 1.55 diff -u -p -r1.55 input.cxx --- ../Input/input.cxx 17 Jan 2005 10:48:35 -0000 1.55 +++ ../Input/input.cxx 5 Jun 2005 13:42:02 -0000 @@ -50,6 +50,7 @@ #include <Cockpit/panel_io.hxx> #include <GUI/gui.h> #include <Model/panelnode.hxx> +#include <Scripting/NasalSys.hxx> #include <Main/globals.hxx> #include <Main/fg_props.hxx> @@ -465,12 +466,17 @@ FGInput::_init_joystick () _joystick_bindings[i].buttons = new button[nbuttons]; + int j; + vector<SGPropertyNode_ptr> nasal = js_node->getChildren("nasal"); + for (j = 0; j < (int)nasal.size(); j++) + ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(nasal[j]); + + // // Initialize the axes. // vector<SGPropertyNode_ptr> axes = js_node->getChildren("axis"); size_t nb_axes = axes.size(); - int j; for (j = 0; j < (int)nb_axes; j++) { const SGPropertyNode * axis_node = axes[j]; const SGPropertyNode * num_node = axis_node->getChild("number"); @@ -696,7 +702,6 @@ FGInput::_update_joystick (double dt) // position fires the bindings. if (fabs(axis_values[j] - a.last_value) > a.tolerance) { // SG_LOG(SG_INPUT, SG_DEBUG, "Axis " << j << " has moved"); - SGPropertyNode node; a.last_value = axis_values[j]; // SG_LOG(SG_INPUT, SG_DEBUG, "There are " // << a.bindings[modifiers].size() << " bindings");
_______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d