X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInput%2FFGJoystickInput.cxx;h=506de36bb3c61a40b0c5507d691e45df5176ba66;hb=088b3bc79134c01bfaf5e219f707eadaf8a889b6;hp=cf7cc3319535d6a8db22db489e1623749a242bd5;hpb=9c98258ab08b48420c86cf09c0f6ba9d1ff82700;p=flightgear.git diff --git a/src/Input/FGJoystickInput.cxx b/src/Input/FGJoystickInput.cxx index cf7cc3319..506de36bb 100644 --- a/src/Input/FGJoystickInput.cxx +++ b/src/Input/FGJoystickInput.cxx @@ -49,16 +49,22 @@ FGJoystickInput::joystick::joystick () naxes(0), nbuttons(0), axes(0), - buttons(0) + buttons(0), + predefined(true) { } 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; } @@ -68,15 +74,29 @@ FGJoystickInput::FGJoystickInput() FGJoystickInput::~FGJoystickInput() { + _remove(true); } +void FGJoystickInput::_remove(bool all) +{ + SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true); + + for (int i = 0; i < MAX_JOYSTICKS; i++) + { + // do not remove predefined joysticks info on reinit + if ((all)||(!bindings[i].predefined)) + js_nodes->removeChild("js", i, false); + 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); + SGPropertyNode_ptr js_nodes = fgGetNode("/input/joysticks", true); FGDeviceConfigurationMap configMap("Input/Joysticks", js_nodes, "js-named"); @@ -96,6 +116,7 @@ void FGJoystickInput::init() SG_LOG(SG_INPUT, SG_INFO, "Using existing bindings for joystick " << i); } else { + bindings[i].predefined = false; SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \"" << name << '"'); SGPropertyNode_ptr named; @@ -121,8 +142,7 @@ void FGJoystickInput::init() void FGJoystickInput::reinit() { SG_LOG(SG_INPUT, SG_DEBUG, "Re-Initializing joystick bindings"); - SGPropertyNode * js_nodes = fgGetNode("/input/joysticks", true); - js_nodes->removeChildren("js", false); + _remove(false); FGJoystickInput::init(); FGJoystickInput::postinit(); }