]> 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 357ab530a8ffd2927c550c3f92bc56a982de76d5..8b2f202ae5ab2d0fc9aae4b832afdf178495c64e 100644 (file)
@@ -25,6 +25,9 @@
 #endif
 
 #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
 ////////////////////////////////////////////////////////////////////////
@@ -96,23 +100,24 @@ LogClassMapping log_class_mappings [] = {
 /**
  * Get the logging classes.
  */
-static string
+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;
     }
   }
-  return result;
+  return result.c_str();
 }
 
 
-static void addLoggingClass (const string &name)
+static void
+addLoggingClass (const string &name)
 {
   sgDebugClass classes = logbuf::get_log_classes();
   for (int i = 0; log_class_mappings[i].c != SG_UNDEFD; i++) {
@@ -129,8 +134,9 @@ static void addLoggingClass (const string &name)
  * Set the logging classes.
  */
 static void
-setLoggingClasses (string classes)
+setLoggingClasses (const char * c)
 {
+  string classes = c;
   logbuf::set_log_classes(SG_NONE);
 
   if (classes == "none") {
@@ -138,7 +144,7 @@ setLoggingClasses (string classes)
     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());
@@ -163,7 +169,7 @@ setLoggingClasses (string classes)
 /**
  * Get the logging priority.
  */
-static string
+static const char *
 getLoggingPriority ()
 {
   switch (logbuf::get_log_priority()) {
@@ -189,13 +195,14 @@ getLoggingPriority ()
  * Set the logging priority.
  */
 static void
-setLoggingPriority (string priority)
+setLoggingPriority (const char * p)
 {
+  string priority = p;
   if (priority == "bulk") {
     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);
@@ -208,42 +215,43 @@ setLoggingPriority (string priority)
 }
 
 
-#if 0
 /**
- * Get the pause state of the sim.
+ * Return the current frozen state.
  */
 static bool
 getFreeze ()
 {
-  return globals->get_freeze();
+  return frozen;
 }
 
 
 /**
- * Set the pause state of the sim.
+ * Set the current frozen state.
  */
 static void
-setFreeze (bool freeze)
-{
-    globals->set_freeze(freeze);
-    if ( freeze ) {
-        // BusyCursor( 0 );
-        current_atcdisplay->CancelRepeatingMessage();
-        current_atcdisplay->RegisterRepeatingMessage("****    SIM IS FROZEN    ****    SIM IS FROZEN    ****");
-    } else {
-        // BusyCursor( 1 );
-        current_atcdisplay->CancelRepeatingMessage();
+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();
+        }
     }
 }
-#endif
+
 
 /**
  * Return the current aircraft directory (UIUC) as a string.
  */
-static string 
+static const char *
 getAircraftDir ()
 {
-  return aircraft_dir;
+  return aircraft_dir.c_str();
 }
 
 
@@ -251,39 +259,34 @@ getAircraftDir ()
  * Set the current aircraft directory (UIUC).
  */
 static void
-setAircraftDir (string dir)
+setAircraftDir (const char * dir)
 {
-  if (getAircraftDir() != dir) {
-    aircraft_dir = dir;
-//     needReinit(); FIXME!!
-  }
+  aircraft_dir = 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();
 }
 
 
 /**
  * Return the current Zulu time.
  */
-static string 
+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;
+  return buf;
 }
 
 
@@ -291,7 +294,7 @@ getDateString ()
  * Set the current Zulu time.
  */
 static void
-setDateString (string date_string)
+setDateString (const char * date_string)
 {
   static const SGPropertyNode *cur_time_override
        = fgGetNode("/sim/time/cur-time-override", true);
@@ -302,7 +305,7 @@ setDateString (string date_string)
 
                                // Scan for basic ISO format
                                // YYYY-MM-DDTHH:MM:SS
-  int ret = sscanf(date_string.c_str(), "%d-%d-%dT%d:%d:%d",
+  int ret = sscanf(date_string, "%d-%d-%dT%d:%d:%d",
                   &(new_time.tm_year), &(new_time.tm_mon),
                   &(new_time.tm_mday), &(new_time.tm_hour),
                   &(new_time.tm_min), &(new_time.tm_sec));
@@ -337,17 +340,15 @@ setDateString (string date_string)
 /**
  * Return the GMT as a string.
  */
-static 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;
+  return buf;
 }
 
 
@@ -404,7 +405,7 @@ getHeadingMag ()
 }
 
 
-#if !defined(FG_NEW_ENVIRONMENT)
+#ifdef FG_WEATHERCM
 
 /**
  * Get the current visibility (meters).
@@ -462,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());
@@ -490,7 +491,7 @@ setWindDown (double speed)
                                                           speed);
 }
 
-#endif // FG_NEW_ENVIRONMENT
+#endif // FG_WEATHERCM
 
 static long
 getWarp ()
@@ -577,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);
@@ -593,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);
@@ -614,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()" );
 }
 
 
@@ -636,6 +639,14 @@ fgUpdateProps ()
 bool
 fgSaveFlight (ostream &output, bool write_all)
 {
+
+  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);
   } catch (const sg_exception &e) {
@@ -659,6 +670,11 @@ fgLoadFlight (istream &input)
     guiErrorMessage("Error reading saved flight: ", e);
     return false;
   }
+
+  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
   // new initial state.
@@ -667,6 +683,181 @@ 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.
+////////////////////////////////////////////////////////////////////////
+
+SGPropertyNode *
+fgGetNode (const char * path, bool create)
+{
+  return globals->get_props()->getNode(path, create);
+}
+
+SGPropertyNode * 
+fgGetNode (const char * path, int index, bool create)
+{
+  return globals->get_props()->getNode(path, index, create);
+}
+
+bool
+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)
+{
+  return globals->get_props()->getBoolValue(name, defaultValue);
+}
+
+int
+fgGetInt (const char * name, int defaultValue)
+{
+  return globals->get_props()->getIntValue(name, defaultValue);
+}
+
+int
+fgGetLong (const char * name, long defaultValue)
+{
+  return globals->get_props()->getLongValue(name, defaultValue);
+}
+
+float
+fgGetFloat (const char * name, float defaultValue)
+{
+  return globals->get_props()->getFloatValue(name, defaultValue);
+}
+
+double
+fgGetDouble (const char * name, double defaultValue)
+{
+  return globals->get_props()->getDoubleValue(name, defaultValue);
+}
+
+const char *
+fgGetString (const char * name, const char * defaultValue)
+{
+  return globals->get_props()->getStringValue(name, defaultValue);
+}
+
+bool
+fgSetBool (const char * name, bool val)
+{
+  return globals->get_props()->setBoolValue(name, val);
+}
+
+bool
+fgSetInt (const char * name, int val)
+{
+  return globals->get_props()->setIntValue(name, val);
+}
+
+bool
+fgSetLong (const char * name, long val)
+{
+  return globals->get_props()->setLongValue(name, val);
+}
+
+bool
+fgSetFloat (const char * name, float val)
+{
+  return globals->get_props()->setFloatValue(name, val);
+}
+
+bool
+fgSetDouble (const char * name, double val)
+{
+  return globals->get_props()->setDoubleValue(name, val);
+}
+
+bool
+fgSetString (const char * name, const char * val)
+{
+  return globals->get_props()->setStringValue(name, val);
+}
+
+void
+fgSetArchivable (const char * name, bool state)
+{
+  SGPropertyNode * node = globals->get_props()->getNode(name);
+  if (node == 0)
+    SG_LOG(SG_GENERAL, SG_ALERT,
+          "Attempt to set archive flag for non-existant property "
+          << name);
+  else
+    node->setAttribute(SGPropertyNode::ARCHIVE, state);
+}
+
+void
+fgSetReadable (const char * name, bool state)
+{
+  SGPropertyNode * node = globals->get_props()->getNode(name);
+  if (node == 0)
+    SG_LOG(SG_GENERAL, SG_ALERT,
+          "Attempt to set read flag for non-existant property "
+          << name);
+  else
+    node->setAttribute(SGPropertyNode::READ, state);
+}
+
+void
+fgSetWritable (const char * name, bool state)
+{
+  SGPropertyNode * node = globals->get_props()->getNode(name);
+  if (node == 0)
+    SG_LOG(SG_GENERAL, SG_ALERT,
+          "Attempt to set write flag for non-existant property "
+          << name);
+  else
+    node->setAttribute(SGPropertyNode::WRITE, state);
+}
+
+void
+fgUntie (const char * name)
+{
+  if (!globals->get_props()->untie(name))
+    SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
+}
+
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGCondition.
@@ -686,7 +877,7 @@ FGCondition::~FGCondition ()
 // Implementation of FGPropertyCondition.
 ////////////////////////////////////////////////////////////////////////
 
-FGPropertyCondition::FGPropertyCondition (const string &propname)
+FGPropertyCondition::FGPropertyCondition (const char * propname)
   : _node(fgGetNode(propname, true))
 {
 }
@@ -900,13 +1091,13 @@ FGComparisonCondition::test () const
 }
 
 void
-FGComparisonCondition::setLeftProperty (const string &propname)
+FGComparisonCondition::setLeftProperty (const char * propname)
 {
   _left_property = fgGetNode(propname, true);
 }
 
 void
-FGComparisonCondition::setRightProperty (const string &propname)
+FGComparisonCondition::setRightProperty (const char * propname)
 {
   delete _right_value;
   _right_value = 0;