]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_props.cxx
Move the texture loader to SimGear
[flightgear.git] / src / Main / fg_props.cxx
index 0ba8109acbae88b71ffcf484839c2fff173183cf..8b2f202ae5ab2d0fc9aae4b832afdf178495c64e 100644 (file)
@@ -27,6 +27,7 @@
 #include <simgear/misc/exception.hxx>
 #include <simgear/magvar/magvar.hxx>
 #include <simgear/timing/sg_time.hxx>
+#include <simgear/misc/sg_path.hxx>
 
 #include STL_IOSTREAM
 
 #include <Aircraft/aircraft.hxx>
 #include <Time/tmp.hxx>
 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
-#ifndef FG_NEW_ENVIRONMENT
+#ifdef FG_WEATHERCM
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #else
 #  include <Environment/environment.hxx>
-#endif // FG_NEW_ENVIRONMENT
+#endif // FG_WEATHERCM
 #include <Objects/matlib.hxx>
 
 #include <GUI/gui.h>
+#include <Sound/soundmgr.hxx>
 
 #include "globals.hxx"
 #include "fgfs.hxx"
 #include "fg_props.hxx"
 
-#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
 SG_USING_STD(istream);
 SG_USING_STD(ostream);
-#endif
 
-#if !defined(FG_NEW_ENVIRONMENT)
+#ifdef FG_WEATHERCM
 static double getWindNorth ();
 static double getWindEast ();
 static double getWindDown ();
-#endif // FG_NEW_ENVIRONMENT
+#endif // FG_WEATHERCM
 
 static bool winding_ccw = true; // FIXME: temporary
 
 static bool fdm_data_logging = false; // FIXME: temporary
 
+static bool frozen = false;    // FIXME: temporary
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -102,10 +104,10 @@ static const char *
 getLoggingClasses ()
 {
   sgDebugClass classes = logbuf::get_log_classes();
-  string result = "";
+  static string result = "";   // FIXME
   for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
     if ((classes&log_class_mappings[i].c) > 0) {
-      if (result != (string)"")
+      if (!result.empty())
        result += '|';
       result += log_class_mappings[i].name;
     }
@@ -142,7 +144,7 @@ setLoggingClasses (const char * c)
     return;
   }
 
-  if (classes == "" || classes == "all") { // default
+  if (classes.empty() || classes == "all") { // default
     logbuf::set_log_classes(SG_ALL);
     SG_LOG(SG_GENERAL, SG_INFO, "Enabled all logging classes: "
           << getLoggingClasses());
@@ -200,7 +202,7 @@ setLoggingPriority (const char * p)
     logbuf::set_log_priority(SG_BULK);
   } else if (priority == "debug") {
     logbuf::set_log_priority(SG_DEBUG);
-  } else if (priority == "" || priority == "info") { // default
+  } else if (priority.empty() || priority == "info") { // default
     logbuf::set_log_priority(SG_INFO);
   } else if (priority == "warn") {
     logbuf::set_log_priority(SG_WARN);
@@ -213,6 +215,36 @@ setLoggingPriority (const char * p)
 }
 
 
+/**
+ * Return the current frozen state.
+ */
+static bool
+getFreeze ()
+{
+  return frozen;
+}
+
+
+/**
+ * Set the current frozen state.
+ */
+static void
+setFreeze (bool f)
+{
+    frozen = f;
+
+    // Stop sound on a pause
+    FGSoundMgr *s = globals->get_soundmgr();
+    if ( s != NULL ) {
+        if ( f ) {
+            s->pause();
+        } else {
+            s->resume();
+        }
+    }
+}
+
+
 /**
  * Return the current aircraft directory (UIUC) as a string.
  */
@@ -236,10 +268,10 @@ setAircraftDir (const char * dir)
 /**
  * Return the number of milliseconds elapsed since simulation started.
  */
-static long
-getElapsedTime_ms ()
+static double
+getElapsedTime_sec ()
 {
-  return globals->get_elapsed_time_ms();
+  return globals->get_sim_time_sec();
 }
 
 
@@ -249,14 +281,12 @@ getElapsedTime_ms ()
 static const char *
 getDateString ()
 {
-  string out;
-  char buf[64];
+  static char buf[64];         // FIXME
   struct tm * t = globals->get_time_params()->getGmt();
   sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d",
          t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
          t->tm_hour, t->tm_min, t->tm_sec);
-  out = buf;
-  return out.c_str();
+  return buf;
 }
 
 
@@ -313,14 +343,12 @@ setDateString (const char * date_string)
 static const char *
 getGMTString ()
 {
-  string out;
-  char buf[16];
+  static char buf[16];         // FIXME
   struct tm *t = globals->get_time_params()->getGmt();
   sprintf(buf, " %.2d:%.2d:%.2d",
          t->tm_hour, t->tm_min, t->tm_sec);
   // cout << t << " " << buf << endl;
-  out = buf;
-  return out.c_str();
+  return buf;
 }
 
 
@@ -377,7 +405,7 @@ getHeadingMag ()
 }
 
 
-#if !defined(FG_NEW_ENVIRONMENT)
+#ifdef FG_WEATHERCM
 
 /**
  * Get the current visibility (meters).
@@ -435,7 +463,7 @@ getWindEast ()
 static void
 setWindEast (double speed)
 {
-  cout << "Set wind-east to " << speed << endl;
+  SG_LOG(SG_GENERAL, SG_INFO,, "Set wind-east to " << speed );
   current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
                                                           speed,
                                                           getWindDown());
@@ -463,7 +491,7 @@ setWindDown (double speed)
                                                           speed);
 }
 
-#endif // FG_NEW_ENVIRONMENT
+#endif // FG_WEATHERCM
 
 static long
 getWarp ()
@@ -550,13 +578,14 @@ setFDMDataLogging (bool state)
 void
 fgInitProps ()
 {
+  SG_LOG(SG_GENERAL, SG_DEBUG, "start of fgInitProps()" );
                                // Simulation
   fgTie("/sim/logging/priority", getLoggingPriority, setLoggingPriority);
   fgTie("/sim/logging/classes", getLoggingClasses, setLoggingClasses);
-  // fgTie("/sim/freeze", getFreeze, setFreeze);
+  fgTie("/sim/freeze/master", getFreeze, setFreeze);
   fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
 
-  fgTie("/sim/time/elapsed-ms", getElapsedTime_ms);
+  fgTie("/sim/time/elapsed-sec", getElapsedTime_sec);
   fgTie("/sim/time/gmt", getDateString, setDateString);
   fgSetArchivable("/sim/time/gmt");
   fgTie("/sim/time/gmt-string", getGMTString);
@@ -566,7 +595,7 @@ fgInitProps ()
   fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
 
                                // Environment
-#if !defined(FG_NEW_ENVIRONMENT)
+#ifdef FG_WEATHERCM
   fgTie("/environment/visibility-m", getVisibility, setVisibility);
   fgSetArchivable("/environment/visibility-m");
   fgTie("/environment/wind-from-north-fps", getWindNorth, setWindNorth);
@@ -587,7 +616,8 @@ fgInitProps ()
   fgTie("/sim/temp/winding-ccw", getWindingCCW, setWindingCCW, false);
   fgTie("/sim/temp/full-screen", getFullScreen, setFullScreen);
   fgTie("/sim/temp/fdm-data-logging", getFDMDataLogging, setFDMDataLogging);
-       
+
+  SG_LOG(SG_GENERAL, SG_DEBUG, "end of fgInitProps()" );
 }
 
 
@@ -610,12 +640,12 @@ bool
 fgSaveFlight (ostream &output, bool write_all)
 {
 
-  fgSetBool("/sim/startup/onground", false);
-  fgSetArchivable("/sim/startup/onground");
-  fgSetBool("/sim/startup/trim", false);
-  fgSetArchivable("/sim/startup/trim");
-  fgSetString("/sim/startup/speed-set", "UVW");
-  fgSetArchivable("/sim/startup/speed-set");
+  fgSetBool("/sim/presets/onground", false);
+  fgSetArchivable("/sim/presets/onground");
+  fgSetBool("/sim/presets/trim", false);
+  fgSetArchivable("/sim/presets/trim");
+  fgSetString("/sim/presets/speed-set", "UVW");
+  fgSetArchivable("/sim/presets/speed-set");
 
   try {
     writeProperties(output, globals->get_props(), write_all);
@@ -641,9 +671,9 @@ fgLoadFlight (istream &input)
     return false;
   }
 
-  fgSetBool("/sim/startup/onground", false);
-  fgSetBool("/sim/startup/trim", false);
-  fgSetString("/sim/startup/speed-set", "UVW");
+  fgSetBool("/sim/presets/onground", false);
+  fgSetBool("/sim/presets/trim", false);
+  fgSetString("/sim/presets/speed-set", "UVW");
 
   copyProperties(&props, globals->get_props());
   // When loading a flight, make it the
@@ -653,6 +683,28 @@ fgLoadFlight (istream &input)
 }
 
 
+bool
+fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root)
+{
+    string fullpath;
+    if (in_fg_root) {
+        SGPath loadpath(globals->get_fg_root());
+        loadpath.append(path);
+        fullpath = loadpath.str();
+    } else {
+        fullpath = path;
+    }
+
+    try {
+        readProperties(fullpath, props);
+    } catch (const sg_exception &e) {
+        guiErrorMessage("Error reading properties: ", e);
+        return false;
+    }
+    return true;
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Property convenience functions.
@@ -676,6 +728,19 @@ fgHasNode (const char * path)
   return (fgGetNode(path, false) != 0);
 }
 
+void
+fgAddChangeListener (SGPropertyChangeListener * listener, const char * path)
+{
+  fgGetNode(path, true)->addChangeListener(listener);
+}
+
+void
+fgAddChangeListener (SGPropertyChangeListener * listener,
+                    const char * path, int index)
+{
+  fgGetNode(path, index, true)->addChangeListener(listener);
+}
+
 bool
 fgGetBool (const char * name, bool defaultValue)
 {