#include <Main/fg_props.hxx>
#include <Scripting/NasalSys.hxx>
+using simgear::PropertyList;
+
FGJoystickInput::axis::axis ()
: last_value(9999999),
tolerance(0.002),
FGJoystickInput::joystick::~joystick ()
{
-// delete js? why not?
-// delete js;
+ // delete js? no, since js == this - and we're in the destructor already.
delete[] axes;
delete[] buttons;
+ jsnum = 0;
+ js = NULL;
+ naxes = 0;
+ nbuttons = 0;
+ axes = NULL;
+ buttons = NULL;
}
FGJoystickInput::~FGJoystickInput()
{
+ _remove();
}
+void FGJoystickInput::_remove()
+{
+ SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true);
+ js_nodes->removeChildren("js", false);
+ for (int i = 0; i < MAX_JOYSTICKS; i++)
+ {
+ if (bindings[i].js)
+ delete bindings[i].js;
+ bindings[i].js = NULL;
+ }
+}
void FGJoystickInput::init()
{
jsInit();
- // TODO: zero the old bindings first.
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing joystick bindings");
SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true);
}
}
+void FGJoystickInput::reinit() {
+ SG_LOG(SG_INPUT, SG_DEBUG, "Re-Initializing joystick bindings");
+ _remove();
+ FGJoystickInput::init();
+ FGJoystickInput::postinit();
+}
+
void FGJoystickInput::postinit()
{
FGNasalSys *nasalsys = (FGNasalSys *)globals->get_subsystem("nasal");
string module = str.str();
nasalsys->createModule(module.c_str(), module.c_str(), "", 0);
- vector<SGPropertyNode_ptr> nasal = js_node->getChildren("nasal");
+ PropertyList nasal = js_node->getChildren("nasal");
unsigned int j;
for (j = 0; j < nasal.size(); j++) {
nasal[j]->setStringValue("module", module.c_str());
//
// Initialize the axes.
//
- vector<SGPropertyNode_ptr> axes = js_node->getChildren("axis");
+ PropertyList axes = js_node->getChildren("axis");
size_t nb_axes = axes.size();
for (j = 0; j < nb_axes; j++ ) {
const SGPropertyNode * axis_node = axes[j];
//
// Initialize the buttons.
//
- vector<SGPropertyNode_ptr> buttons = js_node->getChildren("button");
+ PropertyList buttons = js_node->getChildren("button");
char buf[32];
for (j = 0; j < buttons.size() && j < nbuttons; j++) {
const SGPropertyNode * button_node = buttons[j];
continue;
js->read(&buttons, axis_values);
+ if (js->notWorking()) // If js is disconnected
+ continue;
// Fire bindings for the axes.
for (int j = 0; j < bindings[i].naxes; j++) {