]> git.mxchange.org Git - flightgear.git/blobdiff - Time/fg_time.c
Minor tweaks and fixes for cygwin32.
[flightgear.git] / Time / fg_time.c
index 5daa42994594a1bb842d3642a9b86e3b79227690..6b49f0d0210cbe8f2e55b14e0995f0b4e39adc93 100644 (file)
 #include <stdlib.h>
 #include <time.h>
 
-#ifdef WIN32
-#include <sys/time.h> /* for gettimeofday() */
-#include <unistd.h>   /* for gettimeofday() */
-#endif
+#ifdef USE_FTIME
+#  include <sys/timeb.h> /* for ftime() and struct timeb */
+#else
+#  include <unistd.h>  /* for gettimeofday() */
+#  include <sys/time.h>  /* for get/setitimer, gettimeofday, struct timeval */
+#endif /* USE_FTIME */
 
 #include "fg_time.h"
 #include "../Include/constants.h"
@@ -54,6 +56,9 @@ void fgTimeInit(struct fgTIME *t) {
     printf("Initializing Time\n");
 
     t->gst_diff = -9999.0;
+    t->warp = 0;
+    t->warp = 0 * 3600;
+    t->warp_delta = 0;
 }
 
 
@@ -160,13 +165,14 @@ double sidereal_course(struct tm *gmt, time_t now, double lng) {
     long int offset;
     double diff, part, days, hours, lst;
 
+#ifdef USE_FTIME
+    struct timeb current;
+#endif /* USE_FTIME */
+
 #ifdef WIN32
     int daylight;
     long int timezone;
-
-    struct timeval tv;
-    struct timezone tz;
-#endif
+#endif /* WIN32 */
 
     /*
     printf("  COURSE: GMT = %d/%d/%2d %d:%02d:%02d\n", 
@@ -180,14 +186,20 @@ double sidereal_course(struct tm *gmt, time_t now, double lng) {
     mt.tm_hour = 12;
     mt.tm_min = 0;
     mt.tm_sec = 0;
+    mt.tm_isdst = -1; /* let the system determine the proper time zone */
 
     start = mktime(&mt);
 
-#ifdef WIN32
+    /* printf("start1 = %ld\n", start);
+    printf("start2 = %s", ctime(&start));
+    printf("start3 = %ld\n", start); */
+
     daylight = mt.tm_isdst;
-    gettimeofday(&tv, &tz);
-    timezone = tz.tz_minuteswest * 60;
-#endif
+
+#ifdef USE_FTIME
+    ftime(&current);
+    timezone = current.timezone * 60;
+#endif /* USE_FTIME */
 
     if ( daylight > 0 ) {
        daylight = 1;
@@ -232,17 +244,14 @@ double sidereal_course(struct tm *gmt, time_t now, double lng) {
 
 void fgTimeUpdate(struct fgFLIGHT *f, struct fgTIME *t) {
     double gst_precise, gst_course;
-    static long int warp = 0;
 
     printf("Updating time\n");
 
     /* get current Unix calendar time (in seconds) */
-    /* warp = 60; */
-    warp += 0;
-    t->cur_time = time(NULL) + (0) * 60 * 60;
-    t->cur_time += warp;
-    printf("  Current Unix calendar time = %ld  warp = %ld\n", 
-          t->cur_time, warp);
+    t->warp += t->warp_delta;
+    t->cur_time = time(NULL) + t->warp;
+    printf("  Current Unix calendar time = %ld  warp = %ld  delta = %ld\n", 
+          t->cur_time, t->warp, t->warp_delta);
 
     /* get GMT break down for current time */
     t->gmt = gmtime(&t->cur_time);
@@ -292,9 +301,22 @@ void fgTimeUpdate(struct fgFLIGHT *f, struct fgTIME *t) {
 
 
 /* $Log$
-/* Revision 1.24  1997/12/30 22:22:42  curt
-/* Further integration of event manager.
+/* Revision 1.28  1998/01/19 18:35:49  curt
+/* Minor tweaks and fixes for cygwin32.
 /*
+ * Revision 1.27  1998/01/13 00:23:13  curt
+ * Initial changes to support loading and management of scenery tiles.  Note,
+ * there's still a fair amount of work left to be done.
+ *
+ * Revision 1.26  1998/01/05 18:44:36  curt
+ * Add an option to advance/decrease time from keyboard.
+ *
+ * Revision 1.25  1997/12/31 17:46:50  curt
+ * Tweaked fg_time.c to be able to use ftime() instead of gettimeofday()
+ *
+ * Revision 1.24  1997/12/30 22:22:42  curt
+ * Further integration of event manager.
+ *
  * Revision 1.23  1997/12/30 20:47:58  curt
  * Integrated new event manager with subsystem initializations.
  *