]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
Merge branch 'timoore/fire-fix'
[flightgear.git] / src / Main / fg_commands.cxx
index 7ca69fca4b34d8b424f6ba1f2a0e05ea05dd82db..6131e4795fc2f6796d56702ecd9677075f9ed93b 100644 (file)
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/scene/material/mat.hxx>
+#include <simgear/scene/material/matlib.hxx>
 #include <simgear/structure/exception.hxx>
 #include <simgear/structure/commands.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/structure/event_mgr.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
 
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scripting/NasalSys.hxx>
-#include <Sound/fg_fx.hxx>
+#include <Sound/sample_queue.hxx>
 #include <Time/sunsolver.hxx>
 #include <Time/tmp.hxx>
 
 #include "fg_init.hxx"
 #include "fg_io.hxx"
+#include "fg_os.hxx"
 #include "fg_commands.hxx"
 #include "fg_props.hxx"
 #include "globals.hxx"
@@ -45,6 +48,7 @@
 #include "util.hxx"
 #include "viewmgr.hxx"
 #include "main.hxx"
+#include <Main/viewer.hxx>
 
 using std::string;
 using std::ifstream;
@@ -133,15 +137,15 @@ static bool
 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
 {
     switch (value1->getType()) {
-    case SGPropertyNode::BOOL:
+    case simgear::props::BOOL:
         return (value1->getBoolValue() == value2->getBoolValue());
-    case SGPropertyNode::INT:
+    case simgear::props::INT:
         return (value1->getIntValue() == value2->getIntValue());
-    case SGPropertyNode::LONG:
+    case simgear::props::LONG:
         return (value1->getLongValue() == value2->getLongValue());
-    case SGPropertyNode::FLOAT:
+    case simgear::props::FLOAT:
         return (value1->getFloatValue() == value2->getFloatValue());
-    case SGPropertyNode::DOUBLE:
+    case simgear::props::DOUBLE:
         return (value1->getDoubleValue() == value2->getDoubleValue());
     default:
         return !strcmp(value1->getStringValue(), value2->getStringValue());
@@ -185,7 +189,7 @@ do_exit (const SGPropertyNode * arg)
     fgSetBool("/sim/signals/exit", true);
 
     if (fgGetBool("/sim/startup/save-on-exit")) {
-#ifdef _MSC_VER
+#ifdef _WIN32
         char* envp = ::getenv( "APPDATA" );
         if ( envp != NULL ) {
             SGPath config( envp );
@@ -496,6 +500,13 @@ do_screen_capture (const SGPropertyNode * arg)
   return fgDumpSnapShot();
 }
 
+static bool
+do_reload_shaders (const SGPropertyNode*)
+{
+    simgear::reload_shaders();
+    return true;
+}
+
 static bool
 do_dump_scene_graph (const SGPropertyNode*)
 {
@@ -565,10 +576,8 @@ do_tile_cache_reload (const SGPropertyNode * arg)
  * boundary and aloft environment layers.
  */
 static bool
-do_set_sea_level_degc (const SGPropertyNode * arg)
+do_set_sea_level_degc ( double temp_sea_level_degc)
 {
-    double temp_sea_level_degc = arg->getDoubleValue("temp-degc", 15.0);
-
     SGPropertyNode *node, *child;
 
     // boundary layers
@@ -596,6 +605,12 @@ do_set_sea_level_degc (const SGPropertyNode * arg)
     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
@@ -605,8 +620,7 @@ do_set_sea_level_degc (const SGPropertyNode * arg)
 static bool
 do_set_oat_degc (const SGPropertyNode * arg)
 {
-    const string &temp_str = arg->getStringValue("temp-degc", "15.0");
-
+    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");
@@ -616,38 +630,8 @@ do_set_oat_degc (const SGPropertyNode * arg)
 
     FGEnvironment dummy;       // instantiate a dummy so we can leech a method
     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
-    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;
-    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;
+    dummy.set_temperature_degc( oat_degc );
+    return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
 }
 
 /**
@@ -655,9 +639,8 @@ do_set_oat_degc (const SGPropertyNode * arg)
  * boundary and aloft environment layers.
  */
 static bool
-do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
+do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
 {
-    double dewpoint_sea_level_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
 
     SGPropertyNode *node, *child;
 
@@ -686,6 +669,11 @@ do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
     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
@@ -695,7 +683,7 @@ do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
 static bool
 do_set_dewpoint_degc (const SGPropertyNode * arg)
 {
-    const string &dewpoint_str = arg->getStringValue("dewpoint-degc", "5.0");
+    double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
 
     // check for an altitude specified in the arguments, otherwise use
     // current aircraft altitude.
@@ -706,38 +694,8 @@ do_set_dewpoint_degc (const SGPropertyNode * arg)
 
     FGEnvironment dummy;       // instantiate a dummy so we can leech a method
     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
-    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;
-    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;
-      }
-    }
-
-    return true;
+    dummy.set_dewpoint_degc( dewpoint_degc );
+    return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
 }
 
 /**
@@ -1224,7 +1182,7 @@ do_set_cursor (const SGPropertyNode * arg)
     }
 
     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
-    if (cursor->getType() != SGPropertyNode::NONE)
+    if (cursor->getType() != simgear::props::NONE)
         fgSetMouseCursor(cursor->getIntValue());
 
     cursor->setIntValue(fgGetMouseCursor());
@@ -1241,13 +1199,22 @@ do_set_cursor (const SGPropertyNode * arg)
 static bool
 do_play_audio_sample (const SGPropertyNode * arg)
 {
-    FGFX *fx = (FGFX *)globals->get_subsystem("fx");
     string path = arg->getStringValue("path");
     string file = arg->getStringValue("file");
-    double volume = arg->getDoubleValue("volume");
+    float volume = arg->getFloatValue("volume");
     // cout << "playing " << path << " / " << file << endl;
     try {
-        fx->play_message( path, file, volume );
+        static FGSampleQueue *queue = 0;
+        if ( !queue ) {
+           SGSoundMgr *smgr = globals->get_soundmgr();
+           queue = new FGSampleQueue(smgr, "chatter");
+           queue->tie_to_listener();
+        }
+
+        SGSoundSample *msg = new SGSoundSample(path.c_str(), file.c_str());
+        msg->set_volume( volume );
+        queue->add( msg );
+
         return true;
 
     } catch (const sg_io_exception&) {
@@ -1563,6 +1530,7 @@ static struct {
     { "release-cockpit-button", do_release_cockpit_button },
     { "dump-scenegraph", do_dump_scene_graph },
     { "dump-terrainbranch", do_dump_terrain_branch },
+    { "reload-shaders", do_reload_shaders },
     { 0, 0 }                   // zero-terminated
 };
 
@@ -1575,9 +1543,9 @@ static struct {
 void
 fgInitCommands ()
 {
-  SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
+  SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
   for (int i = 0; built_ins[i].name != 0; i++) {
-    SG_LOG(SG_GENERAL, SG_INFO, "  " << built_ins[i].name);
+    SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
     globals->get_commands()->addCommand(built_ins[i].name,
                                        built_ins[i].command);
   }