]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/input.cxx
Added a <solve-weight> subtag of the approach/cruise parameters that can
[flightgear.git] / src / Input / input.cxx
index 4900c100c588a139551ff2cef7f7b9b9414372fd..9c52389d9b1dfc5674454e41f72d35191f068b49 100644 (file)
@@ -37,7 +37,7 @@
 #include STL_STRING
 #include <vector>
 
-#include <GL/glut.h>
+#include FG_GLUT_H
 
 #include <plib/pu.h>
 
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/props.hxx>
+#include <simgear/props/props.hxx>
 
 #include <Aircraft/aircraft.hxx>
-#include <Autopilot/auto_gui.hxx>
-#include <Autopilot/newauto.hxx>
+// #include <Autopilot/auto_gui.hxx>
+#include <Autopilot/xmlauto.hxx>
 #include <Cockpit/hud.hxx>
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
@@ -61,9 +61,7 @@
 
 #include "input.hxx"
 
-#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
 SG_USING_STD(ifstream);
-#endif
 SG_USING_STD(string);
 SG_USING_STD(vector);
 
@@ -90,26 +88,18 @@ FGBinding::FGBinding ()
 
 FGBinding::FGBinding (const SGPropertyNode * node)
   : _command(0),
-    _arg(new SGPropertyNode),
+    _arg(0),
     _setting(0)
 {
   read(node);
 }
 
-FGBinding::~FGBinding ()
-{
-//   delete _arg;                       // Delete the saved arguments
-//   delete _command_state;     // Delete the saved command state
-}
-
 void
 FGBinding::read (const SGPropertyNode * node)
 {
   const SGPropertyNode * conditionNode = node->getChild("condition");
-  if (conditionNode != 0) {
-    cerr << "Adding condition to binding" << endl;
-    setCondition(fgReadCondition(conditionNode));
-  }
+  if (conditionNode != 0)
+    setCondition(sgReadCondition(globals->get_props(), conditionNode));
 
   _command_name = node->getStringValue("command", "");
   if (_command_name.empty()) {
@@ -118,14 +108,6 @@ FGBinding::read (const SGPropertyNode * node)
     return;
   }
 
-  _command = globals->get_commands()->getCommand(_command_name);
-  if (_command == 0) {
-    SG_LOG(SG_INPUT, SG_ALERT, "Command " << _command_name << " is undefined");
-    _arg = 0;
-    return;
-  }
-
-  delete _arg;
   _arg = new SGPropertyNode;
   _setting = 0;
   copyProperties(node, _arg);  // FIXME: don't use whole node!!!
@@ -135,6 +117,8 @@ void
 FGBinding::fire () const
 {
   if (test()) {
+    if (_command == 0)
+      _command = globals->get_commands()->getCommand(_command_name);
     if (_command == 0) {
       SG_LOG(SG_INPUT, SG_WARN, "No command attached to binding");
     } else if (!(*_command)(_arg)) {
@@ -172,9 +156,6 @@ FGBinding::fire (double setting) const
 // Implementation of FGInput.
 ////////////////////////////////////////////////////////////////////////
 
-                                // From main.cxx
-extern void fgReshape( int width, int height );
-
 
 FGInput::FGInput ()
 {
@@ -204,24 +185,30 @@ FGInput::init ()
   glutPassiveMotionFunc (GLUTmotion);
 }
 
+void 
+FGInput::update (double dt)
+{
+  _update_keyboard();
+  _update_joystick(dt);
+  _update_mouse();
+}
+
 void
-FGInput::bind ()
+FGInput::suspend ()
 {
-  // no op
+    // NO-OP
 }
 
 void
-FGInput::unbind ()
+FGInput::resume ()
 {
-  // no op
+    // NO-OP
 }
 
-void 
-FGInput::update (double dt)
+bool
+FGInput::is_suspended () const
 {
-  _update_keyboard();
-  _update_joystick();
-  _update_mouse();
+    return false;
 }
 
 void
@@ -236,8 +223,8 @@ FGInput::makeDefault (bool status)
 void
 FGInput::doKey (int k, int modifiers, int x, int y)
 {
-  SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
-          << " with modifiers " << modifiers );
+    static SGPropertyNode *heading_enabled
+        = fgGetNode("/autopilot/locks/heading", true);
 
                                 // Sanity check.
   if (k < 0 || k >= MAX_KEYS) {
@@ -313,46 +300,13 @@ FGInput::doKey (int k, int modifiers, int x, int y)
 // START SPECIALS
 
         case 256+GLUT_KEY_F6: // F6 toggles Autopilot target location
-            if ( globals->get_autopilot()->get_HeadingMode() !=
-                 FGAutopilot::FG_HEADING_WAYPOINT ) {
-                globals->get_autopilot()->set_HeadingMode(
-                    FGAutopilot::FG_HEADING_WAYPOINT );
-                globals->get_autopilot()->set_HeadingEnabled( true );
+            if ( strcmp( heading_enabled->getStringValue(),
+                         "true-heading-hold" ) != 0 ) {
+                heading_enabled->setStringValue( "true-heading-hold" );
             } else {
-                globals->get_autopilot()->set_HeadingMode(
-                    FGAutopilot::FG_TC_HEADING_LOCK );
+                heading_enabled->setStringValue( "" );
             }
             return;
-        case 256+GLUT_KEY_F8: {// F8 toggles fog ... off fastest nicest...
-            const string &fog = fgGetString("/sim/rendering/fog");
-            if (fog == "disabled") {
-              fgSetString("/sim/rendering/fog", "fastest");
-              SG_LOG(SG_INPUT, SG_INFO, "Fog enabled, hint=fastest");
-            } else if (fog == "fastest") {
-              fgSetString("/sim/rendering/fog", "nicest");
-              SG_LOG(SG_INPUT, SG_INFO, "Fog enabled, hint=nicest");
-            } else if (fog == "nicest") {
-              fgSetString("/sim/rendering/fog", "disabled");
-              SG_LOG(SG_INPUT, SG_INFO, "Fog disabled");
-            } else {
-              fgSetString("/sim/rendering/fog", "disabled");
-              SG_LOG(SG_INPUT, SG_ALERT, "Unrecognized fog type "
-                     << fog << ", changed to 'disabled'");
-            }
-            return;
-        }
-        case 256+GLUT_KEY_F10: // F10 toggles menu on and off...
-            SG_LOG(SG_INPUT, SG_INFO, "Invoking call back function");
-            guiToggleMenu();
-            return;
-        case 256+GLUT_KEY_F11: // F11 Altitude Dialog.
-            SG_LOG(SG_INPUT, SG_INFO, "Invoking Altitude call back function");
-            NewAltitude( NULL );
-            return;
-        case 256+GLUT_KEY_F12: // F12 Heading Dialog...
-            SG_LOG(SG_INPUT, SG_INFO, "Invoking Heading call back function");
-            NewHeading( NULL );
-            return;
         }
 
 // END SPECIALS
@@ -378,9 +332,9 @@ FGInput::doMouseClick (int b, int updown, int x, int y)
   if (mode.pass_through) {
     if (puMouse(b, updown, x, y))
       return;
-    else if ((current_panel != 0) &&
-             current_panel->getVisibility() &&
-             current_panel->doMouseAction(b, updown, x, y))
+    else if ((globals->get_current_panel() != 0) &&
+             globals->get_current_panel()->getVisibility() &&
+             globals->get_current_panel()->doMouseAction(b, updown, x, y))
       return;
     else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
       return;
@@ -455,7 +409,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) {
@@ -467,6 +420,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);
   }
@@ -493,10 +448,9 @@ 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 {
-#ifdef FG_PLIB_JOYSTICK_GETNAME
       bool found_js = false;
       const char * name = js->getName();
       SG_LOG(SG_INPUT, SG_INFO, "Looking for bindings for joystick \""
@@ -518,7 +472,6 @@ FGInput::_init_joystick ()
         if (found_js)
             break;
       }
-#endif
     }
 #ifdef WIN32
     JOYCAPS jsCaps ;
@@ -579,6 +532,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;
     }
 
     //
@@ -591,7 +546,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);
@@ -654,8 +616,11 @@ FGInput::_init_mouse ()
                                 // Grab node pointers
     char buf[64];
     sprintf(buf, "/devices/status/mice/mouse[%d]/mode", i);
-    m.mode_node = fgGetNode(buf, true);
-    m.mode_node->setIntValue(0);
+    m.mode_node = fgGetNode(buf);
+    if (m.mode_node == NULL) {
+      m.mode_node = fgGetNode(buf, true);
+      m.mode_node->setIntValue(0);
+    }
     for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
       sprintf(buf, "/devices/status/mice/mouse[%d]/button[%d]", i, j);
       m.mouse_button_nodes[j] = fgGetNode(buf, true);
@@ -732,7 +697,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;
@@ -769,25 +734,34 @@ 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.
     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;
+      }
     }
   }
 }
@@ -870,22 +844,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