]> git.mxchange.org Git - simgear.git/blobdiff - simgear/timing/sg_time.hxx
Fix a bug in cloud texture state loading which caused the cloud textures to
[simgear.git] / simgear / timing / sg_time.hxx
index 6d617db7a0a1a1dd5ab59153059c2fa3970e959b..fa0ab060722e789736a73dc8aa7018298ed017ae 100644 (file)
 #endif                                   
 
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <simgear/compiler.h>
 
 #ifdef SG_HAVE_STD_INCLUDES
@@ -76,13 +72,17 @@ private:
     TimezoneContainer* tzContainer;
 
     // Points to the current local timezone name;
-    char *zonename;
+    string zonename;
 
     // Unix "calendar" time in seconds
     time_t cur_time;
 
     // Break down of equivalent GMT time
+#if defined(_MSC_VER) || defined(__MINGW32__)
+    struct tm m_gmt;    // copy of system gmtime(&time_t) structure
+#else
     struct tm *gmt;
+#endif
 
     // offset of local time relative to GMT
     time_t local_offset;
@@ -122,8 +122,10 @@ public:
      * 0).
      * @param lon current longitude
      * @param lat current latitude
-     * @param root root path point to data file location (timezone, etc.)  */
-    SGTime( double lon, double lat, const string& root );
+     * @param root root path point to data file location (timezone, etc.)
+     * @param init_time provide an initialization time, 0 means use
+              current clock time */
+    SGTime( double lon, double lat, const string& root, time_t init_time /* = 0 */ );
 
     /**
      * Create an instance given a data file path.
@@ -134,6 +136,9 @@ public:
     /** Destructor */
     ~SGTime();
 
+    /** init common constructor code */
+    void init( double lon, double lat, const string& root, time_t init_time /* = 0 */ );
+
     /** 
      * Update the time related variables.
      * The update() method requires you to pass in your position and
@@ -143,9 +148,11 @@ public:
      * every frame.
      * @param lon current longitude
      * @param lat current latitude
+     * @param ct specify a unix time, otherwise specify 0 to use current
+              clock time
      * @param warp an optional time offset specified in seconds.  This
      *        allows us to advance or rewind "time" if we choose to.  */
-    void update( double lon, double lat, long int warp = 0 );
+    void update( double lon, double lat, time_t ct /* = 0 */, long int warp /* = 0 */ );
 
     /**
      * Given lon/lat, update timezone information and local_offset
@@ -163,10 +170,14 @@ public:
     inline time_t get_cur_time() const { return cur_time; };
 
     /** @return time zone name for your current position*/
-    inline char* get_zonename() const { return zonename; }
+    inline const char * get_zonename() const { return zonename.c_str(); }
 
     /** @return GMT in a "brokent down" tm structure */
+#if defined(_MSC_VER) || defined(__MINGW32__)
+    inline struct tm* getGmt()const { return (struct tm *)&m_gmt; };
+#else
     inline struct tm* getGmt()const { return gmt; };
+#endif
 
     /** @return julian date */
     inline double getJD() const { return jd; };
@@ -227,12 +238,22 @@ inline time_t sgTimeGetGMT(struct tm* the_time) {
  * @return modified julian date */
 double sgTimeCalcMJD(int mn, double dy, int yr);
 
+/**
+ * \relates SGTime
+ * Given an optional offset from current time calculate the current
+ * modified julian date.
+ * @param ct specify a unix time, otherwise specify 0 to use current
+          clock time
+ * @param warp number of seconds to offset from current time (0 if no offset)
+ * @return current modified Julian date (number of days elapsed
+ * since 1900 jan 0.5), mjd. */
+double sgTimeCurrentMJD( time_t ct /* = 0 */, long int warp /* = 0 */ );
+
 /**
  * \relates SGTime
  * Given an mjd, calculate greenwich mean sidereal time, gst
  * @param mjd modified julian date
- * @return greenwich mean sidereal time (gst)
- */
+ * @return greenwich mean sidereal time (gst) */
 double sgTimeCalcGST( double mjd );
 
 /**