]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/input.cxx
Add David Culp's AI model manager code which is derived from David Luff's AI/ATC...
[flightgear.git] / src / Input / input.cxx
index c6700eb5e86b0fd81896d825f47886ad008b6a2e..54cecb9c2a07a624da0500d7ca0c1de5e5e48347 100644 (file)
@@ -37,7 +37,7 @@
 #include STL_STRING
 #include <vector>
 
-#include GLUT_H
+#include FG_GLUT_H
 
 #include <plib/pu.h>
 
@@ -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
@@ -415,7 +415,6 @@ FGInput::doMouseMotion (int x, int y)
 void
 FGInput::_init_keyboard ()
 {
-                                // TODO: zero the old bindings first.
   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing key bindings");
   SGPropertyNode * key_nodes = fgGetNode("/input/keyboard");
   if (key_nodes == 0) {
@@ -427,6 +426,8 @@ FGInput::_init_keyboard ()
   for (unsigned int i = 0; i < keys.size(); i++) {
     int index = keys[i]->getIndex();
     SG_LOG(SG_INPUT, SG_DEBUG, "Binding key " << index);
+
+    _key_bindings[index].bindings->clear();
     _key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
     _read_bindings(keys[i], _key_bindings[index].bindings, FG_MOD_NONE);
   }
@@ -453,7 +454,7 @@ FGInput::_init_joystick ()
     jsJoystick * js = new jsJoystick(i);
     _joystick_bindings[i].js = js;
     if (js->notWorking()) {
-      SG_LOG(SG_INPUT, SG_WARN, "Joystick " << i << " not found");
+      SG_LOG(SG_INPUT, SG_DEBUG, "Joystick " << i << " not found");
       continue;
     } else {
       bool found_js = false;
@@ -537,6 +538,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 +552,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 +693,7 @@ FGInput::_init_button (const SGPropertyNode * node,
 
 
 void
-FGInput::_update_keyboard (double dt)
+FGInput::_update_keyboard ()
 {
   // no-op
 }
@@ -692,19 +702,13 @@ FGInput::_update_keyboard (double dt)
 void
 FGInput::_update_joystick (double dt)
 {
-#ifdef REMOVE_ME_AFTER_FLIGHTGEAR_0_9_2_RELEASE
-  static double _last_dt = 1.0;
-#else
-  static double _last_dt = 0.0;
-#endif
   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];
 
-#ifdef REMOVE_ME_AFTER_FLIGHTGEAR_0_9_2_RELEASE
-  _last_dt += dt;
-#endif
+  int i;
+  int j;
 
   for ( i = 0; i < MAX_JOYSTICKS; i++) {
 
@@ -733,42 +737,40 @@ FGInput::_update_joystick (double dt)
       }
      
                                 // do we have to emulate axis buttons?
-      if (_last_dt > 0.05) {
+      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);
+         a.last_dt -= a.interval_sec;
       }
     }
 
                                 // Fire bindings for the buttons.
-    if (_last_dt > 0.05) {
-      for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
+    for (j = 0; j < _joystick_bindings[i].nbuttons; j++) {
+      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;
       }
     }
   }
-
-#if REMOVE_ME_AFTER_FLIGHTGEAR_0_9_2_RELEASE
-  if (_last_dt > 0.05) {
-    while(_last_dt >= 0.05)
-      _last_dt -= 0.05;
-  }
-#endif
 }
 
 void
-FGInput::_update_mouse (double dt)
+FGInput::_update_mouse ()
 {
   mouse &m = _mouse_bindings[0];
   int mode =  m.mode_node->getIntValue();
@@ -818,11 +820,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
@@ -847,22 +847,27 @@ FGInput::_read_bindings (const SGPropertyNode * node,
 const vector<FGBinding *> &
 FGInput::_find_key_bindings (unsigned int k, int modifiers)
 {
+  unsigned char kc = (unsigned char)k;
   button &b = _key_bindings[k];
 
                                 // Try it straight, first.
   if (b.bindings[modifiers].size() > 0)
     return b.bindings[modifiers];
 
+                                // Alt-Gr is CTRL+ALT
+  else if (modifiers&(FG_MOD_CTRL|FG_MOD_ALT))
+    return _find_key_bindings(k, modifiers&~(FG_MOD_CTRL|FG_MOD_ALT));
+
                                 // Try removing the control modifier
                                 // for control keys.
-  else if ((modifiers&FG_MOD_CTRL) && iscntrl(k))
+  else if ((modifiers&FG_MOD_CTRL) && iscntrl(kc))
     return _find_key_bindings(k, modifiers&~FG_MOD_CTRL);
 
                                 // Try removing shift modifier 
                                 // for upper case or any punctuation
                                 // (since different keyboards will
                                 // shift different punctuation types)
-  else if ((modifiers&FG_MOD_SHIFT) && (isupper(k) || ispunct(k)))
+  else if ((modifiers&FG_MOD_SHIFT) && (isupper(kc) || ispunct(kc)))
     return _find_key_bindings(k, modifiers&~FG_MOD_SHIFT);
 
                                 // Try removing alt modifier for