]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
Reset: explicit close-window function.
[flightgear.git] / src / Main / fg_commands.cxx
index cf36a7777cecedc9bb7f6f5f5e94efc2844e015d..6ae72a99622eb6ee7a6f4f6a7e057a3007673119 100644 (file)
 #include <simgear/structure/event_mgr.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/timing/sg_time.hxx>
-#include <simgear/misc/interpolator.hxx>
-#include <simgear/io/HTTPRequest.hxx>
+#include <simgear/io/HTTPMemoryRequest.hxx>
 
-#include <Cockpit/panel.hxx>
-#include <Cockpit/panel_io.hxx>
 #include <FDM/flight.hxx>
 #include <GUI/gui.h>
 #include <GUI/new_gui.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/viewer.hxx>
+#include <Environment/presets.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
+
 using std::string;
 using std::ifstream;
 using std::ofstream;
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Static helper functions.
 ////////////////////////////////////////////////////////////////////////
@@ -160,7 +158,7 @@ compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
 }
 
 
-\f
+
 ////////////////////////////////////////////////////////////////////////
 // Command implementations.
 ////////////////////////////////////////////////////////////////////////
@@ -210,95 +208,6 @@ do_reset (const SGPropertyNode * arg)
     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.
- */
-static bool
-do_reinit (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;
-}
-
-#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)
-{
-    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;
-}
-
-/**
- * Built-in command: suspend one or more subsystems.
- *
- * subsystem[*] - the name(s) of the subsystem(s) to suspend.
- */
-static bool
-do_resume (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;
-}
-
-#endif
-
 /**
  * Built-in command: replay the FDR buffer
  */
@@ -325,6 +234,16 @@ do_pause (const SGPropertyNode * arg)
         fgSetBool("/sim/freeze/master",!paused);
         fgSetBool("/sim/freeze/clock",!paused);
     }
+  
+    SGPropertyNode_ptr args(new SGPropertyNode);
+    args->setStringValue("id", "sim-pause");
+    if (!paused && fgGetBool("/sim/view-name-popup")) {
+      args->setStringValue("label", "Simulation is paused");
+      globals->get_commands()->execute("show-message", args);
+    } else {
+      globals->get_commands()->execute("clear-message", args);
+    }
+  
     return true;
 }
 
@@ -391,6 +310,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,48 +345,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();
-  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.
  *
@@ -465,17 +375,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;
 }
 
 /**
@@ -553,22 +482,45 @@ 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;
 }
 
+/**
+ * Reload the materials definition
+ */
+ static bool
+ 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);    
+   return true;   
+ }
+
 
 #if 0
 These do_set_(some-environment-parameters) are deprecated and no longer 
@@ -891,7 +843,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();
 
@@ -903,15 +860,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;
 }
@@ -937,58 +901,86 @@ do_property_randomize (const SGPropertyNode * arg)
 /**
  * Built-in command: interpolate a property value over time
  *
- * property: the name of the property value to interpolate.
- * value[0..n] any number of constant values to interpolate
- * time[0..n]  time between each value, number of time elements must
- *          match those of value elements
+ * 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] any number of target values taken from named properties
- * time[0..n]     time between each value, number of time elements must
- *                match those of property elements minus one
+ * 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);
+  SGPropertyNode * prop = get_prop(arg);
+  if( !prop )
+    return false;
 
-    simgear::PropertyList valueNodes = arg->getChildren( "value" );
-    simgear::PropertyList timeNodes = arg->getChildren( "time" );
+  simgear::PropertyList time_nodes = arg->getChildren("time");
+  simgear::PropertyList rate_nodes = arg->getChildren("rate");
 
-    boost::scoped_array<double> value;
-    boost::scoped_array<double> time;
+  if( !time_nodes.empty() && !rate_nodes.empty() )
+    // mustn't specify time and rate
+    return false;
 
-    if( valueNodes.size() > 0 ) {
-        // must match
-        if( timeNodes.size() != valueNodes.size() )
-            return false;
+  simgear::PropertyList::size_type num_times = time_nodes.empty()
+                                             ? rate_nodes.size()
+                                             : time_nodes.size();
 
-        value.reset( new double[valueNodes.size()] );
-        for( simgear::PropertyList::size_type n = 0; n < valueNodes.size(); n++ ) {
-            value[n] = valueNodes[n]->getDoubleValue();
-        }
-    } else {
-        valueNodes = arg->getChildren("property");
-        // must have one more property node
-        if( valueNodes.size() - 1 != timeNodes.size() )
-          return false;
+  simgear::PropertyList value_nodes = arg->getChildren("value");
+  if( value_nodes.empty() )
+  {
+    simgear::PropertyList prop_nodes = arg->getChildren("property");
 
-        value.reset( new double[valueNodes.size()-1] );
-        for( simgear::PropertyList::size_type n = 0; n < valueNodes.size()-1; n++ ) {
-            value[n] = fgGetNode(valueNodes[n+1]->getStringValue(), "/null")->getDoubleValue();
-        }
+    // 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()) );
+  }
 
-    time.reset( new double[timeNodes.size()] );
-    for( simgear::PropertyList::size_type n = 0; n < timeNodes.size(); n++ ) {
-        time[n] = timeNodes[n]->getDoubleValue();
-    }
+  // must match
+  if( value_nodes.size() != num_times )
+    return false;
 
-    ((SGInterpolator*)globals->get_subsystem_mgr()
-      ->get_group(SGSubsystemMgr::INIT)->get_subsystem("interpolator"))
-      ->interpolate(prop, timeNodes.size(), value.get(), time.get() );
+  double_list deltas;
+  deltas.reserve(num_times);
 
-    return true;
+  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")
+  );
 }
 
 /**
@@ -1014,7 +1006,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
@@ -1149,32 +1144,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
@@ -1184,6 +1153,12 @@ do_set_cursor (const SGPropertyNode * arg)
 static bool
 do_play_audio_sample (const SGPropertyNode * arg)
 {
+    SGSoundMgr *smgr = globals->get_soundmgr();
+    if (!smgr) {
+        SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
+        return false;
+    }
+  
     string path = arg->getStringValue("path");
     string file = arg->getStringValue("file");
     float volume = arg->getFloatValue("volume");
@@ -1191,7 +1166,6 @@ do_play_audio_sample (const SGPropertyNode * arg)
     try {
         static FGSampleQueue *queue = 0;
         if ( !queue ) {
-           SGSoundMgr *smgr = globals->get_soundmgr();
            queue = new FGSampleQueue(smgr, "chatter");
            queue->tie_to_listener();
         }
@@ -1221,7 +1195,7 @@ do_presets_commit (const SGPropertyNode * arg)
       // 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;
@@ -1318,18 +1292,18 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
     return true;
 }
 
-class RemoteXMLRequest : public simgear::HTTP::Request
+class RemoteXMLRequest:
+  public simgear::HTTP::MemoryRequest
 {
 public:
     SGPropertyNode_ptr _complete;
     SGPropertyNode_ptr _status;
     SGPropertyNode_ptr _failed;
     SGPropertyNode_ptr _target;
-    string propsData;
-    
-    RemoteXMLRequest(const std::string& url, SGPropertyNode* targetNode) : 
-        simgear::HTTP::Request(url),
-        _target(targetNode)
+
+    RemoteXMLRequest(const std::string& url, SGPropertyNode* targetNode) :
+      simgear::HTTP::MemoryRequest(url),
+      _target(targetNode)
     {
     }
     
@@ -1347,20 +1321,25 @@ public:
     {
         _failed = p;
     }
+    
 protected:
-    virtual void gotBodyData(const char* s, int n)
+    
+    virtual void onFail()
     {
-        propsData += string(s, n);
+        SG_LOG(SG_IO, SG_INFO, "network level failure in RemoteXMLRequest");
+        if (_failed) {
+            _failed->setBoolValue(true);
+        }
     }
     
-    virtual void responseComplete()
+    virtual void onDone()
     {
         int response = responseCode();
         bool failed = false;
         if (response == 200) {
             try {
-                const char* buffer = propsData.c_str();
-                readProperties(buffer, propsData.size(), _target, true);
+                const char* buffer = responseBody().c_str();
+                readProperties(buffer, responseBody().size(), _target, true);
             } catch (const sg_exception &e) {
                 SG_LOG(SG_IO, SG_WARN, "parsing XML from remote, failed: " << e.getFormattedMessage());
                 failed = true;
@@ -1372,7 +1351,7 @@ protected:
     // now the response data is output, signal Nasal / listeners
         if (_complete) _complete->setBoolValue(true);
         if (_status) _status->setIntValue(response);
-        if (_failed) _failed->setBoolValue(failed);
+        if (_failed && failed) _failed->setBoolValue(true);
     }
 };
 
@@ -1380,6 +1359,12 @@ protected:
 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;
@@ -1392,6 +1377,9 @@ do_load_xml_from_url(const SGPropertyNode * arg)
     
     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));
@@ -1400,8 +1388,7 @@ do_load_xml_from_url(const SGPropertyNode * arg)
     if (arg->hasValue("status")) 
         req->setStatusProp(fgGetNode(arg->getStringValue("status"), true));
         
-    FGHTTPClient::instance()->makeRequest(req);
-    
+    http->makeRequest(req);
     return true;
 }
 
@@ -1496,63 +1483,48 @@ 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");
-
-  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();
-  }
-  
-  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);
-  }
-  
-  if (!nav) {
-    return true;
-  }
-  
-  SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
-  nav->createBinding(result);
+#if FG_HAVE_GPERFTOOLS
+  ProfilerStop();
   return true;
+#else
+  no_profiling_support();
+  return false;
+#endif
 }
-  
+
+
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
 ////////////////////////////////////////////////////////////////////////
@@ -1572,15 +1544,14 @@ static struct {
     { "nasal", do_nasal },
     { "exit", do_exit },
     { "reset", do_reset },
-    { "reinit", do_reinit },
-    { "suspend", do_reinit },
-    { "resume", do_reinit },
     { "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 },
@@ -1609,7 +1580,6 @@ static struct {
     { "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 },
@@ -1627,10 +1597,11 @@ static struct {
     { "dump-terrainbranch", do_dump_terrain_branch },
     { "print-visible-scene", do_print_visible_scene_info },
     { "reload-shaders", do_reload_shaders },
-  
-    { "find-navaid", do_nav_search },
-    { "find-comm", do_comm_search },
-  
+    { "reload-materials", do_materials_reload },
+
+    { "profiler-start", do_profiler_start },
+    { "profiler-stop",  do_profiler_stop },
+
     { 0, 0 }                   // zero-terminated
 };
 
@@ -1653,6 +1624,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