]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
apt.dat parser: clearer log and exception messages
[flightgear.git] / src / Main / fg_commands.cxx
index 7711f6b4f0acc194326f5f109e98d871cd7e6fcb..1e93a0b7b70e6cd32a12381c525c1646e5ab3f25 100644 (file)
 #include <simgear/structure/exception.hxx>
 #include <simgear/structure/commands.hxx>
 #include <simgear/props/props.hxx>
+#include <simgear/props/props_io.hxx>
 #include <simgear/structure/event_mgr.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/timing/sg_time.hxx>
+#include <Network/RemoteXMLRequest.hxx>
 
-#include <Cockpit/panel.hxx>
-#include <Cockpit/panel_io.hxx>
 #include <FDM/flight.hxx>
 #include <GUI/gui.h>
 #include <GUI/new_gui.hxx>
 #include <GUI/dialog.hxx>
 #include <Aircraft/replay.hxx>
 #include <Scenery/scenery.hxx>
+#include <Scenery/tilemgr.hxx>
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.hxx>
 #include <Airports/xmlloader.hxx>
-#include <ATC/CommStation.hxx>
-#include <Navaids/navrecord.hxx>
-#include <Navaids/navlist.hxx>
+#include <Network/HTTPClient.hxx>
+#include <Viewer/viewmgr.hxx>
+#include <Viewer/view.hxx>
+#include <Environment/presets.hxx>
+#include <Navaids/NavDataCache.hxx>
 
 #include "fg_init.hxx"
 #include "fg_io.hxx"
 #include "globals.hxx"
 #include "logger.hxx"
 #include "util.hxx"
-#include "viewmgr.hxx"
 #include "main.hxx"
-#include <Main/viewer.hxx>
-#include <Environment/presets.hxx>
+#include "positioninit.hxx"
+
+#include <boost/scoped_array.hpp>
+
+#if FG_HAVE_GPERFTOOLS
+# include <google/profiler.h>
+#endif
+
+#if defined(HAVE_QT)
+#include <GUI/QtLauncher.hxx>
+#endif
 
 using std::string;
 using std::ifstream;
 using std::ofstream;
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Static helper functions.
 ////////////////////////////////////////////////////////////////////////
@@ -154,7 +164,7 @@ compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
 }
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Command implementations.
 ////////////////////////////////////////////////////////////////////////
@@ -188,31 +198,7 @@ do_exit (const SGPropertyNode * arg)
 {
     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
     fgSetBool("/sim/signals/exit", true);
-
-    if (fgGetBool("/sim/startup/save-on-exit")) {
-#ifdef _WIN32
-        char* envp = ::getenv( "APPDATA" );
-        if ( envp != NULL ) {
-            SGPath config( envp );
-            config.append( "flightgear.org" );
-#else
-        if ( homedir != NULL ) {
-            SGPath config( homedir );
-            config.append( ".fgfs" );
-#endif
-            config.append( "autosave.xml" );
-            config.create_dir( 0700 );
-            SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str());
-            try {
-                writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
-            } catch (const sg_exception &e) {
-                guiErrorMessage("Error writing autosave.xml: ", e);
-            }
-
-            SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
-        }
-    }
-    
+    globals->saveUserSettings();
     fgOSExit(arg->getIntValue("status", 0));
     return true;
 }
@@ -224,107 +210,67 @@ do_exit (const SGPropertyNode * arg)
 static bool
 do_reset (const SGPropertyNode * arg)
 {
-    fgReInitSubsystems();
+    fgResetIdleState();
     return true;
 }
 
 
 /**
- * Built-in command: reinitialize one or more subsystems.
- *
- * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
- * none is specified, reinitialize all of them.
+ * Change aircraft
  */
 static bool
-do_reinit (const SGPropertyNode * arg)
+do_switch_aircraft (const SGPropertyNode * arg)
 {
-    bool result = true;
-
-    vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
-    if (subsystems.size() == 0) {
-        globals->get_subsystem_mgr()->reinit();
-    } else {
-        for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
-            const char * name = subsystems[i]->getStringValue();
-            SGSubsystem * subsystem = globals->get_subsystem(name);
-            if (subsystem == 0) {
-                result = false;
-                SG_LOG( SG_GENERAL, SG_ALERT,
-                        "Subsystem " << name << " not found" );
-            } else {
-                subsystem->reinit();
-            }
-        }
-    }
-
-    globals->get_event_mgr()->reinit();
-
-    return result;
+    fgSetString("/sim/aircraft", arg->getStringValue("aircraft"));
+    // start a reset
+    fgResetIdleState();
+    return true;
 }
 
-#if 0
-  //
-  // these routines look useful ??? but are never used in the code ???
-  //
-
 /**
- * Built-in command: suspend one or more subsystems.
- *
- * subsystem[*] - the name(s) of the subsystem(s) to suspend.
  */
 static bool
-do_suspend (const SGPropertyNode * arg)
+do_reposition (const SGPropertyNode * arg)
 {
-    bool result = true;
-
-    vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
-    for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
-        const char * name = subsystems[i]->getStringValue();
-        SGSubsystem * subsystem = globals->get_subsystem(name);
-        if (subsystem == 0) {
-            result = false;
-            SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
-        } else {
-            subsystem->suspend();
-        }
-    }
-    return result;
+  fgStartReposition();
+  return true;
 }
 
 /**
- * Built-in command: suspend one or more subsystems.
- *
- * subsystem[*] - the name(s) of the subsystem(s) to suspend.
+ * Built-in command: replay the FDR buffer
  */
 static bool
-do_resume (const SGPropertyNode * arg)
+do_replay (const SGPropertyNode * arg)
 {
-    bool result = true;
-
-    vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
-    for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
-        const char * name = subsystems[i]->getStringValue();
-        SGSubsystem * subsystem = globals->get_subsystem(name);
-        if (subsystem == 0) {
-            result = false;
-            SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
-        } else {
-            subsystem->resume();
-        }
-    }
-    return result;
+    FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
+    return r->start();
 }
 
-#endif
-
+/**
+ * Built-in command: pause/unpause the sim
+ */
 static bool
 do_pause (const SGPropertyNode * arg)
 {
+    bool forcePause = arg->getBoolValue("force-pause", false );
+    bool forcePlay = arg->getBoolValue("force-play", false );
+
     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
-    fgSetBool("/sim/freeze/master",!paused);
-    fgSetBool("/sim/freeze/clock",!paused);
-    if (fgGetBool("/sim/freeze/replay-state",false))
-        fgSetBool("/sim/replay/disable",true);
+
+    if(forcePause) paused = false;
+    if(forcePlay) paused = true;
+
+    if (paused && (fgGetInt("/sim/freeze/replay-state",0)>0))
+    {
+        do_replay(NULL);
+    }
+    else
+    {
+        fgSetBool("/sim/freeze/master",!paused);
+        fgSetBool("/sim/freeze/clock",!paused);
+    }
+  
+    syncPausePopupState();
     return true;
 }
 
@@ -337,17 +283,19 @@ do_pause (const SGPropertyNode * arg)
 static bool
 do_load (const SGPropertyNode * arg)
 {
-    string file = arg->getStringValue("file", "fgfs.sav");
-    if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
-        file += ".sav";
+    SGPath file(arg->getStringValue("file", "fgfs.sav"));
 
-    if (!fgValidatePath(file.c_str(), false)) {
+    if (file.extension() != "sav")
+        file.concat(".sav");
+
+    std::string validated_path = fgValidatePath(file, false);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
                 "(unauthorized access)");
         return false;
     }
 
-    ifstream input(file.c_str());
+    ifstream input(validated_path.c_str());
     if (input.good() && fgLoadFlight(input)) {
         input.close();
         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
@@ -368,11 +316,13 @@ do_load (const SGPropertyNode * arg)
 static bool
 do_save (const SGPropertyNode * arg)
 {
-    string file = arg->getStringValue("file", "fgfs.sav");
-    if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
-        file += ".sav";
+    SGPath file(arg->getStringValue("file", "fgfs.sav"));
+
+    if (file.extension() != "sav")
+        file.concat(".sav");
 
-    if (!fgValidatePath(file.c_str(), false)) {
+    std::string validated_path = fgValidatePath(file, true);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
                 "(unauthorized access)");
         return false;
@@ -380,7 +330,7 @@ do_save (const SGPropertyNode * arg)
 
     bool write_all = arg->getBoolValue("write-all", false);
     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
-    ofstream output(file.c_str());
+    ofstream output(validated_path.c_str());
     if (output.good() && fgSaveFlight(output, write_all)) {
         output.close();
         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
@@ -391,6 +341,30 @@ do_save (const SGPropertyNode * arg)
     }
 }
 
+/**
+ * Built-in command: save flight recorder tape.
+ *
+ */
+static bool
+do_save_tape (const SGPropertyNode * arg)
+{
+    FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
+    replay->saveTape(arg);
+
+    return true;
+}
+/**
+ * Built-in command: load flight recorder tape.
+ *
+ */
+static bool
+do_load_tape (const SGPropertyNode * arg)
+{
+    FGReplay* replay = (FGReplay*) globals->get_subsystem("replay");
+    replay->loadTape(arg);
+
+    return true;
+}
 
 /**
  * Built-in command: (re)load the panel.
@@ -402,49 +376,15 @@ do_save (const SGPropertyNode * arg)
 static bool
 do_panel_load (const SGPropertyNode * arg)
 {
-  string panel_path =
-    arg->getStringValue("path", fgGetString("/sim/panel/path"));
-  if (panel_path.empty()) {
-    return false;
+  string panel_path = arg->getStringValue("path");
+  if (!panel_path.empty()) {
+    // write to the standard property, which will force a load
+    fgSetString("/sim/panel/path", panel_path.c_str());
   }
   
-  FGPanel * new_panel = fgReadPanel(panel_path);
-  if (new_panel == 0) {
-    SG_LOG(SG_INPUT, SG_ALERT,
-          "Error reading new panel from " << panel_path);
-    return false;
-  }
-  SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
-  globals->get_current_panel()->unbind();
-  delete globals->get_current_panel();
-  globals->set_current_panel( new_panel );
-  globals->get_current_panel()->bind();
   return true;
 }
 
-
-/**
- * Built-in command: pass a mouse click to the panel.
- *
- * button: the mouse button number, zero-based.
- * is-down: true if the button is down, false if it is up.
- * x-pos: the x position of the mouse click.
- * y-pos: the y position of the mouse click.
- */
-static bool
-do_panel_mouse_click (const SGPropertyNode * arg)
-{
-  if (globals->get_current_panel() != 0)
-    return globals->get_current_panel()
-      ->doMouseAction(arg->getIntValue("button"),
-                     arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
-                     arg->getIntValue("x-pos"),
-                     arg->getIntValue("y-pos"));
-  else
-    return false;
-}
-
-
 /**
  * Built-in command: (re)load preferences.
  *
@@ -466,17 +406,36 @@ do_preferences_load (const SGPropertyNode * arg)
 }
 
 static void
-do_view_next( bool )
+do_view_next(bool do_it)
 {
+  // Only switch view if really requested to do so (and not for example while
+  // reset/reposition where /command/view/next is set to false)
+  if( do_it )
+  {
     globals->get_current_view()->setHeadingOffset_deg(0.0);
     globals->get_viewmgr()->next_view();
+  }
 }
 
 static void
-do_view_prev( bool )
+do_view_prev(bool do_it)
 {
+  if( do_it )
+  {
     globals->get_current_view()->setHeadingOffset_deg(0.0);
     globals->get_viewmgr()->prev_view();
+  }
+}
+
+/**
+ * An fgcommand to toggle fullscreen mode.
+ * No parameters.
+ */
+static bool
+do_toggle_fullscreen(const SGPropertyNode *arg)
+{
+    fgOSFullScreen();
+    return true;
 }
 
 /**
@@ -554,154 +513,48 @@ do_hires_screen_capture (const SGPropertyNode * arg)
 static bool
 do_tile_cache_reload (const SGPropertyNode * arg)
 {
-    static const SGPropertyNode *master_freeze
-       = fgGetNode("/sim/freeze/master");
+    SGPropertyNode *master_freeze = fgGetNode("/sim/freeze/master");
     bool freeze = master_freeze->getBoolValue();
     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
     if ( !freeze ) {
-       fgSetBool("/sim/freeze/master", true);
+        master_freeze->setBoolValue(true);
     }
 
     globals->get_subsystem("tile-manager")->reinit();
 
     if ( !freeze ) {
-       fgSetBool("/sim/freeze/master", false);
+        master_freeze->setBoolValue(false);
     }
     return true;
 }
 
-
-#if 0
-These do_set_(some-environment-parameters) are deprecated and no longer 
-useful/functional - Torsten Dreyer, January 2011
 /**
- * Set the sea level outside air temperature and assigning that to all
- * boundary and aloft environment layers.
+ * Reload the materials definition
  */
 static bool
-do_set_sea_level_degc ( double temp_sea_level_degc)
-{
-    SGPropertyNode *node, *child;
-
-    // boundary layers
-    node = fgGetNode( "/environment/config/boundary" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "temperature-sea-level-degc",
-                              temp_sea_level_degc );
-       ++i;
-      }
-    }
-
-    // aloft layers
-    node = fgGetNode( "/environment/config/aloft" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "temperature-sea-level-degc",
-                              temp_sea_level_degc );
-       ++i;
-      }
-    }
-
-    return true;
-}
-
-static bool
-do_set_sea_level_degc (const SGPropertyNode * arg)
-{
-    return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
-}
-
-
-/**
- * Set the outside air temperature at the "current" altitude by first
- * calculating the corresponding sea level temp, and assigning that to
- * all boundary and aloft environment layers.
- */
-static bool
-do_set_oat_degc (const SGPropertyNode * arg)
-{
-    double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
-    // check for an altitude specified in the arguments, otherwise use
-    // current aircraft altitude.
-    const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
-    if ( altitude_ft == NULL ) {
-        altitude_ft = fgGetNode("/position/altitude-ft");
-    }
-
-    FGEnvironment dummy;       // instantiate a dummy so we can leech a method
-    dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
-    dummy.set_temperature_degc( oat_degc );
-    return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
-}
-
-/**
- * Set the sea level outside air dewpoint and assigning that to all
- * boundary and aloft environment layers.
- */
-static bool
-do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
-{
-
-    SGPropertyNode *node, *child;
-
-    // boundary layers
-    node = fgGetNode( "/environment/config/boundary" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "dewpoint-sea-level-degc",
-                              dewpoint_sea_level_degc );
-       ++i;
-      }
-    }
-
-    // aloft layers
-    node = fgGetNode( "/environment/config/aloft" );
-    if ( node != NULL ) {
-      int i = 0;
-      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
-       child->setDoubleValue( "dewpoint-sea-level-degc",
-                              dewpoint_sea_level_degc );
-       ++i;
-      }
-    }
-
+do_materials_reload (const SGPropertyNode * arg)
+{
+    SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
+    SGMaterialLib* new_matlib =  new SGMaterialLib;
+    SGPath mpath( globals->get_fg_root() );
+    mpath.append( fgGetString("/sim/rendering/materials-file") );
+    bool loaded = new_matlib->load(globals->get_fg_root(), 
+                                  mpath.str(), 
+                                  globals->get_props());
+
+    if ( ! loaded ) {
+       SG_LOG( SG_GENERAL, SG_ALERT,
+               "Error loading materials file " << mpath.str() );
+       return false;
+    }  
+
+    globals->set_matlib(new_matlib);    
+    FGTileMgr* tileManager = static_cast<FGTileMgr*>(globals->get_subsystem("tile-manager"));
+    tileManager->materialLibChanged();
+    
     return true;
 }
 
-static bool
-do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
-{
-    return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
-}
-
-/**
- * Set the outside air dewpoint at the "current" altitude by first
- * calculating the corresponding sea level dewpoint, and assigning
- * that to all boundary and aloft environment layers.
- */
-static bool
-do_set_dewpoint_degc (const SGPropertyNode * arg)
-{
-    double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
-
-    // check for an altitude specified in the arguments, otherwise use
-    // current aircraft altitude.
-    const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
-    if ( altitude_ft == NULL ) {
-        altitude_ft = fgGetNode("/position/altitude-ft");
-    }
-
-    FGEnvironment dummy;       // instantiate a dummy so we can leech a method
-    dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
-    dummy.set_dewpoint_degc( dewpoint_degc );
-    return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
-}
-#endif
-
 /**
  * Built-in command: toggle a bool property value.
  *
@@ -726,15 +579,18 @@ static bool
 do_property_assign (const SGPropertyNode * arg)
 {
   SGPropertyNode * prop = get_prop(arg);
-  const SGPropertyNode * prop2 = get_prop2(arg);
   const SGPropertyNode * value = arg->getNode("value");
 
   if (value != 0)
       return prop->setUnspecifiedValue(value->getStringValue());
-  else if (prop2)
-      return prop->setUnspecifiedValue(prop2->getStringValue());
   else
-      return false;
+  {
+      const SGPropertyNode * prop2 = get_prop2(arg);
+      if (prop2)
+          return prop->setUnspecifiedValue(prop2->getStringValue());
+      else
+          return false;
+  }
 }
 
 
@@ -889,7 +745,12 @@ static bool
 do_property_cycle (const SGPropertyNode * arg)
 {
     SGPropertyNode * prop = get_prop(arg);
-    vector<SGPropertyNode_ptr> values = arg->getChildren("value");
+    std::vector<SGPropertyNode_ptr> values = arg->getChildren("value");
+    
+    bool wrap = arg->getBoolValue("wrap", true);
+    // compatible with knob/pick animations
+    int offset = arg->getIntValue("offset", 1);
+    
     int selection = -1;
     int nSelections = values.size();
 
@@ -901,15 +762,22 @@ do_property_cycle (const SGPropertyNode * arg)
                                 // Try to find the current selection
     for (int i = 0; i < nSelections; i++) {
         if (compare_values(prop, values[i])) {
-            selection = i + 1;
+            selection = i;
             break;
         }
     }
 
-                                // Default or wrap to the first selection
-    if (selection < 0 || selection >= nSelections)
+    if (selection < 0) { // default to first selection
         selection = 0;
-
+    } else {
+        selection += offset;
+        if (wrap) {
+            selection = (selection + nSelections) % nSelections;
+        } else {
+            SG_CLAMP_RANGE(selection, 0, nSelections - 1);
+        }
+    }
+    
     prop->setUnspecifiedValue(values[selection]->getStringValue());
     return true;
 }
@@ -932,6 +800,90 @@ do_property_randomize (const SGPropertyNode * arg)
     return true;
 }
 
+/**
+ * Built-in command: interpolate a property value over time
+ *
+ * property:        the name of the property value to interpolate.
+ * type:            the interpolation type ("numeric", "color", etc.)
+ * easing:          name of easing function (see http://easings.net/)
+ * value[0..n]      any number of constant values to interpolate
+ * time/rate[0..n]  time between each value, number of time elements must
+ *                  match those of value elements. Instead of time also rate can
+ *                  be used which automatically calculates the time to change
+ *                  the property value at the given speed.
+ * -or-
+ * property[1..n+1] any number of target values taken from named properties
+ * time/rate[0..n]  time between each value, number of time elements must
+ *                  match those of value elements. Instead of time also rate can
+ *                  be used which automatically calculates the time to change
+ *                  the property value at the given speed.
+ */
+static bool
+do_property_interpolate (const SGPropertyNode * arg)
+{
+  SGPropertyNode * prop = get_prop(arg);
+  if( !prop )
+    return false;
+
+  simgear::PropertyList time_nodes = arg->getChildren("time");
+  simgear::PropertyList rate_nodes = arg->getChildren("rate");
+
+  if( !time_nodes.empty() && !rate_nodes.empty() )
+    // mustn't specify time and rate
+    return false;
+
+  simgear::PropertyList::size_type num_times = time_nodes.empty()
+                                             ? rate_nodes.size()
+                                             : time_nodes.size();
+
+  simgear::PropertyList value_nodes = arg->getChildren("value");
+  if( value_nodes.empty() )
+  {
+    simgear::PropertyList prop_nodes = arg->getChildren("property");
+
+    // must have one more property node
+    if( prop_nodes.size() != num_times + 1 )
+      return false;
+
+    value_nodes.reserve(num_times);
+    for( size_t i = 1; i < prop_nodes.size(); ++i )
+      value_nodes.push_back( fgGetNode(prop_nodes[i]->getStringValue()) );
+  }
+
+  // must match
+  if( value_nodes.size() != num_times )
+    return false;
+
+  double_list deltas;
+  deltas.reserve(num_times);
+
+  if( !time_nodes.empty() )
+  {
+    for( size_t i = 0; i < num_times; ++i )
+      deltas.push_back( time_nodes[i]->getDoubleValue() );
+  }
+  else
+  {
+    for( size_t i = 0; i < num_times; ++i )
+    {
+      // TODO calculate delta based on property type
+      double delta = value_nodes[i]->getDoubleValue()
+                   - ( i > 0
+                     ? value_nodes[i - 1]->getDoubleValue()
+                     : prop->getDoubleValue()
+                     );
+      deltas.push_back( fabs(delta / rate_nodes[i]->getDoubleValue()) );
+    }
+  }
+
+  return prop->interpolate
+  (
+    arg->getStringValue("type", "numeric"),
+    value_nodes,
+    deltas,
+    arg->getStringValue("easing", "linear")
+  );
+}
 
 /**
  * Built-in command: reinit the data logging system based on the
@@ -956,7 +908,10 @@ static bool
 do_dialog_new (const SGPropertyNode * arg)
 {
     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
-
+    if (!gui) {
+      return false;
+    }
+  
     // Note the casting away of const: this is *real*.  Doing a
     // "dialog-apply" command later on will mutate this property node.
     // I'm not convinced that this isn't the Right Thing though; it
@@ -1018,6 +973,35 @@ do_dialog_update (const SGPropertyNode * arg)
     }
 }
 
+static bool
+do_open_browser (const SGPropertyNode * arg)
+{
+    string path;
+    if (arg->hasValue("path"))
+        path = arg->getStringValue("path");
+    else
+    if (arg->hasValue("url"))
+        path = arg->getStringValue("url");
+    else
+        return false;
+
+    return openBrowser(path);
+}
+
+static bool
+do_open_launcher(const SGPropertyNode *)
+{
+#if defined(HAVE_QT)
+    bool ok = flightgear::runInAppLauncherDialog();
+    if (ok) {
+        // start a full reset
+        fgResetIdleState();
+    }
+    return ok;
+#else
+    return false;
+#endif
+}
 
 /**
  * Apply a value in the active XML-configured dialog.
@@ -1064,14 +1048,9 @@ static bool
 do_add_model (const SGPropertyNode * arg)
 {
     SGPropertyNode * model = fgGetNode("models", true);
-    for (int i = 0;; i++) {
-        if (i < 0)
-            return false;
-        if (!model->getChild("model", i, false)) {
-            model = model->getChild("model", i, true);
-            break;
-        }
-    }
+    int i;
+    for (i = 0; model->hasChild("model",i); i++);
+    model = model->getChild("model", i, true);
     copyProperties(arg, model);
     if (model->hasValue("elevation-m"))
         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
@@ -1082,66 +1061,6 @@ do_add_model (const SGPropertyNode * arg)
     return true;
 }
 
-
-/**
- * Set mouse cursor coordinates and cursor shape.
- */
-static bool
-do_set_cursor (const SGPropertyNode * arg)
-{
-    if (arg->hasValue("x") || arg->hasValue("y")) {
-        SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
-        SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
-        int x = arg->getIntValue("x", mx->getIntValue());
-        int y = arg->getIntValue("y", my->getIntValue());
-        fgWarpMouse(x, y);
-        mx->setIntValue(x);
-        my->setIntValue(y);
-    }
-
-    SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
-    if (cursor->getType() != simgear::props::NONE)
-        fgSetMouseCursor(cursor->getIntValue());
-
-    cursor->setIntValue(fgGetMouseCursor());
-    return true;
-}
-
-
-/**
- * Built-in command: play an audio message (i.e. a wav file) This is
- * fire and forget.  Call this once per message and it will get dumped
- * into a queue.  Messages are played sequentially so they do not
- * overlap.
- */
-static bool
-do_play_audio_sample (const SGPropertyNode * arg)
-{
-    string path = arg->getStringValue("path");
-    string file = arg->getStringValue("file");
-    float volume = arg->getFloatValue("volume");
-    // cout << "playing " << path << " / " << file << endl;
-    try {
-        static FGSampleQueue *queue = 0;
-        if ( !queue ) {
-           SGSoundMgr *smgr = globals->get_soundmgr();
-           queue = new FGSampleQueue(smgr, "chatter");
-           queue->tie_to_listener();
-        }
-
-        SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
-        msg->set_volume( volume );
-        queue->add( msg );
-
-        return true;
-
-    } catch (const sg_io_exception&) {
-        SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
-                "failed to load" << path << '/' << file);
-        return false;
-    }
-}
-
 /**
  * Built-in command: commit presets (read from in /sim/presets/)
  */
@@ -1149,12 +1068,12 @@ static bool
 do_presets_commit (const SGPropertyNode * arg)
 {
     if (fgGetBool("/sim/initialized", false)) {
-      fgReInitSubsystems();
+      fgResetIdleState();
     } else {
       // Nasal can trigger this during initial init, which confuses
       // the logic in ReInitSubsystems, since initial state has not been
       // saved at that time. Short-circuit everything here.
-      fgInitPosition();
+      flightgear::initPosition();
     }
     
     return true;
@@ -1171,24 +1090,6 @@ do_log_level (const SGPropertyNode * arg)
    return true;
 }
 
-/**
- * Built-in command: replay the FDR buffer
- */
-static bool
-do_replay (const SGPropertyNode * arg)
-{
-    // freeze the fdm, resume from sim pause 
-    fgSetInt( "/sim/freeze/replay-state", 1 );
-    fgSetBool("/sim/freeze/master", 0 );
-    fgSetBool("/sim/freeze/clock", 0 );
-    fgSetDouble( "/sim/replay/time", -1 );
-
-    // cout << "start = " << r->get_start_time()
-    //      << "  end = " << r->get_end_time() << endl;
-
-    return true;
-}
-
 /*
 static bool
 do_decrease_visibility (const SGPropertyNode * arg)
@@ -1247,9 +1148,10 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
         }
     }
     
-    if (!fgValidatePath(file.c_str(), false)) {
+    std::string validated_path = fgValidatePath(file, false);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
-                "(unauthorized access)");
+                "(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, add them to --fg-aircraft)");
         return false;
     }
 
@@ -1260,7 +1162,7 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
 
     try {
-        readProperties(file.c_str(), targetnode, true);
+        readProperties(validated_path.c_str(), targetnode, true);
     } catch (const sg_exception &e) {
         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
         return false;
@@ -1269,6 +1171,42 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
     return true;
 }
 
+static bool
+do_load_xml_from_url(const SGPropertyNode * arg)
+{
+    FGHTTPClient* http = static_cast<FGHTTPClient*>(globals->get_subsystem("http"));
+    if (!http) {
+        SG_LOG(SG_IO, SG_ALERT, "xmlhttprequest: HTTP client not running");
+        return false;
+    }
+  
+    std::string url(arg->getStringValue("url"));
+    if (url.empty())
+        return false;
+        
+    SGPropertyNode *targetnode;
+    if (arg->hasValue("targetnode"))
+        targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
+    else
+        targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
+    
+    RemoteXMLRequest* req = new RemoteXMLRequest(url, targetnode);
+    
+    if (arg->hasChild("body"))
+        req->setBodyData(arg->getChild("body"));
+    
+// connect up optional reporting properties
+    if (arg->hasValue("complete")) 
+        req->setCompletionProp(fgGetNode(arg->getStringValue("complete"), true));
+    if (arg->hasValue("failure")) 
+        req->setFailedProp(fgGetNode(arg->getStringValue("failure"), true));
+    if (arg->hasValue("status")) 
+        req->setStatusProp(fgGetNode(arg->getStringValue("status"), true));
+        
+    http->makeRequest(req);
+    return true;
+}
+
 
 /**
  * An fgcommand to allow saving of xml files via nasal,
@@ -1293,9 +1231,10 @@ do_save_xml_from_proptree(const SGPropertyNode * arg)
     if (file.extension() != "xml")
         file.concat(".xml");
 
-    if (!fgValidatePath(file.c_str(), true)) {
+    std::string validated_path = fgValidatePath(file, true);
+    if (validated_path.empty()) {
         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
-                "(unauthorized access)");
+                "(unauthorized directory - authorization no longer follows symlinks)");
         return false;
     }
 
@@ -1308,7 +1247,7 @@ do_save_xml_from_proptree(const SGPropertyNode * arg)
         return false;
 
     try {
-        writeProperties (file.c_str(), sourcenode, true);
+        writeProperties (validated_path.c_str(), sourcenode, true);
     } catch (const sg_exception &e) {
         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
         return false;
@@ -1360,63 +1299,80 @@ do_release_cockpit_button (const SGPropertyNode *arg)
   return true;
 }
 
-static SGGeod commandSearchPos(const SGPropertyNode* arg)
+// Optional profiling commands using gperftools:
+// http://code.google.com/p/gperftools/
+
+#if !FG_HAVE_GPERFTOOLS
+static void
+no_profiling_support()
 {
-  if (arg->hasChild("longitude-deg") && arg->hasChild("latitude-deg")) {
-    return SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
-                           arg->getDoubleValue("latitude-deg"));
-  }
-  
-  // use current viewer/aircraft position
-  return SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"), 
-                         fgGetDouble("/position/latitude-deg"));
+  SG_LOG
+  (
+    SG_GENERAL,
+    SG_WARN,
+    "No profiling support! Install gperftools and reconfigure/rebuild fgfs."
+  );
 }
-  
+#endif
+
 static bool
-do_comm_search(const SGPropertyNode* arg)
+do_profiler_start(const SGPropertyNode *arg)
 {
-  SGGeod pos = commandSearchPos(arg);
-  int khz = static_cast<int>(arg->getDoubleValue("frequency-mhz") * 100.0 + 0.25);
-  
-  flightgear::CommStation* sta = flightgear::CommStation::findByFreq(khz, pos, NULL);
-  if (!sta) {
-    return true;
-  }
-  
-  SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
-  sta->createBinding(result);
+#if FG_HAVE_GPERFTOOLS
+  const char *filename = arg->getStringValue("filename", "fgfs.profile");
+  ProfilerStart(filename);
   return true;
+#else
+  no_profiling_support();
+  return false;
+#endif
 }
 
 static bool
-do_nav_search(const SGPropertyNode* arg)
+do_profiler_stop(const SGPropertyNode *arg)
 {
-  SGGeod pos = commandSearchPos(arg);
-  double mhz = arg->getDoubleValue("frequency-mhz");
+#if FG_HAVE_GPERFTOOLS
+  ProfilerStop();
+  return true;
+#else
+  no_profiling_support();
+  return false;
+#endif
+}
 
-  FGNavList* navList = globals->get_navlist();
-  string type(arg->getStringValue("type", "vor"));
-  if (type == "dme") {
-    navList = globals->get_dmelist();
-  } else if (type == "tacan") {
-    navList = globals->get_tacanlist();
-  }
+
+static bool
+do_set_scenery_paths(const SGPropertyNode* arg)
+{
+  globals->clear_fg_scenery();
+  
+  std::string terrasyncPath(fgGetString("/sim/terrasync/scenery-dir"));
+  bool seenTerrasyncPath = false;
   
-  FGNavRecord* nav = navList->findByFreq(mhz, pos);
-  if (!nav && (type == "vor")) {
-    // if we're searching VORs, look for localizers too
-    nav = globals->get_loclist()->findByFreq(mhz, pos);
+  simgear::PropertyList paths = arg->getChildren("path");
+  for (size_t i = 0; i < paths.size(); ++i) {
+    std::string s = paths[i]->getStringValue();
+    if (s == terrasyncPath) {
+      seenTerrasyncPath = true;
+    }
+    
+    globals->append_fg_scenery(s);
   }
   
-  if (!nav) {
-    return true;
+  if (fgGetBool("/sim/terrasync/enabled") && !seenTerrasyncPath) {
+    globals->append_fg_scenery(terrasyncPath);
   }
   
-  SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
-  nav->createBinding(result);
+  if (paths.empty()) {
+    // no scenery paths set *at all*, use the data in FG_ROOT
+    SGPath root(globals->get_fg_root());
+    root.append("Scenery");
+    globals->append_fg_scenery(root.str());
+  }
+
   return true;
 }
-  
+
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
 ////////////////////////////////////////////////////////////////////////
@@ -1436,15 +1392,16 @@ static struct {
     { "nasal", do_nasal },
     { "exit", do_exit },
     { "reset", do_reset },
-    { "reinit", do_reinit },
-    { "suspend", do_reinit },
-    { "resume", do_reinit },
+    { "reposition", do_reposition },
+    { "switch-aircraft", do_switch_aircraft },
     { "pause", do_pause },
     { "load", do_load },
     { "save", do_save },
+    { "save-tape", do_save_tape },
+    { "load-tape", do_load_tape },
     { "panel-load", do_panel_load },
-    { "panel-mouse-click", do_panel_mouse_click },
     { "preferences-load", do_preferences_load },
+    { "toggle-fullscreen", do_toggle_fullscreen },
     { "view-cycle", do_view_cycle },
     { "screen-capture", do_screen_capture },
     { "hires-screen-capture", do_hires_screen_capture },
@@ -1463,35 +1420,39 @@ static struct {
     { "property-scale", do_property_scale },
     { "property-cycle", do_property_cycle },
     { "property-randomize", do_property_randomize },
+    { "property-interpolate", do_property_interpolate },
     { "data-logging-commit", do_data_logging_commit },
     { "dialog-new", do_dialog_new },
     { "dialog-show", do_dialog_show },
     { "dialog-close", do_dialog_close },
     { "dialog-update", do_dialog_update },
     { "dialog-apply", do_dialog_apply },
+    { "open-browser", do_open_browser },
     { "gui-redraw", do_gui_redraw },
     { "add-model", do_add_model },
-    { "set-cursor", do_set_cursor },
-    { "play-audio-sample", do_play_audio_sample },
     { "presets-commit", do_presets_commit },
     { "log-level", do_log_level },
     { "replay", do_replay },
+    { "open-launcher", do_open_launcher },
     /*
     { "decrease-visibility", do_decrease_visibility },
     { "increase-visibility", do_increase_visibility },
     */
     { "loadxml", do_load_xml_to_proptree},
     { "savexml", do_save_xml_from_proptree },
+    { "xmlhttprequest", do_load_xml_from_url },
     { "press-cockpit-button", do_press_cockpit_button },
     { "release-cockpit-button", do_release_cockpit_button },
     { "dump-scenegraph", do_dump_scene_graph },
     { "dump-terrainbranch", do_dump_terrain_branch },
     { "print-visible-scene", do_print_visible_scene_info },
     { "reload-shaders", do_reload_shaders },
+    { "reload-materials", do_materials_reload },
+    { "set-scenery-paths", do_set_scenery_paths },
   
-    { "find-navaid", do_nav_search },
-    { "find-comm", do_comm_search },
-  
+    { "profiler-start", do_profiler_start },
+    { "profiler-stop",  do_profiler_stop },
+
     { 0, 0 }                   // zero-terminated
 };
 
@@ -1514,6 +1475,9 @@ fgInitCommands ()
   typedef bool (*dummy)();
   fgTie( "/command/view/next", dummy(0), do_view_next );
   fgTie( "/command/view/prev", dummy(0), do_view_prev );
+
+  globals->get_props()->setValueReadOnly( "/sim/debug/profiler-available",
+                                          bool(FG_HAVE_GPERFTOOLS) );
 }
 
 // end of fg_commands.cxx