]> git.mxchange.org Git - flightgear.git/commitdiff
- modified FGBinding to keep a local copy of the argument property
authorcurt <curt>
Fri, 29 Jun 2001 03:47:07 +0000 (03:47 +0000)
committercurt <curt>
Fri, 29 Jun 2001 03:47:07 +0000 (03:47 +0000)
  node, and to modify that directly for scaling events: that will make
  handling joystick axes much more efficient
- modified FGBinding to work with the new command state, so that
  commands can save their state (i.e. compiled arguments) from the last
  pass
- removed FGBinding::_fire implementation
- implemented FGBinding copy constructor

src/Input/input.cxx

index c66023575fdba1346085d8ccd21a88512713d8e4..73ee635dd60e0028fcfde13264cf63208fb312a3 100644 (file)
@@ -85,19 +85,36 @@ SG_USING_STD(vector);
 ////////////////////////////////////////////////////////////////////////
 
 FGBinding::FGBinding ()
-  : _command(0), _arg(0)
+  : _command(0),
+    _arg(new SGPropertyNode),
+    _setting(0),
+    _command_state(0)
 {
 }
 
+FGBinding::FGBinding (const FGBinding &binding)
+  : _command_name(binding._command_name),
+    _command(binding._command),
+    _arg(new SGPropertyNode),
+    _setting(0),
+    _command_state(0)
+{
+  copyProperties(binding._arg, _arg);
+}
+
 FGBinding::FGBinding (const SGPropertyNode * node)
-  : _command(0), _arg(0)
+  : _command(0),
+    _arg(new SGPropertyNode),
+    _setting(0),
+    _command_state(0)
 {
   read(node);
 }
 
 FGBinding::~FGBinding ()
 {
-  // no op
+  delete _arg;                 // Delete the saved arguments
+  delete _command_state;       // Delete the saved command state
 }
 
 void
@@ -116,33 +133,32 @@ FGBinding::read (const SGPropertyNode * node)
     _arg = 0;
     return;
   }
-  _arg = node;                 // FIXME: don't use whole node!!!
+
+  delete _arg;
+  _arg = new SGPropertyNode;
+  _setting = 0;
+  copyProperties(node, _arg);  // FIXME: don't use whole node!!!
 }
 
 void
 FGBinding::fire () const
 {
-  _fire(_arg);
+  if (_command == 0) {
+    SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
+  } else if (!(*_command)(_arg, &_command_state)) {
+    SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name);
+  }
 }
 
 void
 FGBinding::fire (double setting) const
 {
-  SGPropertyNode arg;
-  if (_arg != 0)
-    copyProperties(_arg, &arg);
-  arg.setDoubleValue("setting", setting);
-  _fire(&arg);
-}
-
-void
-FGBinding::_fire(const SGPropertyNode * arg) const
-{
-  if (_command == 0) {
-    SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
-  } else if (!(*_command)(arg)) {
-    SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name);
-  }
+                               // A value is automatically added to
+                               // the args
+  if (_setting == 0)           // save the setting node for efficiency
+    _setting = _arg->getChild("setting", 0, true);
+  _setting->setDoubleValue(setting);
+  fire();
 }