]> git.mxchange.org Git - flightgear.git/blobdiff - Time/fg_time.cxx
C++ ifying ...
[flightgear.git] / Time / fg_time.cxx
index c9abf8259381a5cf9c95b2dc819cf71201d8b241..4cdb20c761d077a648899ace092eba9b71e28ae5 100644 (file)
 #  include <sys/time.h>  // for get/setitimer, gettimeofday, struct timeval
 #endif
 
+#ifdef  WIN32
+#  include <windows.h>
+#  ifdef __CYGWIN32__
+#    define NEAR /* */
+#    define FAR  /* */
+#  endif
+#  include <mmsystem.h>
+#endif
+
+#include <Astro/sky.hxx>
+#include <Astro/solarsystem.hxx>
 #include <Debug/fg_debug.h>
-#include <Flight/flight.h>
+#include <Flight/flight.hxx>
 #include <Include/fg_constants.h>
 #include <Main/options.hxx>
+#include <Time/light.hxx>
 
 #include "fg_time.hxx"
 
 fgTIME cur_time_params;
 
 
-// Initialize the time dependent variables
+// Force an update of the sky and lighting parameters
+static void local_update_sky_and_lighting_params( void ) {
+    // fgSunInit();
+    SolarSystem::theSolarSystem->rebuild();
+    cur_light_params.Update();
+    fgSkyColorsInit();
+}
 
+
+// Initialize the time dependent variables
 void fgTimeInit(fgTIME *t) {
     fgPrintf( FG_EVENT, FG_INFO, "Initializing Time\n");
 
@@ -72,12 +92,19 @@ void fgTimeInit(fgTIME *t) {
 
     t->warp = current_options.get_time_offset();
     t->warp_delta = 0;
+
+    t->pause = current_options.get_pause();
 }
 
 
 // Portability wrap to get current time.
 void timestamp(fg_timestamp *timestamp) {
-#if defined( HAVE_GETTIMEOFDAY )
+#if defined( WIN32 )
+    unsigned int t;
+    t = timeGetTime();
+    timestamp->seconds = 0;
+    timestamp->millis =  t;
+#elif defined( HAVE_GETTIMEOFDAY )
     struct timeval current;
     struct timezone tz;
     // fg_timestamp currtime;
@@ -102,16 +129,25 @@ void timestamp(fg_timestamp *timestamp) {
 
 // Return duration in millis from first to last
 long timediff(fg_timestamp *first, fg_timestamp *last) {
-    return 1000 * (last->seconds - first->seconds) + 
-       (last->millis - first->millis);
+#if defined( WIN32 )
+    return (last->millis - first->millis);
+#else
+    return ( 1000 * (last->seconds - first->seconds) + 
+            (last->millis - first->millis) );
+#endif
 }
 
 
 // Return new timestamp given a time stamp and an interval to add in
 void timesum(fg_timestamp *res, fg_timestamp *start, long millis) {
+#ifdef WIN32
+    res->seconds = 0;
+    res->millis = ( start->millis + millis );
+#else
     res->seconds = start->seconds + 
        ( start->millis + millis ) / 1000;
     res->millis = ( start->millis + millis ) % 1000;
+#endif
 }
 
 
@@ -165,7 +201,7 @@ double cal_mjd (int mn, double dy, int yr) {
 }
 
 
-// given an mjd, return greenwich mean siderial time, gst
+// given an mjd, return greenwich mean sidereal time, gst
 
 double utc_gst (double mjd) {
     double gst;
@@ -309,10 +345,13 @@ time_t get_start_gmt(int year) {
 
 
 // return a courser but cheaper estimate of sidereal time
-double sidereal_course(struct tm *gmt, time_t now, double lng) {
-    time_t start_gmt;
+double sidereal_course(fgTIME *t, double lng) {
+    struct tm *gmt;
+    time_t start_gmt, now;
     double diff, part, days, hours, lst;
 
+    gmt = t->gmt;
+    now = t->cur_time;
     start_gmt = get_start_gmt(gmt->tm_year);
 
     fgPrintf(FG_EVENT, FG_DEBUG, 
@@ -358,6 +397,11 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
              "  Current Unix calendar time = %ld  warp = %ld  delta = %ld\n", 
              t->cur_time, t->warp, t->warp_delta);
 
+    if ( t->warp_delta ) {
+       // time is changing so force an update
+       local_update_sky_and_lighting_params();
+    }
+
     // get GMT break down for current time
     t->gmt = gmtime(&t->cur_time);
     fgPrintf( FG_EVENT, FG_BULK, 
@@ -385,19 +429,14 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
         // calculation to get the difference.
       fgPrintf( FG_EVENT, FG_INFO, "  First time, doing precise gst\n");
       t->gst = gst_precise = sidereal_precise(t->mjd, 0.00);
-      gst_course = sidereal_course(t->gmt, t->cur_time, 0.00);
+      gst_course = sidereal_course(t, 0.00);
       t->gst_diff = gst_precise - gst_course;
 
-      t->lst = 
-       sidereal_course(t->gmt, t->cur_time, -(FG_Longitude * RAD_TO_DEG))
-       + t->gst_diff;
+      t->lst = sidereal_course(t, -(FG_Longitude * RAD_TO_DEG)) + t->gst_diff;
     } else {
        // course + difference should drift off very slowly
-       t->gst = 
-           sidereal_course(t->gmt, t->cur_time, 0.00) + t->gst_diff;
-       t->lst = 
-           sidereal_course(t->gmt, t->cur_time, -(FG_Longitude * RAD_TO_DEG))
-           + t->gst_diff;
+       t->gst = sidereal_course(t, 0.00) + t->gst_diff;
+       t->lst = sidereal_course(t, -(FG_Longitude * RAD_TO_DEG)) + t->gst_diff;
     }
     fgPrintf( FG_EVENT, FG_DEBUG,
              "  Current lon=0.00 Sidereal Time = %.3f\n", t->gst);
@@ -409,6 +448,55 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t) {
 
 
 // $Log$
+// Revision 1.19  1998/10/17 01:34:29  curt
+// C++ ifying ...
+//
+// Revision 1.18  1998/10/02 21:36:09  curt
+// Fixes to try to break through the win95/98 18.3 fps barrier.
+//
+// Revision 1.17  1998/09/15 04:27:49  curt
+// Changes for new astro code.
+//
+// Revision 1.16  1998/08/29 13:11:32  curt
+// Bernie Bright writes:
+//   I've created some new classes to enable pointers-to-functions and
+//   pointers-to-class-methods to be treated like objects.  These objects
+//   can be registered with fgEVENT_MGR.
+//
+//   File "Include/fg_callback.hxx" contains the callback class defns.
+//
+//   Modified fgEVENT and fgEVENT_MGR to use the callback classes.  Also
+//   some minor tweaks to STL usage.
+//
+//   Added file "Include/fg_stl_config.h" to deal with STL portability
+//   issues.  I've added an initial config for egcs (and probably gcc-2.8.x).
+//   I don't have access to Visual C++ so I've left that for someone else.
+//   This file is influenced by the stl_config.h file delivered with egcs.
+//
+//   Added "Include/auto_ptr.hxx" which contains an implementation of the
+//   STL auto_ptr class which is not provided in all STL implementations
+//   and is needed to use the callback classes.
+//
+//   Deleted fgLightUpdate() which was just a wrapper to call
+//   fgLIGHT::Update().
+//
+//   Modified fg_init.cxx to register two method callbacks in place of the
+//   old wrapper functions.
+//
+// Revision 1.15  1998/08/24 20:12:16  curt
+// Rewrote sidereal_course with simpler parameters.
+//
+// Revision 1.14  1998/08/05 00:20:07  curt
+// Added a local routine to update lighting params every frame when time is
+// accelerated.
+//
+// Revision 1.13  1998/07/30 23:48:55  curt
+// Sgi build tweaks.
+// Pause support.
+//
+// Revision 1.12  1998/07/27 18:42:22  curt
+// Added a pause option.
+//
 // Revision 1.11  1998/07/22 21:45:37  curt
 // fg_time.cxx: Removed call to ctime() in a printf() which should be harmless
 //   but seems to be triggering a bug.