]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
Improve timing statistics
[flightgear.git] / src / Main / fg_commands.cxx
index 1dd37d387e8912f2e11cc24a4f6643994c1c74e3..8f7a1c18cab9ebb2ca620b7188244e0c520152fe 100644 (file)
 
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
-#include <Cockpit/hud.hxx>
-#include <Environment/environment.hxx>
 #include <FDM/flight.hxx>
 #include <GUI/gui.h>
 #include <GUI/new_gui.hxx>
 #include <GUI/dialog.hxx>
 #include <Aircraft/replay.hxx>
-#include <Scenery/tilemgr.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.hxx>
 #include <Time/sunsolver.hxx>
-#include <Time/tmp.hxx>
 
 #include "fg_init.hxx"
 #include "fg_io.hxx"
@@ -50,6 +46,7 @@
 #include "viewmgr.hxx"
 #include "main.hxx"
 #include <Main/viewer.hxx>
+#include <Environment/presets.hxx>
 
 using std::string;
 using std::ifstream;
@@ -212,7 +209,8 @@ do_exit (const SGPropertyNode * arg)
             SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
         }
     }
-    fgExit(arg->getIntValue("status", 0));
+    
+    fgOSExit(arg->getIntValue("status", 0));
     return true;
 }
 
@@ -223,7 +221,7 @@ do_exit (const SGPropertyNode * arg)
 static bool
 do_reset (const SGPropertyNode * arg)
 {
-    doSimulatorReset();
+    fgReInitSubsystems();
     return true;
 }
 
@@ -249,7 +247,7 @@ do_reinit (const SGPropertyNode * arg)
             if (subsystem == 0) {
                 result = false;
                 SG_LOG( SG_GENERAL, SG_ALERT,
-                        "Subsystem " << name << "not found" );
+                        "Subsystem " << name << " not found" );
             } else {
                 subsystem->reinit();
             }
@@ -282,7 +280,7 @@ do_suspend (const SGPropertyNode * arg)
         SGSubsystem * subsystem = globals->get_subsystem(name);
         if (subsystem == 0) {
             result = false;
-            SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
+            SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
         } else {
             subsystem->suspend();
         }
@@ -306,7 +304,7 @@ do_resume (const SGPropertyNode * arg)
         SGSubsystem * subsystem = globals->get_subsystem(name);
         if (subsystem == 0) {
             result = false;
-            SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
+            SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
         } else {
             subsystem->resume();
         }
@@ -392,9 +390,11 @@ static bool
 do_panel_load (const SGPropertyNode * arg)
 {
   string panel_path =
-    arg->getStringValue("path",
-                       fgGetString("/sim/panel/path",
-                                   "Panels/Default/default.xml"));
+    arg->getStringValue("path", fgGetString("/sim/panel/path"));
+  if (panel_path.empty()) {
+    return false;
+  }
+  
   FGPanel * new_panel = fgReadPanel(panel_path);
   if (new_panel == 0) {
     SG_LOG(SG_INPUT, SG_ALERT,
@@ -452,24 +452,11 @@ do_preferences_load (const SGPropertyNode * arg)
   return true;
 }
 
-
-static void
-fix_hud_visibility()
-{
-  if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
-      globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
-      if ( globals->get_viewmgr()->get_current() == 1 ) {
-          globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
-      }
-  }
-}
-
 static void
 do_view_next( bool )
 {
     globals->get_current_view()->setHeadingOffset_deg(0.0);
     globals->get_viewmgr()->next_view();
-    fix_hud_visibility();
 }
 
 static void
@@ -477,7 +464,6 @@ do_view_prev( bool )
 {
     globals->get_current_view()->setHeadingOffset_deg(0.0);
     globals->get_viewmgr()->prev_view();
-    fix_hud_visibility();
 }
 
 /**
@@ -488,7 +474,6 @@ do_view_cycle (const SGPropertyNode * arg)
 {
   globals->get_current_view()->setHeadingOffset_deg(0.0);
   globals->get_viewmgr()->next_view();
-  fix_hud_visibility();
   return true;
 }
 
@@ -532,6 +517,13 @@ do_dump_terrain_branch (const SGPropertyNode*)
     return true;
 }
 
+static bool
+do_print_visible_scene_info(const SGPropertyNode*)
+{
+    fgPrintVisibleSceneInfoCommand();
+    return true;
+}
+
 /**
  * Built-in command: hires capture screen.
  */
@@ -556,15 +548,9 @@ do_tile_cache_reload (const SGPropertyNode * arg)
     if ( !freeze ) {
        fgSetBool("/sim/freeze/master", true);
     }
-    if ( globals->get_tile_mgr()->init() ) {
-       // Load the local scenery data
-        double visibility_meters = fgGetDouble("/environment/visibility-m");
-       globals->get_tile_mgr()->update( visibility_meters );
-    } else {
-       SG_LOG( SG_GENERAL, SG_ALERT, 
-               "Error in Tile Manager initialization!" );
-       exit(-1);
-    }
+
+    globals->get_subsystem("tile-manager")->reinit();
+
     if ( !freeze ) {
        fgSetBool("/sim/freeze/master", false);
     }
@@ -572,6 +558,9 @@ do_tile_cache_reload (const SGPropertyNode * arg)
 }
 
 
+#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.
@@ -698,7 +687,7 @@ do_set_dewpoint_degc (const SGPropertyNode * arg)
     dummy.set_dewpoint_degc( dewpoint_degc );
     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
 }
-
+#endif
 /**
  * Update the lighting manually.
  */
@@ -711,8 +700,6 @@ do_timeofday (const SGPropertyNode * arg)
         = fgGetNode("/position/longitude-deg");
     static const SGPropertyNode *latitude
         = fgGetNode("/position/latitude-deg");
-    static const SGPropertyNode *cur_time_override
-        = fgGetNode("/sim/time/cur-time-override", true);
 
     int orig_warp = globals->get_warp();
     SGTime *t = globals->get_time_params();
@@ -773,14 +760,10 @@ do_timeofday (const SGPropertyNode * arg)
                                              * SGD_DEGREES_TO_RADIANS,
                                            180.0, false ); 
     }
-    // cout << "warp = " << warp << endl;
-    globals->set_warp( orig_warp + warp );
-
-    t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
-               latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
-               cur_time_override->getLongValue(),
-               globals->get_warp() );
+    
 
+    fgSetInt("/sim/time/warp", orig_warp + warp);
+    
     return true;
 }
 
@@ -1212,7 +1195,7 @@ do_play_audio_sample (const SGPropertyNode * arg)
            queue->tie_to_listener();
         }
 
-        SGSoundSample *msg = new SGSoundSample(path.c_str(), file.c_str());
+        SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
         msg->set_volume( volume );
         queue->add( msg );
 
@@ -1231,25 +1214,15 @@ do_play_audio_sample (const SGPropertyNode * arg)
 static bool
 do_presets_commit (const SGPropertyNode * arg)
 {
-    // unbind the current fdm state so property changes
-    // don't get lost when we subsequently delete this fdm
-    // and create a new one.
-    globals->get_subsystem("flight")->unbind();
-
-    // set position from presets
-    fgInitPosition();
-
-    fgReInitSubsystems();
-
-    globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") );
-
-#if 0
-    if ( ! fgGetBool("/sim/presets/onground") ) {
-        fgSetBool( "/sim/freeze/master", true );
-        fgSetBool( "/sim/freeze/clock", true );
+    if (fgGetBool("/sim/initialized", false)) {
+      fgReInitSubsystems();
+    } 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();
     }
-#endif
-
+    
     return true;
 }
 
@@ -1270,8 +1243,10 @@ do_log_level (const SGPropertyNode * arg)
 static bool
 do_replay (const SGPropertyNode * arg)
 {
-    // freeze the master fdm
+    // freeze the fdm, resume from sim pause 
     fgSetInt( "/sim/freeze/replay-state", 1 );
+    fgSetBool("/sim/freeze/master", 0 );
+    fgSetBool("/sim/freeze/clock", 0 );
 
     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
 
@@ -1290,44 +1265,21 @@ do_replay (const SGPropertyNode * arg)
     return true;
 }
 
-
+/*
 static bool
 do_decrease_visibility (const SGPropertyNode * arg)
 {
-    double new_value = fgGetDouble("/environment/visibility-m") * 0.9;
-    fgSetDouble("/environment/visibility-m", new_value);
-    fgDefaultWeatherValue("visibility-m", new_value);
-    globals->get_subsystem("environment")->reinit();
-
+    Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
     return true;
 }
  
 static bool
 do_increase_visibility (const SGPropertyNode * arg)
 {
-    double new_value = fgGetDouble("/environment/visibility-m") * 1.1;
-    fgSetDouble("/environment/visibility-m", new_value);
-    fgDefaultWeatherValue("visibility-m", new_value);
-    globals->get_subsystem("environment")->reinit();
-
+    Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
     return true;
 }
-
-static bool
-do_hud_init(const SGPropertyNode *)
-{
-    fgHUDInit(); // minimal HUD
-    return true;
-}
-
-static bool
-do_hud_init2(const SGPropertyNode *)
-{
-    fgHUDInit2();  // normal HUD
-    return true;
-}
-
-
+*/
 /**
  * An fgcommand to allow loading of xml files via nasal,
  * the xml file's structure will be made available within
@@ -1350,6 +1302,10 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
     if (file.extension() != "xml")
         file.concat(".xml");
 
+    if (file.isRelative()) {
+      file = globals->resolve_maybe_aircraft_path(file.str());
+    }
+
     if (!fgValidatePath(file.c_str(), false)) {
         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
                 "(unauthorized access)");
@@ -1495,10 +1451,12 @@ static struct {
     { "screen-capture", do_screen_capture },
     { "hires-screen-capture", do_hires_screen_capture },
     { "tile-cache-reload", do_tile_cache_reload },
+    /*
     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
     { "set-outside-air-temp-degc", do_set_oat_degc },
     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
+    */
     { "timeofday", do_timeofday },
     { "property-toggle", do_property_toggle },
     { "property-assign", do_property_assign },
@@ -1521,16 +1479,17 @@ static struct {
     { "presets-commit", do_presets_commit },
     { "log-level", do_log_level },
     { "replay", do_replay },
+    /*
     { "decrease-visibility", do_decrease_visibility },
     { "increase-visibility", do_increase_visibility },
-    { "hud-init", do_hud_init },
-    { "hud-init2", do_hud_init2 },
+    */
     { "loadxml", do_load_xml_to_proptree},
     { "savexml", do_save_xml_from_proptree },
     { "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 },
     { 0, 0 }                   // zero-terminated
 };