]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
Fix line endings
[flightgear.git] / src / Main / fg_commands.cxx
index 21a5b7d2a8f04e20fa4d7a1cc80ee053629ac959..2a1863411e1f439c9d749e3cc585ace428901ee7 100644 (file)
@@ -1,5 +1,9 @@
 // fg_commands.cxx - internal FGFS commands.
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <string.h>            // strcmp()
 
 #include <simgear/compiler.h>
@@ -28,6 +32,7 @@
 #  include <Scripting/scriptmgr.hxx>
 #endif
 #include <Scripting/NasalSys.hxx>
+#include <Sound/fg_fx.hxx>
 #include <Time/sunsolver.hxx>
 #include <Time/tmp.hxx>
 
@@ -39,6 +44,7 @@
 #include "logger.hxx"
 #include "util.hxx"
 #include "viewmgr.hxx"
+#include "main.hxx"
 
 SG_USING_STD(string);
 SG_USING_STD(ifstream);
@@ -189,9 +195,34 @@ do_nasal (const SGPropertyNode * arg)
 static bool
 do_exit (const SGPropertyNode * arg)
 {
-  SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
-  fgExit(arg->getIntValue("status", 0));
-  return true;
+    SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
+    fgSetBool("/sim/signals/exit", true);
+
+    if (fgGetBool("/sim/startup/save-on-exit")) {
+#ifdef _MSC_VER
+        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 autosave.xml");
+            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_BULK, "Finished Saving user settings");
+        }
+    }
+    fgExit(arg->getIntValue("status", 0));
+    return true;
 }
 
 
@@ -557,9 +588,9 @@ do_set_oat_degc (const SGPropertyNode * arg)
     dummy.set_temperature_degc( atof( temp_str.c_str() ) );
     double temp_sea_level_degc = dummy.get_temperature_sea_level_degc();
 
-    cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
-    cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl;
-    cout << "Temp sea level (C) = " << temp_sea_level_degc << endl;
+    //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
+    //cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl;
+    //cout << "Temp sea level (C) = " << temp_sea_level_degc << endl;
  
     SGPropertyNode *node, *child;
 
@@ -647,9 +678,9 @@ do_set_dewpoint_degc (const SGPropertyNode * arg)
     dummy.set_dewpoint_degc( atof( dewpoint_str.c_str() ) );
     double dewpoint_sea_level_degc = dummy.get_dewpoint_sea_level_degc();
 
-    cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
-    cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl;
-    cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl;
+    //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
+    //cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl;
+    //cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl;
  
     SGPropertyNode *node, *child;
 
@@ -1118,6 +1149,24 @@ do_gui_redraw (const SGPropertyNode * arg)
     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_message (const SGPropertyNode * arg)
+{
+    FGFX *fx = (FGFX *)globals->get_subsystem("fx");
+    string path = arg->getStringValue("path");
+    string file = arg->getStringValue("file");
+    // cout << "playing " << path << " / " << file << endl;
+    fx->play_message( path, file );
+
+    return true;
+}
+
 /**
  * Built-in command: commit presets (read from in /sim/presets/)
  */
@@ -1178,8 +1227,8 @@ do_replay (const SGPropertyNode * arg)
         fgSetDouble( "/sim/replay/time", r->get_start_time() );
     }
 
-    cout << "start = " << r->get_start_time()
-         << "  end = " << r->get_end_time() << endl;
+    // cout << "start = " << r->get_start_time()
+    //      << "  end = " << r->get_end_time() << endl;
 
     return true;
 }
@@ -1358,6 +1407,7 @@ static struct {
     { "dialog-update", do_dialog_update },
     { "dialog-apply", do_dialog_apply },
     { "gui-redraw", do_gui_redraw },
+    { "play-audio-message", do_play_audio_message },
     { "presets-commit", do_presets_commit },
     { "log-level", do_log_level },
     { "replay", do_replay },