]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/input.cxx
Add support for moving cloud layers
[flightgear.git] / src / Input / input.cxx
index 26fd15bc5918907d140b616c35ef7ff282b0ee7b..cc6ca78fe10537c97b4a6b157fc179f23bb96966 100644 (file)
@@ -194,9 +194,9 @@ FGInput::init ()
 void 
 FGInput::update (double dt)
 {
-  _update_keyboard(dt);
+  _update_keyboard();
   _update_joystick(dt);
-  _update_mouse(dt);
+  _update_mouse();
 }
 
 void
@@ -537,6 +537,8 @@ FGInput::_init_joystick ()
       
       _init_button(axis_node->getChild("high"), a.high, "high");
       a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
+      a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0);
+      a.last_dt = 0.0;
     }
 
     //
@@ -549,7 +551,14 @@ FGInput::_init_joystick ()
       _init_button(js_node->getChild("button", j),
                    _joystick_bindings[i].buttons[j],
                    buf);
-                   
+      
+      // get interval-sec property             
+      button &b = _joystick_bindings[i].buttons[j];
+      const SGPropertyNode * button_node = js_node->getChild("button", j);
+      if (button_node != 0) {
+        b.interval_sec = button_node->getDoubleValue("interval-sec",0.0);
+        b.last_dt = 0.0;
+      }
     }
 
     js->setMinRange(minRange);
@@ -683,7 +692,7 @@ FGInput::_init_button (const SGPropertyNode * node,
 
 
 void
-FGInput::_update_keyboard (double dt)
+FGInput::_update_keyboard ()
 {
   // no-op
 }
@@ -692,17 +701,13 @@ FGInput::_update_keyboard (double dt)
 void
 FGInput::_update_joystick (double dt)
 {
-  static double _last_dt = 0.0;
   int modifiers = FG_MOD_NONE;  // FIXME: any way to get the real ones?
-  int i, j, buttons;
+  int buttons;
   // float js_val, diff;
   float axis_values[MAX_JOYSTICK_AXES];
 
-  // update the joystick 20 times per second.
-  if ((_last_dt += dt) > 50)
-    _last_dt = 0.0;
-  else
-    return;
+  int i;
+  int j;
 
   for ( i = 0; i < MAX_JOYSTICKS; i++) {
 
@@ -731,31 +736,40 @@ FGInput::_update_joystick (double dt)
       }
      
                                 // do we have to emulate axis buttons?
-      if (a.low.bindings[modifiers].size())
-        _update_button(_joystick_bindings[i].axes[j].low,
-                       modifiers,
-                       axis_values[j] < a.low_threshold,
-                       -1, -1);
+      a.last_dt += dt;
+      if(a.last_dt >= a.interval_sec) {
+        if (a.low.bindings[modifiers].size())
+          _update_button(_joystick_bindings[i].axes[j].low,
+                         modifiers,
+                         axis_values[j] < a.low_threshold,
+                         -1, -1);
       
-      if (a.high.bindings[modifiers].size())
-        _update_button(_joystick_bindings[i].axes[j].high,
-                       modifiers,
-                       axis_values[j] > a.high_threshold,
-                       -1, -1);
+        if (a.high.bindings[modifiers].size())
+          _update_button(_joystick_bindings[i].axes[j].high,
+                         modifiers,
+                         axis_values[j] > a.high_threshold,
+                         -1, -1);
+         a.last_dt -= a.interval_sec;
+      }
     }
 
                                 // Fire bindings for the buttons.
     for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
-      _update_button(_joystick_bindings[i].buttons[j],
-                     modifiers,
-                     (buttons & (1 << j)) > 0,
-                     -1, -1);
+      button &b = _joystick_bindings[i].buttons[j];
+      b.last_dt += dt;
+      if(b.last_dt >= b.interval_sec) {
+        _update_button(_joystick_bindings[i].buttons[j],
+                       modifiers,
+                       (buttons & (1 << j)) > 0,
+                       -1, -1);
+        b.last_dt -= b.interval_sec;
+      }
     }
   }
 }
 
 void
-FGInput::_update_mouse (double dt)
+FGInput::_update_mouse ()
 {
   mouse &m = _mouse_bindings[0];
   int mode =  m.mode_node->getIntValue();
@@ -805,11 +819,9 @@ FGInput::_read_bindings (const SGPropertyNode * node,
   SG_LOG(SG_INPUT, SG_DEBUG, "Reading all bindings");
   vector<SGPropertyNode_ptr> bindings = node->getChildren("binding");
   for (unsigned int i = 0; i < bindings.size(); i++) {
-    if (bindings[i]->nChildren() > 0) {
-      SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
-             << bindings[i]->getStringValue("command"));
-      binding_list[modifiers].push_back(new FGBinding(bindings[i]));
-    }
+    SG_LOG(SG_INPUT, SG_DEBUG, "Reading binding "
+           << bindings[i]->getStringValue("command"));
+    binding_list[modifiers].push_back(new FGBinding(bindings[i]));
   }
 
                                 // Read nested bindings for modifiers