]> git.mxchange.org Git - flightgear.git/commitdiff
Jim Wilson:
authorehofman <ehofman>
Tue, 1 Jul 2003 16:32:00 +0000 (16:32 +0000)
committerehofman <ehofman>
Tue, 1 Jul 2003 16:32:00 +0000 (16:32 +0000)
This patch adds an "interval-sec" property which allows fixing an interval in seconds (or fraction of seconds) for the repeats for emulated axis controls (digital hats) on joysticks.

src/Input/input.cxx
src/Input/input.hxx

index 9e236f26910f3c69c68d3d4b4fea1a470096c205..f4df2882e636e54dbacb36f922bd3614bf6fe787 100644 (file)
@@ -195,7 +195,7 @@ void
 FGInput::update (double dt)
 {
   _update_keyboard();
-  _update_joystick();
+  _update_joystick(dt);
   _update_mouse();
 }
 
@@ -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;
     }
 
     //
@@ -690,7 +692,7 @@ FGInput::_update_keyboard ()
 
 
 void
-FGInput::_update_joystick ()
+FGInput::_update_joystick (double dt)
 {
   int modifiers = FG_MOD_NONE;  // FIXME: any way to get the real ones?
   int buttons;
@@ -727,17 +729,21 @@ FGInput::_update_joystick ()
       }
      
                                 // 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.
index 2ca5568a68d72bdb8739d75e4a37a5433ec855a5..3fe0783b8f4a8da2e23f7718df675c00a3aa989c 100644 (file)
@@ -297,6 +297,8 @@ private:
     float high_threshold;
     struct button low;
     struct button high;
+    float interval_sec;
+    double last_dt;
   };
 
 
@@ -381,7 +383,7 @@ private:
   /**
    * Update the joystick.
    */
-  void _update_joystick ();
+  void _update_joystick (double dt);
 
 
   /**