diff --git a/src/Input/input.cxx b/src/Input/input.cxx index fdb13de5e..2dd6f1c48 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -32,6 +32,7 @@ #include #include +#include #include STL_FSTREAM #include STL_STRING @@ -63,6 +64,7 @@ #include
SG_USING_STD(ifstream); +SG_USING_STD(ostringstream); SG_USING_STD(string); SG_USING_STD(vector); @@ -385,13 +387,13 @@ void FGInput::_init_keyboard () { SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings"); - _module[0] = 0; + _module = "__kbd"; SGPropertyNode * key_nodes = fgGetNode("/input/keyboard"); if (key_nodes == 0) { SG_LOG(SG_INPUT, SG_WARN, "No key bindings (/input/keyboard)!!"); key_nodes = fgGetNode("/input/keyboard", true); } - + vector keys = key_nodes->getChildren("key"); for (unsigned int i = 0; i < keys.size(); i++) { int index = keys[i]->getIndex(); @@ -501,6 +503,19 @@ FGInput::_init_joystick () } +void +FGInput::_postinit_keyboard() +{ + FGNasalSys *nasalsys = (FGNasalSys *)globals->get_subsystem("nasal"); + SGPropertyNode *key_nodes = fgGetNode("/input/keyboard", true); + vector nasal = key_nodes->getChildren("nasal"); + for (unsigned int j = 0; j < nasal.size(); j++) { + nasal[j]->setStringValue("module", _module.c_str()); + nasalsys->handleCommand(nasal[j]); + } +} + + void FGInput::_postinit_joystick() { @@ -546,15 +561,15 @@ FGInput::_postinit_joystick() // // Initialize nasal groups. // - string init; - init = "this=\"" + string(js_node->getPath()) + "\""; - sprintf(_module, "__js%d", i); - nasalsys->createModule(_module, _module, init.c_str(), init.size()); + ostringstream str; + str << "__js" << i; + _module = str.str(); + nasalsys->createModule(_module.c_str(), _module.c_str(), "", 0); vector nasal = js_node->getChildren("nasal"); unsigned int j; for (j = 0; j < nasal.size(); j++) { - nasal[j]->setStringValue("module", _module); + nasal[j]->setStringValue("module", _module.c_str()); nasalsys->handleCommand(nasal[j]); } @@ -665,7 +680,7 @@ void FGInput::_init_mouse () { SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings"); - _module[0] = 0; + _module = ""; SGPropertyNode * mouse_nodes = fgGetNode("/input/mice"); if (mouse_nodes == 0) { @@ -910,8 +925,8 @@ FGInput::_read_bindings (const SGPropertyNode * node, const char *cmd = bindings[i]->getStringValue("command"); SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding " << cmd); - if (!strcmp(cmd, "nasal") && _module[0]) - bindings[i]->setStringValue("module", _module); + if (!strcmp(cmd, "nasal") && !_module.empty()) + bindings[i]->setStringValue("module", _module.c_str()); binding_list[modifiers].push_back(new SGBinding(bindings[i], globals->get_props())); } diff --git a/src/Input/input.hxx b/src/Input/input.hxx index 99116dbe6..83527590b 100644 --- a/src/Input/input.hxx +++ b/src/Input/input.hxx @@ -280,6 +280,7 @@ private: * Initialize nasal parts that had to wait for the nasal to get * functional. */ + void _postinit_keyboard (); void _postinit_joystick (); /** @@ -327,7 +328,7 @@ private: /** * Nasal module name/namespace. */ - char _module[32]; + string _module; /** * List of currently pressed mouse button events